Exemplo n.º 1
0
    bool Player::rotate(const Ogre::Vector3 &rot, bool adjust)
    {
        if (mVanity.enabled) {
            toggleVanityMode(false);
        }

        Ogre::Vector3 trueRot = rot;

        /// \note rotate player on forced vanity
        if (mVanity.forced) {
            if (mFreeLook) {
                float diff = (adjust) ? rot.z : mMainCam.yaw - rot.z;

                mVanity.enabled = false;
                rotateCamera(rot, adjust);
                mVanity.enabled = true;

                compensateYaw(diff);
            }
            trueRot.z = 0.f;
        }

        if (mFreeLook || mVanity.enabled || mPreviewMode) {
            rotateCamera(trueRot, adjust);
        }

        /// \note if vanity mode is forced by TVM then rotate player
        return (!mVanity.enabled && !mPreviewMode) || mVanity.forced;
    }
Exemplo n.º 2
0
void processMouseEvents(float factor)
{
    int x;
    int y;

    int cx = scene->context->w / 2;
    int cy = scene->context->h / 2;

    float sensitivity = 0.05f;

    float dx, dy;

    glfwGetMousePos(&x, &y);

    dx = sensitivity * ((float) cx - (float) x);
    dy = sensitivity * ((float) cy - (float) y);

    if (dx == 0.0f && dy == 0.0f)
    {
        return;
    }

    if (glfwGetKey(GLFW_KEY_LSHIFT) == GLFW_PRESS ||
        glfwGetKey(GLFW_KEY_RSHIFT) == GLFW_PRESS)
    {
        float slide = SLIDE_STEP * factor;

        dx *= slide;
        dy *= slide;

        slideCamera(scene->camera, -dx, dy, 0.0f);
    }
    else
    {
        float rotate = ROTATE_STEP * factor;

        dx *= rotate;
        dy *= rotate;

        rotateCamera(scene->camera, dx, 0.0f, 0.0f);
        rotateCamera(scene->camera, 0.0f, -dy, 0.0f);
    }

    if (scene->world != NULL)
    {
        setupCamera(scene->world->sp, scene->camera);
    }

    if (scene->water != NULL)
    {
        setupCameraAlter(scene->water->modifySP, scene->camera);
        setupCamera(scene->water->drawSP, scene->camera);
    }

    glfwSetMousePos(cx, cy);
}
Exemplo n.º 3
0
void Camera::mouseMovement(int x, int y){
	
	rotateCamera(-changeX,-changeY);
	changeX = (float) (startX-x);
	changeY = (float) (startY-y);
	if(!(changeX == 0 && changeY == 0)){
	//New
	rotateCamera(changeX,changeY);
	}
}
Exemplo n.º 4
0
    bool Camera::toggleVanityMode(bool enable)
    {
        // Changing the view will stop all playing animations, so if we are playing
        // anything important, queue the view change for later
        if (!mPreviewMode)
        {
            mVanityToggleQueued = true;
            return false;
        }

        if(!mVanity.allowed && enable)
            return false;

        if(mVanity.enabled == enable)
            return true;
        mVanity.enabled = enable;

        processViewChange();

        float offset = mPreviewCam.offset;
        Ogre::Vector3 rot(0.f, 0.f, 0.f);
        if (mVanity.enabled) {
            rot.x = Ogre::Degree(-30.f).valueRadians();
            mMainCam.offset = mCamera->getPosition().z;
        } else {
            rot.x = getPitch();
            offset = mMainCam.offset;
        }
        rot.z = getYaw();

        mCamera->setPosition(0.f, 0.f, offset);
        rotateCamera(rot, false);

        return true;
    }
Exemplo n.º 5
0
    void Camera::update(float duration, bool paused)
    {
        if (mAnimation->allowSwitchViewMode())
        {
            // Now process the view changes we queued earlier
            if (mVanityToggleQueued)
            {
                toggleVanityMode(!mVanity.enabled);
                mVanityToggleQueued = false;
            }
            if (mViewModeToggleQueued)
            {

                togglePreviewMode(false);
                toggleViewMode();
                mViewModeToggleQueued = false;
            }
        }

        updateListener();
        if (paused)
            return;

        // only show the crosshair in game mode and in first person mode.
        MWBase::WindowManager *wm = MWBase::Environment::get().getWindowManager();
        wm->showCrosshair(!wm->isGuiMode() && (mFirstPersonView && !mVanity.enabled && !mPreviewMode));

        if(mVanity.enabled)
        {
            Ogre::Vector3 rot(0.f, 0.f, 0.f);
            rot.z = Ogre::Degree(3.f * duration).valueRadians();
            rotateCamera(rot, true);
        }
    }
Exemplo n.º 6
0
    void Camera::update(float duration, bool paused)
    {
        if (mAnimation->upperBodyReady())
        {
            // Now process the view changes we queued earlier
            if (mVanityToggleQueued)
            {
                toggleVanityMode(!mVanity.enabled);
                mVanityToggleQueued = false;
            }
            if (mViewModeToggleQueued)
            {

                togglePreviewMode(false);
                toggleViewMode();
                mViewModeToggleQueued = false;
            }
        }

        if (paused)
            return;

        // only show the crosshair in game mode and in first person mode.
        MWBase::WindowManager *wm = MWBase::Environment::get().getWindowManager();
        wm->showCrosshair(!wm->isGuiMode() && (mFirstPersonView && !mVanity.enabled && !mPreviewMode));

        if(mVanity.enabled)
        {
            rotateCamera(0.f, osg::DegreesToRadians(3.f * duration), true);
        }
    }
Exemplo n.º 7
0
    bool Player::toggleVanityMode(bool enable, bool force)
    {
        if ((mVanity.forced && !force) ||
            (!mVanity.allowed && (force || enable)))
        { 
            return false;
        } else if (mVanity.enabled == enable) {
            return true;
        }
        mVanity.enabled = enable;
        mVanity.forced = force && enable;

        float offset = mPreviewCam.offset;
        Ogre::Vector3 rot(0.f, 0.f, 0.f);
        if (mVanity.enabled) {
            rot.x = Ogre::Degree(-30.f).valueRadians();
            mMainCam.offset = mCamera->getPosition().z;

            setLowHeight(true);
        } else {
            rot.x = getPitch();
            offset = mMainCam.offset;

            setLowHeight(!mFirstPersonView);
        }
        rot.z = getYaw();
        mCamera->setPosition(0.f, 0.f, offset);
        rotateCamera(rot, false);

        return true;
    }
Exemplo n.º 8
0
void rotatePlayer(player_s* p, vect3Df_s v)
{
	if(!p)return;

	p->tempAngle = vaddf(p->tempAngle, v);
	rotateCamera(&p->camera, v);
}
Exemplo n.º 9
0
///
/// \brief GlFrame::keyPressEvent
///     Key Event handler, for translation and rotation
///         ZS : move along Z
///         QD : move along X
///         RF : move along Y
///
///         Arrow keys : rotate camera
///
/// \param event
///
void GlFrame::keyPressEvent( QKeyEvent* event )
{
    switch( event->key())
    {
            case Qt::Key_Left:
                rotateCamera( m_rotateSpeed * m_timeSinceLastFrame, 0 );
                break;

            case Qt::Key_Right:
                rotateCamera( -m_rotateSpeed * m_timeSinceLastFrame, 0);
                break;

            case Qt::Key_Up:
                rotateCamera( 0, m_rotateSpeed * m_timeSinceLastFrame );
                break;

            case Qt::Key_Down:
                rotateCamera( 0, -m_rotateSpeed * m_timeSinceLastFrame);
                break;  

            case Qt::Key_D:
                translateCamera(0, m_moveSpeed * m_timeSinceLastFrame);
                break;

            case Qt::Key_Q:
                translateCamera(0, -m_moveSpeed * m_timeSinceLastFrame);
                break;

            case Qt::Key_Z:
                translateCamera(m_moveSpeed * m_timeSinceLastFrame, 0);
                break;

            case Qt::Key_S:
                translateCamera(-m_moveSpeed * m_timeSinceLastFrame, 0);
                break;

            case Qt::Key_R:
                m_Camera->translateY(m_moveSpeed * m_timeSinceLastFrame);
                break;

            case Qt::Key_F:
                m_Camera->translateY(-m_moveSpeed * m_timeSinceLastFrame);
                break;
    }
}
Exemplo n.º 10
0
void myKeyHandler(unsigned char ch, int x, int y)
{
  switch (ch)
  {
    case '/':
      rotateCamera(5, Y_AXIS);
      break;
      
    case '?':
      rotateCamera(-5, Y_AXIS);
      break;
      
    case 'q':
      endCanvas(0);
      break;
      
    case 'a':
      if (_iterations < 10)
      {
        ++_iterations;
      }
      break;
      
    case 's':
      if (_iterations > 0)
      {
        --_iterations;
      }
      break;
      
    case 'p':
    
      break;
    
    case 'w':
      setSeason();
      break;

    default:
      return;
      break;
  }
  
  display ();
}
Exemplo n.º 11
0
bool myApp::processInput(unsigned int nMsg, int wParam, long lParam)
{
  // Handle input
  switch (nMsg)
  {
    // Process mouse move message
  case WM_MOUSEMOVE:
  {
                     // Get mouse x & y (to the upper-left corner of the client area)
                     int xPos = GET_X_LPARAM(lParam);
                     int yPos = GET_Y_LPARAM(lParam);

                     if ((wParam & MK_LBUTTON) != 0 && m_nPrevMouseX >= 0) // 
                     {
                       rotateCamera(s_rMouseMove2Rotate*(xPos - m_nPrevMouseX),
                         s_rMouseMove2Rotate*(yPos - m_nPrevMouseY));
                     }

                     m_nPrevMouseX = xPos;
                     m_nPrevMouseY = yPos;
                     break;
  }

    // Process mouse wheel message
  case WM_MOUSEWHEEL:
  {
                      int zDelta = (int)((signed short)(HIWORD(wParam)));
                      zoom(zDelta * s_rMouseWheel2Zoom);
                      break;
  }

  case WM_KEYDOWN:
  {
                   // Save flags for continuous controls
                   if (wParam < MAX_KEYS)
                     m_keysPressed[wParam] = true;
                   break;
  }

  case WM_KEYUP:
  {
                 // Save flags for continuous controls
                 if (wParam < MAX_KEYS)
                   m_keysPressed[wParam] = false;
                 // Process switch controls
                 switch (wParam)
                 {
                 case '1': /* do something */ break;
                 case '2': /* do something */ break;
                 case '3': /* do something */ break;
                 }
                 break;
  }
  }

  return cglApp::processInput(nMsg, wParam, lParam);
}
Exemplo n.º 12
0
void QgsCameraController::onPositionChanged( Qt3DInput::QMouseEvent *mouse )
{
  int dx = mouse->x() - mMousePos.x();
  int dy = mouse->y() - mMousePos.y();

  bool hasShift = ( mouse->modifiers() & Qt::ShiftModifier );
  bool hasCtrl = ( mouse->modifiers() & Qt::ControlModifier );
  bool hasLeftButton = ( mouse->buttons() & Qt::LeftButton );
  bool hasMiddleButton = ( mouse->buttons() & Qt::MiddleButton );
  bool hasRightButton = ( mouse->buttons() & Qt::RightButton );

  if ( ( hasLeftButton && hasShift && !hasCtrl ) || ( hasMiddleButton && !hasShift && !hasCtrl ) )
  {
    // rotate/tilt using mouse (camera moves as it rotates around its view center)
    float pitch = mCameraPose.pitchAngle();
    float yaw = mCameraPose.headingAngle();
    pitch += dy;
    yaw -= dx / 2;
    mCameraPose.setPitchAngle( pitch );
    mCameraPose.setHeadingAngle( yaw );
    updateCameraFromPose();
  }
  else if ( hasLeftButton && hasCtrl && !hasShift )
  {
    // rotate/tilt using mouse (camera stays at one position as it rotates)
    float diffPitch = 0.2f * dy;
    float diffYaw = 0.2f * -dx / 2;
    rotateCamera( diffPitch, diffYaw );
    updateCameraFromPose( true );
  }
  else if ( hasLeftButton && !hasShift && !hasCtrl )
  {
    // translation works as if one grabbed a point on the plane and dragged it
    // i.e. find out x,z of the previous mouse point, find out x,z of the current mouse point
    // and use the difference

    float z = mLastPressedHeight;
    QPointF p1 = screen_point_to_point_on_plane( QPointF( mMousePos.x(), mMousePos.y() ), mViewport, mCamera, z );
    QPointF p2 = screen_point_to_point_on_plane( QPointF( mouse->x(), mouse->y() ), mViewport, mCamera, z );

    QgsVector3D center = mCameraPose.centerPoint();
    center.set( center.x() - ( p2.x() - p1.x() ), center.y(), center.z() - ( p2.y() - p1.y() ) );
    mCameraPose.setCenterPoint( center );
    updateCameraFromPose( true );
  }
  else if ( hasRightButton && !hasShift && !hasCtrl )
  {
    // zoom in/out
    float dist = mCameraPose.distanceFromCenterPoint();
    dist -= dist * dy * 0.01f;
    mCameraPose.setDistanceFromCenterPoint( dist );
    updateCameraFromPose();
  }

  mMousePos = QPoint( mouse->x(), mouse->y() );
}
Exemplo n.º 13
0
void mouseTrack(int x, int y)
{
  
  double x_change = x - _x_pos;
  _x_pos = (double)x;
  
  cout << "entered mouseTrack " << x_change << endl;
  if(x_change > 0 && _counter%3 ==0) //mouse moved right - counter clockwise
  {
    rotateCamera(x_change/2,Y_AXIS);
  }
  else if(x_change < 0 && _counter%3 ==0) //mouse moved left - clockwise
  {
    rotateCamera(x_change/2,Y_AXIS);
  }
  _counter++;
   display ();

}
void CameraController3rd::update(float delta)
{
	//Modificar la distancia al objetivo si conviene
	checkCameraDistance();

	if(_lockOn)
	{
		//Shadow mira hacia donde mira la camara
		TransformComponent * player_trans = EntityManager::get().getComponent<TransformComponent>(World::instance()->getPlayer());
		btVector3 cam_front;  CameraSystem::get().getPlayerCamera().getFront(cam_front);
		cam_front.setY(0);
		player_trans->approximateFront_v(cam_front, 10*delta);

		//Si hay enemigo fijado, hacer que el player mire hacia el
		if(_lockedEntity)
		{
			btVector3 dir =  EntityManager::get().getComponent<TransformComponent>(_lockedEntity)->getPosition() - player_trans->getPosition();
			lookTo(dir, 0.8f); //Camara mira hacia la entity fijada
		}
		else
		{
			lookForEnemies();
			if(!CameraSystem::get().isLockedCamera3rd()) rotateCamera(delta); //Rotar camara segun input 
		}
	}
	else
	{
		if(!CameraSystem::get().isLockedCamera3rd()) rotateCamera(delta); //Rotar camara segun input 
	}

	//Centrar camara
	checkCenterCamera();

	//Se resitua la camara en una posicion guay
	btVector3 targetPos = _targetTransform->getOrigin();
	targetPos.setY(targetPos.getY() + _upDist);
	btVector3 left = btVector3(0,1,0).cross(_front);  left.normalize();
	targetPos = targetPos + _sideDist*left;

	placeByCollisionsPosition(delta, targetPos);

	_camera->lookAt( _position, targetPos, btVector3(0,1,0));
}
Exemplo n.º 15
0
void Display() {

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
	setupLights();
	setupCamera(); 
	drawBanana(30,cameraY+90,0);


	if (coins >= 5) {
		win = true;
		//sound for winning
	}
		
    if (cinematic)
		rotateCamera();
	glColor3f(1,1,1);
	Draw_Skybox(cameraX, cameraY, cameraZ, 400, 800, 400);
	if (Levels.size() > 0) {
		if (Levels[0].y <cameraY - 100) {
			printf("deleting level");
			Levels.erase(Levels.begin());
			//	for (int j = 0; j<Levels.size() - 1; j++) {
			//		Levels[j] = Levels[j + 1];
			//	}
			//	Levels.pop_back();
			if (Levels.size()>0) {
				Levels[0].levelBefore = NULL;
			}

		}
	}
	char result[10];
	sprintf(result, "%i", coins);
	//std::string name = "Score: ", result;
	displayText(50, cameraY + 110, 0, 1, 1, 1, result);

	if (!lost&!win) {
		createScene();
		character.drawCharacter();
		//std::string name = "Score: ";
	//	char numstr[2];
	///	result = name + numstr;
	}
	else {
		    if (lost)
			displayText(-20, cameraY + 100, 0, 1, 1, 1, "GAME OVER!");
		
			if (win)
				displayText(-20, cameraY + 100, 0, 1, 1, 1, "YOU WON :)");
			
	}
	
	glFlush();
}
Exemplo n.º 16
0
void performanceTest(void) {
	int start, end;
	int i;
	int curr_width, curr_height;

	/* Give a warning if the window has been resized */
	curr_width = glutGet(GLUT_WINDOW_WIDTH);
	curr_height = glutGet(GLUT_WINDOW_HEIGHT);

	if ((curr_width != win_width) || (curr_height != win_height)) {
		printf("*** Warning ***\n");
		printf("The window has been resized and results may be inaccurate.\n");
		printf("First press 'z' to restore the default window size.\n");
		printf("*** Warning ***\n");
	}

	resetCamera();

	printf("Initiating Performance Test\n");
	start = glutGet(GLUT_ELAPSED_TIME);

	/* For every rotation, the display loop will be recalled */
	for (i = 0; i < 360; i++) {
		rotateCamera(1.0, X_AXIS);
		myDisplay();		/* refresh the screen */
	}
	for (i = 0; i < 360; i++) {
		rotateCamera(1.0, Y_AXIS);
		myDisplay();		/* refresh the screen */
	}
	for (i = 0; i < 360; i++) {
		rotateCamera(1.0, Z_AXIS);
		myDisplay();		/* refresh the screen */
	}

	end = glutGet(GLUT_ELAPSED_TIME);

	/* Return the number of milliseconds elapsed */
	printf("Performance Test completed in %.2f sec\n",
		(end - start) / 1000.0f);
}
Exemplo n.º 17
0
static void special(int key, int x, int y)
{
	switch (key) {
	case GLUT_KEY_UP:
		/* move forward */
		translateCamera(0.15f);
		break;
	case GLUT_KEY_DOWN:
		/* move backward */
		translateCamera(-0.15f);
		break;
	case GLUT_KEY_RIGHT:
		/* rotate to the right */
		rotateCamera(5.0f);
		break;
	case GLUT_KEY_LEFT:
		/* rotate to the left */
		rotateCamera(-5.0f);
		break;
	}
}
/// 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;
}
Exemplo n.º 19
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);
		}
	}

}
Exemplo n.º 20
0
Camera * newCamera(int w, int h)
{
    Camera * camera = (Camera *) malloc(sizeof(Camera));

    camera->pos[0] = 2.0f;
    camera->pos[1] = 2.0f;
    camera->pos[2] = 3.0f;

    camera->q[0] = 1.0f;
    camera->q[1] = 0.0f;
    camera->q[2] = 0.0f;
    camera->q[3] = 0.0f;

    rotateCamera(camera, 0.0f, -90.0f, 0.0f);
    rotateCamera(camera, 135.0f, 0.0f, 0.0f);
    rotateCamera(camera, 0.0f, -45.0f, 0.0f);

    camera->viewAngleY = 45.0f;
    camera->aspect = ((float) w) / ((float) h);
    camera->znear = 0.001f;
    camera->zfar = 100.0f;

    return camera;
}
Exemplo n.º 21
0
void Viewer::update(){

 	GLfloat elapsedTime = glfwGetTime() - _lastAccessedTime;
	_lastAccessedTime = glfwGetTime();
	changeElevation(_elevation_velocity * elapsedTime);

	_velocity = _velocity - glm::vec3(0,_fall_speed,0);
	_direction.y = 0;

	glm::vec3 displacement = _velocity * elapsedTime;
	GLfloat cameraRotation = _cameraRotationVelocity * elapsedTime;

	rotateCamera(cameraRotation);
	move(displacement.x, displacement.y, - displacement.z);
}
Exemplo n.º 22
0
///
/// \brief GlFrame::mouseMoveEvent
///     Rotate camera with mouse when in fullscreen mode
/// \param event
///
void GlFrame::mouseMoveEvent(QMouseEvent *event)
{    if(!isFullScreen())
        return;

    float disX = (event->globalX() - m_lastPos.x()) * m_rotateSpeed;
    float disY = (event->globalY() - m_lastPos.y()) * m_rotateSpeed;

//    cout << "Souris y " << disY << endl;
//    cout << "Souris x " << disX << endl;

    rotateCamera(-disX, -disY);

    QPoint glob = mapToGlobal(QPoint(width()/2,height()/2));
    QCursor::setPos(glob);
    m_lastPos = QPoint(width()/2,height()/2);
}
Exemplo n.º 23
0
void myMouseMotion(int x, int y) {
    init();
	double d_x, d_y;	/* The change in x and y since the last callback */
    
	d_x = x - m_last_x;
	d_y = y - m_last_y;
    
	m_last_x = x;
	m_last_y = y;
    
    d_x /= 2.0;
    
    rotateCamera(d_x);	/* y-axis rotation */
    
	/* Redraw the screen */
	glutPostRedisplay();
}
Exemplo n.º 24
0
void key(unsigned char key, int x, int y) {
	if (key == ' ' &(!character.fall||character.x>60 || character.x<-70)&&jumpVelocity<30) {
		// sound for jumping
		
		character.angleOfLooking = 0;
	    jump = true;
		if (jumpVelocity < 35){
			//sound for double jump
			jumpVelocity = 1.2*jumpVelocity;
			//cameraAcceleration = 4*cameraAcceleration;
			cameraY += jumpVelocity/8;
			eyeY += jumpVelocity/8;
	
		}
		else{
			jump = false;
		}
		jumpTime = clock();
		jumpBeginX = character.x;
		jumpBeginY = character.y;
		jumpEndY = character.y;
	}
	if (key == 'd') {
		characterSpeed = fabs(characterSpeed);
		character.x += characterSpeed;
		character.angleOfLooking = 90;
	}
	if (key == 'a') {
		characterSpeed = fabs(characterSpeed)*-1;
		character.x += characterSpeed;
		character.angleOfLooking = -90;

	}

	if (key == 'v'&!lost&!win){
		cinematic = true;
		rotateCamera();
	}
	if (key == 'c') {
		eyeY--;
		cameraY--;
	}
	
}
void drawKinectData() {
	getKinectData();
	rotateCamera();

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_COLOR_ARRAY);

	glBindBuffer(GL_ARRAY_BUFFER, vboId);
	glVertexPointer(3, GL_FLOAT, 0, NULL);
	
	glBindBuffer(GL_ARRAY_BUFFER, cboId);
	glColorPointer(3, GL_FLOAT, 0, NULL);

	glPointSize(1.f);
	glDrawArrays(GL_POINTS, 0, width*height);
	
	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_COLOR_ARRAY);
	
	// Draw some arms
	const Vector4& lh = skeletonPosition[NUI_SKELETON_POSITION_HAND_LEFT];
	const Vector4& le = skeletonPosition[NUI_SKELETON_POSITION_ELBOW_LEFT];
	const Vector4& ls = skeletonPosition[NUI_SKELETON_POSITION_SHOULDER_LEFT];
	const Vector4& rh = skeletonPosition[NUI_SKELETON_POSITION_HAND_RIGHT];
	const Vector4& re = skeletonPosition[NUI_SKELETON_POSITION_ELBOW_RIGHT];
	const Vector4& rs = skeletonPosition[NUI_SKELETON_POSITION_SHOULDER_RIGHT];
	glBegin(GL_LINES);
		glColor3f(1.f, 0.f, 0.f);
		if (lh.w > 0 && le.w > 0 && ls.w > 0) {
			glVertex3f(lh.x, lh.y, lh.z);
			glVertex3f(le.x, le.y, le.z);
			glVertex3f(le.x, le.y, le.z);
			glVertex3f(ls.x, ls.y, ls.z);
		}
		if (rh.w > 0 && re.w > 0 && rs.w > 0) {
			glVertex3f(rh.x, rh.y, rh.z);
			glVertex3f(re.x, re.y, re.z);
			glVertex3f(re.x, re.y, re.z);
			glVertex3f(rs.x, rs.y, rs.z);
		}
	glEnd();
}
Exemplo n.º 26
0
    void Player::update(float duration)
    {
        updateListener();

        // only show the crosshair in game mode and in first person mode.
        MWBase::Environment::get().getWindowManager ()->showCrosshair
                (!MWBase::Environment::get().getWindowManager ()->isGuiMode () && (mFirstPersonView && !mVanity.enabled && !mPreviewMode));

        /// \fixme We shouldn't hide the whole model, just certain components of the character (head, chest, feet, etc)
        mPlayerNode->setVisible(mVanity.enabled || mPreviewMode || !mFirstPersonView);
        if (mFirstPersonView && !mVanity.enabled) {
            return;
        }
        if (mVanity.enabled) {
            Ogre::Vector3 rot(0.f, 0.f, 0.f);
            rot.z = Ogre::Degree(3.f * duration).valueRadians();
            rotateCamera(rot, true);
        }
    }
Exemplo n.º 27
0
    void Player::togglePreviewMode(bool enable)
    {
        if (mPreviewMode == enable) {
            return;
        }
        mPreviewMode = enable;
        float offset = mCamera->getPosition().z;
        if (mPreviewMode) {
            mMainCam.offset = offset;
            offset = mPreviewCam.offset;

            setLowHeight(true);
        } else {
            mPreviewCam.offset = offset;
            offset = mMainCam.offset;

            setLowHeight(!mFirstPersonView);
        }
        mCamera->setPosition(0.f, 0.f, offset);
        rotateCamera(Ogre::Vector3(getPitch(), 0.f, getYaw()), false);
    }
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();
}
Exemplo n.º 29
0
void SimObjectRenderer::moveCamera(float x, float y)
{
  if(cameraMode == SimRobotCore2::Renderer::targetCam)
  {
    if(x != 0.f)
      rotateCamera(x, 0);
    if(y != 0.f)
    {
      Vector3<> v = cameraPos - cameraTarget;
      float len = v.abs() + y;
      if(len < 0.0001f)
        len = 0.0001f;
      v.normalize(len);
      cameraPos = cameraTarget + v;
    }
  }
  else // if(cameraMode == SimRobotCore2::Renderer::FREECAM)
  {
    if(x != 0.f)
    {
      Vector3<> v = cameraTarget - cameraPos;
      Vector3<> v2 = v ^ Vector3<>(0.f, 0.f, 1.f);
      v2.normalize(x);
      cameraTarget += v2;
      cameraPos += v2;
    }
    if(y != 0.f)
    {
      Vector3<> v = cameraTarget - cameraPos;
      v.normalize(y);
      cameraTarget -= v;
      cameraPos -= v;
    }
  }
  updateCameraTransformation();
}
Exemplo n.º 30
0
/*Render all the objects into the scene. With appropriate
 *transformations applied.*/
void renderScene()
{
    if(!global.split)
    {
        drawStarBackground();
        showTextDisplay(FALSE);
    }

    /*Save matrix for rotation before calculating
    how far to zoom in.*/
    glMatrixMode(GL_PROJECTION);
    glScalef(cameraVar.zoom, cameraVar.zoom, cameraVar.zoom);
    glMatrixMode(GL_MODELVIEW);

    if(!global.split)
        rotateCamera();
    
    drawSceneWorld();  
    drawSceneProjectiles();
    drawSceneBases();

    /*Print any errors that may pop up.*/
    int error = glGetError();
    if(error != GL_NO_ERROR)
    {
        printf("%s\n", gluErrorString(error));
        exit(1);
    }

    /*Reset projection matrix to default
     *so the text and star background does not
     *get scaled next iteration.*/
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glMatrixMode(GL_MODELVIEW);
}