bool OrbitCameraManipulator::handleMouseWheel( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
{
	osgGA::GUIEventAdapter::ScrollingMotion sm = ea.getScrollingMotion();

	// TODO: increase scroll factor when eye is far away from model bounding sphere
	double scroll_distance_factor = ( m_eye - m_rotate_center ).length()*0.1;

	switch( sm )
	{
		// mouse scroll up event
	case osgGA::GUIEventAdapter::SCROLL_UP:
		{
			// perform zoom
			zoomCamera( m_wheel_zoom_factor*scroll_distance_factor );
			aa.requestRedraw();
			aa.requestContinuousUpdate( isAnimating() || _thrown );
			return true;
		}

		// mouse scroll down event
	case osgGA::GUIEventAdapter::SCROLL_DOWN:
		{
			// perform zoom
			zoomCamera( -m_wheel_zoom_factor*scroll_distance_factor );
			aa.requestRedraw();
			aa.requestContinuousUpdate( isAnimating() || _thrown );
			return true;
		}

		// unhandled mouse scrolling motion
	default:
		return false;
	}
}
void Engine::checkKeys(void)
{
	if(keys['r']) { initPlayer(); }
	if(keys['4']) { turnCamera(0.002); }
	if(keys['5']) { zoomCamera(0.01); }
	if(keys['6']) { turnCamera(-0.002); }
	if(keys['8']) { zoomCamera(-0.01); }
	if(keys[playerKeys->keyUp()])	{ moveX(player->GetxyS()); }
	if(keys[playerKeys->keyDown()]) { moveX(-player->GetxyS()); }
	if(keys[playerKeys->keyLeft()]) { moveY(player->GetxyS()); }
	if(keys[playerKeys->keyRight()]){ moveY(-player->GetxyS()); }
	//if(keys[playerKeys->keyJump()]) { if(state == 0) { index = player->GetZ() + 10; } }
	//if(index - player->GetZ() > 0.02) 
	//{ player->SetZ(player->GetZ() + player->GetzS()); index-=player->GetzS(); }
	//else
	{ player->SetZ(player->GetZ() - player->GetzS()); }
}
/// Make movement step of manipulator. Returns true if any movement was made.
bool OrbitCameraManipulator::performMovement( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
{
	// return if less then two events have been added
	if( _ga_t0.get() == nullptr || _ga_t1.get() == nullptr )
	{
		return false;
	}

	// get delta time
	double eventTimeDelta = _ga_t0->getTime() - _ga_t1->getTime();
	if( eventTimeDelta < 0. )
	{
		OSG_WARN << "Manipulator warning: eventTimeDelta = " << eventTimeDelta << std::endl;
		eventTimeDelta = 0.;
	}

	// get deltaX and deltaY
	float dx = _ga_t0->getXnormalized() - _ga_t1->getXnormalized();
	float dy = _ga_t0->getYnormalized() - _ga_t1->getYnormalized();
	float scale = getThrowScale( eventTimeDelta );
	dx = dx*scale;
	dy = dy*scale;

	// return if there is no movement.
	if( dx == 0. && dy == 0. )
	{
		return false;
	}

	// call appropriate methods
	int buttonMask = _ga_t1->getButtonMask();
	if( buttonMask == osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON )
	{
		rotateCamera( dx, dy );
		return true;
	}
	else if( buttonMask == osgGA::GUIEventAdapter::MIDDLE_MOUSE_BUTTON || buttonMask == (osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON | osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON) )
	{
		// pan model
		//float scale = getThrowScale( eventTimeDelta );
		panCamera( dx, dy, ea, aa );
		return true;
	}
	else if( buttonMask == osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON )
	{
		zoomCamera( dy );
		return true;
	}

	return false;
}
Exemple #4
0
void checkInput(){
	if(keyDown[27]){
		exit(0);
	}
	if (specialKeyDown[GLUT_KEY_LEFT]){
		rotateCamera(LEFT);
	}
	if (specialKeyDown[GLUT_KEY_RIGHT]){
		rotateCamera(RIGHT);
	}
	if (specialKeyDown[GLUT_KEY_UP]){
		zoomCamera(IN);
	}
	if (specialKeyDown[GLUT_KEY_DOWN]){
		zoomCamera(OUT);
	}
	
	//Nomlet control
	vector<Nomlet> &nomlets = manager->getNomlets();
	
	if (nomlets.size() > 0){
		Nomlet &nomlet = nomlets[0];
		if(keyDown['w']){
			nomlet.accelerate();
		}
		if(keyDown['a']){
			nomlet.turn(NOMLET_TURN_SPEED);
		}
		if(keyDown['d']){
			nomlet.turn(-NOMLET_TURN_SPEED);
		}
		if(keyDown['1']){
			nomlet.giveEnergy(500);
		}
	}

}
void GLWidget::mouseMoveEvent(QMouseEvent *event) {
  int dx = event->x() - last_mouse_x;
  int dy = event->y() - last_mouse_y;

  if (event->buttons() & Qt::LeftButton) {
    rotateCamera(dx, dy);
  }
  else if (event->buttons() & Qt::MidButton) {
    moveCamera(dx, dy);
  }
  else if (event->buttons() & Qt::RightButton) {
    zoomCamera(dy);
  }

  if (user_motion_func) {
    user_motion_func(int(event->x()), int(event->y()));
  }
  last_mouse_x = event->x();
  last_mouse_y = event->y();

  requestRedraw();
}
void myKeyHandler(unsigned char ch, int x, int y) {
    switch(ch) {
        case 'w':
            setup3DModel();
            break;
            
        case 'e':
            toggleDisplayMode();
            break;
            
        case 'r':
            toggleControlPoints();
            
            break;
            
        case 'a':
            subdivideVertical();
            break;
            
        case 'b':
            subdivideHorizontal(true);
            break;
            
        case 'd':
            toggleShadingMode();
            break;
            
        case 's':
            if (!drawing3D()) {
                return;
            } // if
            
            cout << "Changing shininess." << endl;
            
            shininessValue++;
            
            if (shininessValue > HIGH_SHINY) {
                shininessValue = LOW_SHINY;
            } // if
            break;
            
        case 'z':
            toggle3D();
            resetCamera();
            break;
            
        case 'p':
            if (!drawing3D()) {
                return;
            } // if
            
            cout << "[NYI] Changing to the ";
            
            extraFeatureMode++;
            
            if (extraFeatureMode > PROFILE_MODE) {
                extraFeatureMode = AVERAGE_MODE;
            } // if
            
            if (extraFeatureMode == AVERAGE_MODE) {
                cout << "average of the normal of all of the polygons";
            } // if
            
            else if (extraFeatureMode == PROFILE_MODE) {
                cout << "normal from the profile curve.";
            } // else if
            
            cout << endl;
            break;
            
        case 'c':
            resetCamera();
            cout << "Camera reset." << endl;
            break;
            
        case '=':
            zoomCamera(0.1);
            break;
            
        case 'C':
            removeAllPoints();
            resetCamera();
            cout << "Removing all points." << endl;
            break;
            
        case 'q':
                endSubdiv(0);
                break;
        default:
                /* Unrecognized keypress */
        return;
	}

	glutPostRedisplay();

	return;
}
Exemple #7
0
/* Handle user input */
void myKeyHandler(unsigned char ch, int x, int y) {
	switch(ch) {
		case 'c':
			resetCamera();
			printf("Camera reset.\n");
			break;

		case 's':
		case 'S':
			if (disp_style == DS_SOLID) {
				disp_style = DS_WIRE;
			} else {
				disp_style = DS_SOLID;
			}
			print_disp_style();
			break;

		case 'd':
			/* Cycle through the various display modes */
			disp_mode = (disp_mode + 1) % DM_MAX;
			print_disp_mode();
			break;

		case 'D':
			/* Cycle through the various display modes backwards */
			/* By adding DM_MAX, the args to "%" wil never be negative */
			disp_mode = (disp_mode + DM_MAX - 1) % DM_MAX;
			print_disp_mode();
			break;

		case ',':
			rotateCamera(5, X_AXIS);
			break;

		case '<':
			rotateCamera(-5, X_AXIS);
			break;

		case '.':
			rotateCamera(5, Y_AXIS);
			break;

		case '>':
			rotateCamera(-5, Y_AXIS);
			break;

		case '/':
			rotateCamera(5, Z_AXIS);
			break;

		case '?':
			rotateCamera(-5, Z_AXIS);
			break;

		case '+':
			/* Zoom in */
			zoomCamera(-0.1);
			break;

		case '=':
			/* Zoom out */
			zoomCamera(0.1);
			break;

		case 'z':
			myResize(win_width, win_height);
			printf("Window set to default size.\n");
			break;

		case 't':
			performanceTest();
			break;

		case 'q':
			/* Quit with exit code 0 */
			endCanvas(0);
			break;


		/*********************************************/
		/* ADD ADDITIONAL KEYS HERE                  */
		/*********************************************/
		case 'i':
			// If disp mode is not in cone_tri_calc, don't change variable
			if (disp_mode != DM_CONE_TRI_CALC) {
				break;
			} // if

			// Increases the radius of triangles in draw_cone_tri_calc
			r += 0.1;
			printf("Radius increased by 0.1\n");
			break;
		case 'I':
			// If disp mode is not in cone_tri_calc, don't change variable
			if (disp_mode != DM_CONE_TRI_CALC) {
				break;
			} // if

			r -= 0.1;

			if (r < 0.1) {
				r = 0.1;
			} // if

			else {
				printf("Radius decreased by 0.1\n");
			} // else
			break;

		case 'o':
			// If disp mode is not in cone_tri_calc, don't change variable
			if (disp_mode != DM_CONE_TRI_CALC) {
				break;
			} // if

			// Increase the height of triangles in draw_cone_tri_calc
			h += 0.1;
			printf("Height increased by 0.1\n");
			break;
		case 'O':
			// If disp mode is not in cone_tri_calc, don't change variable
			if (disp_mode != DM_CONE_TRI_CALC) {
				break;
			} // if

			h -= 0.1;

			if (h < 0.1) {
				h = 0.1;
			} // if

			else {
				printf("Height decreased by 0.1\n");
			} // else
			break;

		case 'p':
			// If disp mode is not in cone_tri_calc, don't change variable
			if (disp_mode != DM_CONE_TRI_CALC) {
				break;
			} // if

			// Increase number of triangles in draw_cone_tri_calc
			n += 1;
			printf("Number of triangles increased by 1\n");
			break;
		case 'P':
			// If disp mode is not in cone_tri_calc, don't change variable
			if (disp_mode != DM_CONE_TRI_CALC) {
				break;
			} // if

			n -= 1;
			
			if (n < 3) {
				n = 3;
			} // if

			else {
				printf("Number of triangles decreased by 1\n");
			} // else
			break;

		case 'v':
			if (disp_mode != DM_VRML) {
				break;
			} // if

			vr_object = (vr_object + 1) % VR_MAX;
			print_vrml_object();
			break;



		default:
			/* Unrecognized key press, just return */
			return;

			break;
	}

	/*
	 * If control reaches here, the key press was recognized.  Refresh
	 * the screen, since most key presses change the display in some way.
	 */
	myDisplay();

	return;
}
Exemple #8
0
/* Handle user input */
void myKeyHandler(unsigned char ch, int x, int y) {
	switch(ch) {
		case 'c':
			resetCamera();
			printf("Camera reset.\n");
			break;

		case 's':
		case 'S':
			if (disp_style == DS_SOLID) {
				disp_style = DS_WIRE;
			} else {
				disp_style = DS_SOLID;
			}
			print_disp_style();
			break;

		case 'd':
			/* Cycle through the various display modes */
			disp_mode = (disp_mode + 1) % DM_MAX;
			print_disp_mode();
			break;

		case 'D':
			/* Cycle through the various display modes backwards */
			/* By adding DM_MAX, the args to "%" wil never be negative */
			disp_mode = (disp_mode + DM_MAX - 1) % DM_MAX;
			print_disp_mode();
			break;

		case ',':
			rotateCamera(5, X_AXIS);
			break;

		case '<':
			rotateCamera(-5, X_AXIS);
			break;

		case '.':
			rotateCamera(5, Y_AXIS);
			break;

		case '>':
			rotateCamera(-5, Y_AXIS);
			break;

		case '/':
			rotateCamera(5, Z_AXIS);
			break;

		case '?':
			rotateCamera(-5, Z_AXIS);
			break;

		case '+':
			/* Zoom in */
			zoomCamera(-0.1);
			break;

		case '=':
			/* Zoom out */
			zoomCamera(0.1);
			break;

		case 'z':
			myResize(win_width, win_height);
			printf("Window set to default size.\n");
			break;

		case 't':
			performanceTest();
			break;

		case 'q':
			/* Quit with exit code 0 */
			endCanvas(0);
			break;


		/*********************************************/
		/* ADD ADDITIONAL KEYS HERE                  */
		/*********************************************/
        
        
        //Controls for cone triangle calculation
        case 'I':
            radius += 0.1;
            printf("Radius increased to %.1f.\n", radius);
            break;
            
        case 'i':
            if(radius > 0.1) {
                radius -= 0.1;
            }
            printf("Radius decreased to %.1f.\n", radius);
            break;
      
        case 'O':
            height += 0.1;
            printf("Height increased to %.1f.\n", height);
            break;
            
        case 'o':
            if(height > 0.1) {
                height -= 0.1;
            }
            printf("Height decreased to %.1f.\n", height);
            break;
        
        case 'P':
            sides += 1;
            printf("Sides increased to %d.\n", sides);
            break;
            
        case 'p':
            if(sides > 3) {
                sides -= 1;
            }
            printf("Sides decreased to %d.\n", sides);
            break;
            
        //Controls for switching between vrml objects
        case 'v':
            vr_object++;
            if(vr_object >= VR_MAX) {
                vr_object = 0;
            }
            print_vrml_object();
            break;
        
        /* Switching between free scene modes */
        case 'f':
            free_scene_mode++;
            break;
            
        case 'F':
            free_scene_mode--;
        
        case 'a':
            animate = !animate;
            if(animate) {
                printf("Animation engaged.\n");
            }
            else {
                printf("Animation disengaged.\n");
            }
            break;
        /* Allows mathematical shading on display mode 7 */
        case 'y':
            color_change = !color_change;
            if(color_change) {
                printf("Mathematical shading for Display Mode 7.\n");
            }
            else {
                printf("Regular displace in Display Mode 7.\n");
            }
            break;
        case 'l':
            lighting = !lighting;
            if(lighting) {
                printf("Lighting Engaged. \n");
                light_me_up();
                glutPostRedisplay();
            }
            else {
                printf("Lighting Disengaged. \n");
                turn_out_lights();
                glutPostRedisplay();
            }
		default:
			/* Unrecognized key press, just return */
			return;

			break;
	}

	/*
	 * If control reaches here, the key press was recognized.  Refresh
	 * the screen, since most key presses change the display in some way.
	 */
	myDisplay();

	return;
}
Exemple #9
0
///
//  ESWindowProc()
//
//      Main window procedure
//
LRESULT WINAPI ESWindowProc ( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) 
{
   LRESULT  lRet = 1; 

   switch (uMsg) 
   { 
      case WM_CREATE:
         break;

      case WM_SIZE:
         {
            ESContext *esContext = (ESContext*)(LONG_PTR) GetWindowLongPtr ( hWnd, GWLP_USERDATA );
            if ( esContext ) {
               esContext->width = LOWORD( lParam );
               esContext->height = HIWORD( lParam );
               InvalidateRect( esContext->hWnd, NULL, FALSE );
            }
         }

      case WM_PAINT:
         {
            ESContext *esContext = (ESContext*)(LONG_PTR) GetWindowLongPtr ( hWnd, GWLP_USERDATA );
            
            if ( esContext && esContext->drawFunc )
               esContext->drawFunc ( esContext );
            
            if ( esContext )
              ValidateRect( esContext->hWnd, NULL );
         }
         break;

		 case WM_CLOSE:
			 PostQuitMessage(0);             
         break; 

      case WM_DESTROY:
         PostQuitMessage(0);             
         break; 
      
      case WM_CHAR:
         {
            POINT      point;
            ESContext *esContext = (ESContext*)(LONG_PTR) GetWindowLongPtr ( hWnd, GWLP_USERDATA );
            
            GetCursorPos( &point );

            if ( esContext && esContext->keyFunc )
	            esContext->keyFunc ( esContext, (unsigned char) wParam, 
		                             (int) point.x, (int) point.y );
}
         break;
         


	
	case 0x020A://WM_MOUSEWHEEL:
	{

		int  zDelta = (short)HIWORD(wParam);
		int xPos = LOWORD(lParam); 
		int yPos = HIWORD(lParam); 
		zoomCamera(zDelta);
		break;
	}

	case WM_MOUSEMOVE:
		{
				int xPos = LOWORD(lParam); 
				int yPos = HIWORD(lParam); 
			mouseMotionFunc(xPos,yPos);
			break;
		}
	case WM_RBUTTONUP:
	{
			int xPos = LOWORD(lParam); 
			int yPos = HIWORD(lParam); 
			mouseFunc(2,1,xPos,yPos);
		break;
	}
	case WM_RBUTTONDOWN:
	{
			int xPos = LOWORD(lParam); 
			int yPos = HIWORD(lParam); 
			mouseFunc(2,0,xPos,yPos);
		break;
	}
	case WM_LBUTTONDOWN:
		{
				int xPos = LOWORD(lParam); 
				int yPos = HIWORD(lParam); 
			//	gDemoApplication->mouseFunc(0,0,xPos,yPos);
				mouseFunc(0,0,xPos,yPos);
			break;
		}
		case WM_LBUTTONUP:
	{
			int xPos = LOWORD(lParam); 
			int yPos = HIWORD(lParam); 
			//gDemoApplication->mouseFunc(0,1,xPos,yPos);
			mouseFunc(0,1,xPos,yPos);
		break;
	}
      default: 
         lRet = DefWindowProc (hWnd, uMsg, wParam, lParam); 
         break; 
   } 

   return lRet; 
}