コード例 #1
0
void CameraController::closeCursorPosition()
{
	ICursorControl* cursor = _game->getDevice()->getCursorControl();
	vector2df position = cursor->getRelativePosition();

	if (closeCoordinate(position.X) ||
		closeCoordinate(position.Y)) {
		cursor->setPosition(position);
		_previousMousePosition = position;
	}
}
コード例 #2
0
void PlayerInstance :: UpdateRotation()
{
	ICursorControl* cursorControl = IRR->device->getCursorControl();
	position2d<f32> cursorPos = cursorControl->getRelativePosition();
	static float rotateSpeed = 4.0f;

	if(firstRot) // it checks if it is the first time camera rotates and than fill tables with proper values
	{
		rotX[0] = rotX[1] = 0.5f - cursorPos.X;
		rotY[0] = rotY[1] = 0.5f - cursorPos.Y;
		firstRot = false;
	}
      
	// puts values from this frame into table
	rotX[2] = 0.5f - cursorPos.X;
	rotY[2] = 0.5f - cursorPos.Y; 

	// If any change in cursorPos this frame:
	if (cursorPos.X < 0.5 || cursorPos.X > 0.5 || cursorPos.Y < 0.5 || cursorPos.Y > 0.5 )
	{
		// Rotate Y Axis:
		yRotation -= (rotX[0]+rotX[1]+rotX[2])/3 * rotateSpeed;

		// Rotate X Axis:
		xRotation -= (rotY[0]+rotY[1]+rotY[2])/3 * rotateSpeed;

		// Restrict X Axis:
		if(xRotation > PI/2.1f) xRotation = PI/2.1f;
		if(xRotation < -PI/2.1f) xRotation = -PI/2.1f;
		
		cursorControl->setPosition(0.5f, 0.5f);
      
		rotX[0] = rotX[1]; // finaly we move values to make room for a new ones
		rotX[1] = rotX[2];
      
		rotY[0] = rotY[1];
		rotY[1] = rotY[2];
	}

	
	lookAtHeading = IRR->RotateVectorAboutVector(vector3df(1,0,0), vector3df(0,1,0), yRotation);

	vector3df newTangent = lookAtHeading.crossProduct(vector3df(0,-1,0));
	newTangent.Y = 0;
	newTangent.normalize();

	lookAtHeading = IRR->RotateVectorAboutVector(lookAtHeading, newTangent, xRotation); // + camRecoil.X
	camUp = lookAtHeading.crossProduct(newTangent);

	SetHeading(vector3df(lookAtHeading.X, 0, lookAtHeading.Z)); 
}
コード例 #3
0
bool CameraController::OnEvent(const SEvent& event)
{
	closeCursorPosition();

	if (event.EventType == EET_MOUSE_INPUT_EVENT) {

		if (event.MouseInput.Event == EMIE_MOUSE_MOVED) {
			ICursorControl* cursor = _game->getDevice()->getCursorControl();
			vector2df position = cursor->getRelativePosition();

			vector2df delta = position - _previousMousePosition;
			_previousMousePosition = position;

			_cameraAngles += 
				vector2df(delta.X, delta.Y)*_config.MouseSensitivity;

			if (_cameraAngles.Y > MAX_THETA_VALUE)
				_cameraAngles.Y = MAX_THETA_VALUE;
			if (_cameraAngles.Y < MIN_THETA_VALUE)
				_cameraAngles.Y = MIN_THETA_VALUE;

			refreshPosition();

			return true;
		}

		if (event.MouseInput.Event == EMIE_MOUSE_WHEEL) {
			_cameraRadius += 
				event.MouseInput.Wheel*_config.WheelSensitivity;

			if (_cameraRadius > _config.MaxCameraRadius)
				_cameraRadius = _config.MaxCameraRadius;
			if (_cameraRadius < _config.MinCameraRadius)
				_cameraRadius = _config.MinCameraRadius;

			refreshPosition();

			return true;
		}

	}

	return false;
}