/**
 *	Handles a mouse event. The majority of changes to the DirectionCursor will
 *	come from events from positional devices, such as joysticks and mouses.
 *
 *	@param	event		The mouse event.
 *
 *	@return	True, if the event was processed. False, if the event was ignored.
 */
bool DirectionCursor::handleMouseEvent( const MouseEvent &event )
{
	BW_GUARD;
	// Find the mouse sensitivity
	float msens = this->mouseSensitivity() *
		Moo::rc().camera().fov() / DEG_TO_RAD( 60.f );

	// Adjust raw mouse values into changes in angle.
	Angle dYaw = event.dx() * this->mouseHVBias() * msens;
	Angle dPitch = event.dy() * ( 1.0f - this->mouseHVBias() ) * msens;

	// Apply the changes to current cursor direction.
	Angle newYaw( this->yaw() + dYaw );
	if ( yawReference_ )
	{
		Matrix m;
		yawReference_->matrix( m );
		float yawRefVal = m.yaw();
		newYaw.clampBetween( yawRefVal+minYaw_, yawRefVal+maxYaw_ );
	}
	this->yaw( newYaw );

	if ( this->invertVerticalMovement() )
	{
		this->pitch( this->pitch() + dPitch );
	}
	else
	{
		this->pitch( this->pitch() - dPitch );
	}

	// Limit the pitch values.
	this->pitch( Math::clamp( this->minPitch(),
		this->pitch(),
		this->maxPitch() ) );

	// Set the dirty flag for direction.
	refreshDirection_ = true;

	// Reset elapsed time for kicking in the look-spring behaviour.
	elapsedTimeForLookSpring_ = 0.0;

	// Event has been handled.
	return true;
}
Esempio n. 2
0
void PlayerCharacter::processMouseInput(Ogre::Real elapsedTime)
{
	if(InputManager::getSingleton().isMouseButtonPressed(OIS::MB_Right))
	{
		Ogre::Radian newYaw(InputManager::getSingleton().getMouseExtraData().x * elapsedTime * -300.0f);

		//Also update the camera if the right mouse button is pressed
		mGameContext->getCameraControl()->updateYaw(newYaw);

		Ogre::Radian cameraYaw = mGameContext->getCameraControl()->getTargetNodeOrientation().getYaw();
		Ogre::Radian yawDifference = cameraYaw - mMainNode_->getOrientation().getYaw();

		//Prevent a 359,99..° turn
		if(yawDifference < Ogre::Radian(-3.0f))
		{
			cameraYaw += Ogre::Radian(6.0f);
			yawDifference = cameraYaw - mMainNode_->getOrientation().getYaw();
		}
		else if(yawDifference > Ogre::Radian(3.0f))
		{
			cameraYaw -= Ogre::Radian(6.0f);
			yawDifference = cameraYaw - mMainNode_->getOrientation().getYaw();
		}

		//Slow down the roatation
		if(yawDifference > Ogre::Radian(0.01f) || yawDifference < Ogre::Radian(-0.01f))
			yawDifference = yawDifference * elapsedTime;

		//Limit the rotation to a maximum
		if( yawDifference > mRotationSpeedModificator)
			yawDifference = mRotationSpeedModificator;
		else if( yawDifference < -mRotationSpeedModificator)
			yawDifference = -mRotationSpeedModificator;

		//Position the player slowly to the camera direction
		mMainNode_->yaw(yawDifference);
	}
}