コード例 #1
0
ファイル: Camera.cpp プロジェクト: gmevelec/firstgame
void		Camera::move()
{
	calculateZoom();
	calculatePitch();
	calculateAngleAroundPlayer();
	float horizontalDistance = calculateHorizontalDistance();
	float verticalDistance = calculateVerticalDistance();
	calculateCameraPosition(horizontalDistance, verticalDistance);
	_yaw = 180 - (_player->getRotation().y + _angleAroundPlayer);
}
コード例 #2
0
ファイル: SpelchkCamera.cpp プロジェクト: C-Compton/OpenGL
void SpelchkCamera::moveCamera( float xDepth, float yDepth, float zDepth ) {
  _oldTranslationVector = _translationVector;
  _oldCameraPosition = _cameraPosition;
  
  _xDepth = xDepth;
  _yDepth = yDepth;
  _zDepth = zDepth;
  
  calculateTranslationVector();
  calculateCameraPosition();
}
コード例 #3
0
void PlayableState::view()
{
    if(auto spt = theWorld.lock())
    {
      shipPosition = spt->getPlayerShip()->getPhysicsObject().getPosition();
      shipForward = spt->getPlayerShip()->getPhysicsObject().getForward();
      shipUp = spt->getPlayerShip()->getPhysicsObject().getUp();
    }
    calculateCameraPosition();
    gluLookAt(cameraPosition.getX(), cameraPosition.getY(), cameraPosition.getZ(),
              shipPosition.getX(), shipPosition.getY(), shipPosition.getZ(),
              shipUp.getX(), shipUp.getY(), shipUp.getZ());
}
コード例 #4
0
ファイル: SpelchkCamera.cpp プロジェクト: C-Compton/OpenGL
void SpelchkCamera::reset() {
  _projectionType = 0;
  _fovy = 45;
  
  _left = -1.0;
  _right = 1.0;
  _bottom = -1.0;
  _top = 1.0;
  _zNear = 0.1;
  _zFar = 20.0;
  
  _xDepth = 0.0;
  _yDepth = 0.0;
  _zDepth = 0.0;
  
  _xAngle = 0.0;
  _yAngle = 0.0;
  _zAngle = 0.0;
  
  _xHead = 0.0;
  _yHead = 0.0;
  _zHead = 0.0;
  
  _xHeadAngle = 0.0;
  _yHeadAngle = 0.0;
  _zHeadAngle = 0.0;
  
  _oldTranslationVector = _initialTranslationVector;
  _translationVector = _oldTranslationVector;

  _oldCameraPosition = _initialTranslationVector;
  _cameraPosition = _oldCameraPosition;

  calculateTranslationVector();
  calculateCameraPosition();
}
コード例 #5
0
bool RotateDesktopGesture::processGestureImpl(GestureContext *gestureContext)
{
	float angle = calculateAngle(gestureContext);
	QList<Path *> activePaths = gestureContext->getActiveTouchPaths();
	if (_animatingToForward)
	{
		// user may realize accidental trigger of rotation while camera is orienting to face "forward" wall
		if (gestureContext->getNumActiveTouchPoints() != 2) 
		{
			_animatingToForward = false;
			cam->killAnimation();
			cam->animateTo(_startPos, _startDir, _startUp);
			return false;
		}

		if(cam->isAnimating())
			return true; // let camera animate to face the "forward" wall first
		else
		{
			_originalDir = cam->getDir();
			_originalUp = cam->getUp();
			_compensate = angle;
			_animatingToForward = false;
		}
	}

	if (gestureContext->getNumActiveTouchPoints() != 2) 
	{
		if (activePaths.count() == 1)
		{
			if (activePaths.contains(_gestureTouchPaths[0]) || activePaths.contains(_gestureTouchPaths[1]))
			{
				_recalculateInitials = true;
				return true; // still remain as rotate gesture, user probably lifted and repositioning one finger
			}
		}
		if (abs(angle) < SNAP_MINIMUM_ANGLE) // finished rotation gesture, check if a rotation is achieved
		{
			cam->animateTo(_startPos, _startDir, _startUp); // rotation amount too small, revert to original view
			return false;
		}
		// Snap the camera to the nearest wall
		int wallIndex = getWallCameraIsFacing();
		assert(wallIndex != -1);
		Vec3 camDir, camPos;
		cam->lookAtWall(GLOBAL(Walls)[wallIndex], camPos, camDir);
		cam->animateTo(camPos, camDir);
		return false;
	}

	if (_recalculateInitials)
	{
		_recalculateInitials = false;
		// if rotation after repositioning is canceled, revert camera to before lifting and repositioning
		// not revert camera to before rotation gesture is recognized
		_startUp = cam->getUp(); 
		_startDir = cam->getDir();
		_startPos = cam->getEye();
	}

	cam->revertAnimation();
	
	pair<Vec3, Vec3> camPair = calculateCameraPosition();
	cam->setEye(camPair.first);
	
	// Rotate the camera; take out the amount used to trigger rotation and face "forward" wall to avoid too much initial rotation
	float rotationAngle = angle - _compensate;
	Quat rotation(rotationAngle, Vec3(0.0f, 1.0f, 0.0f));
	Vec3 dir = _originalDir;
	Vec3 up = _originalUp;
	rotation.rotate(dir);
	rotation.rotate(up);

	dir.sety(camPair.second.y);
	
	cam->animateTo(cam->getEye(), dir, up, 5, false);	
	
	return true;
}