• Advertisement
Sign in to follow this  

Camera Input Lag

This topic is 2742 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey folks,

I'm having a bit of trouble implementing camera rotations around the y axis. I've set up my editor so that mouse rotations are enabled when the user presses down on the right mouse button.

The problem is that after rotation begins, say yaw to the left, and the mouse movement changes direction, the camera still rotates for a few frames to the left before switching so that it yaws to the right.

Below is the code I'm using to implement camera yaw:


// This will rotate the camera based on the direction that the mouse is moving in. m_mouseDelta is updated
// every frame, and is the old mouse position subtracted from the new one.
case CameraMovementType.CMT_Rotate :
System.Console.WriteLine("MOUSE DELTA = {0:n} {1:n}", m_mouseDelta.X, m_mouseDelta.Y);
if( m_mouseDelta.X > 0 )
{
camera.RotateCamera(BasicCamera.CameraRotation.CR_YAW_LEFT);
}
else if( m_mouseDelta.X < 0 )
{
camera.RotateCamera(BasicCamera.CameraRotation.CR_YAW_RIGHT);
}


...

// This is code taken from the camera class instance used above. m_rotationSpeed is 0.01f
case CameraRotation.CR_YAW_LEFT:
{
m_rotation.Y -= m_rotationSpeed;
ClampRotationAngle(RotationAxis.RA_Y);
System.Console.WriteLine("YAW LEFT ROTATION Y : {0:f4}\n", m_rotation.Y);
Matrix yawMatrix = Matrix.CreateFromAxisAngle(m_upDirection, m_rotation.Y);
m_rightDirection = Vector3.Transform(m_rightDirection, yawMatrix);
m_lookAt = Vector3.Transform(m_lookAt, yawMatrix);
m_previousRotation = CameraRotation.CR_YAW_LEFT;
}
break;

case CameraRotation.CR_YAW_RIGHT:
{
m_rotation.Y += m_rotationSpeed;
ClampRotationAngle(RotationAxis.RA_Y);
System.Console.WriteLine("YAW RIGHT ROTATION Y : {0:f4}\n", m_rotation.Y);
Matrix yawMatrix = Matrix.CreateFromAxisAngle(m_upDirection, m_rotation.Y);
m_rightDirection = Vector3.Transform(m_rightDirection, yawMatrix);
m_lookAt = Vector3.Transform(m_lookAt, yawMatrix);
m_previousRotation = CameraRotation.CR_YAW_RIGHT;
}
break;




The output from the console.Writeline for a change in direction looks like this:


MOUSE DELTA = 1.00 0.00
YAW LEFT ROTATION Y : -0.0100

MOUSE DELTA = 2.00 0.00
YAW LEFT ROTATION Y : -0.0200

MOUSE DELTA = 1.00 0.00
YAW LEFT ROTATION Y : -0.0300

MOUSE DELTA = 1.00 0.00
YAW LEFT ROTATION Y : -0.0400

MOUSE DELTA = 1.00 0.00
YAW LEFT ROTATION Y : -0.0500

MOUSE DELTA = 1.00 0.00
YAW LEFT ROTATION Y : -0.0600

MOUSE DELTA = 1.00 0.00
YAW LEFT ROTATION Y : -0.0700

MOUSE DELTA = 1.00 0.00
YAW LEFT ROTATION Y : -0.0800

MOUSE DELTA = -1.00 1.00
YAW RIGHT ROTATION Y : -0.0700

MOUSE DELTA = -1.00 0.00
YAW RIGHT ROTATION Y : -0.0600

MOUSE DELTA = -1.00 0.00
YAW RIGHT ROTATION Y : -0.0500

MOUSE DELTA = -1.00 0.00
YAW RIGHT ROTATION Y : -0.0400

MOUSE DELTA = -1.00 0.00
YAW RIGHT ROTATION Y : -0.0300

MOUSE DELTA = -1.00 0.00
YAW RIGHT ROTATION Y : -0.0200

MOUSE DELTA = -1.00 0.00
YAW RIGHT ROTATION Y : -0.0100

MOUSE DELTA = -1.00 0.00
YAW RIGHT ROTATION Y : 0.0000

MOUSE DELTA = -1.00 1.00
YAW RIGHT ROTATION Y : 0.0100

MOUSE DELTA = -1.00 0.00
YAW RIGHT ROTATION Y : 0.0200

MOUSE DELTA = -1.00 0.00
YAW RIGHT ROTATION Y : 0.0300

MOUSE DELTA = -1.00 0.00
YAW RIGHT ROTATION Y : 0.0400

MOUSE DELTA = -1.00 0.00
YAW RIGHT ROTATION Y : 0.0500

MOUSE DELTA = -2.00 1.00
YAW RIGHT ROTATION Y : 0.0600

MOUSE DELTA = -1.00 0.00
YAW RIGHT ROTATION Y : 0.0700

MOUSE DELTA = -1.00 0.00
YAW RIGHT ROTATION Y : 0.0800

MOUSE DELTA = -1.00 0.00
YAW RIGHT ROTATION Y : 0.0900

MOUSE DELTA = -1.00 1.00
YAW RIGHT ROTATION Y : 0.1000

MOUSE DELTA = -1.00 0.00
YAW RIGHT ROTATION Y : 0.1100

MOUSE DELTA = -1.00 0.00
YAW RIGHT ROTATION Y : 0.1200

MOUSE DELTA = -1.00 0.00
YAW RIGHT ROTATION Y : 0.1300




Any ideas as to why I would be getting this input lag would be greatly appreciated!

Share this post


Link to post
Share on other sites
Advertisement
Quote:
m_rightDirection = Vector3.Transform(m_rightDirection, yawMatrix);
m_lookAt = Vector3.Transform(m_lookAt, yawMatrix);

From your code, it appears that you want yawMatrix to be the direction for m_lookAt. The code above, however, adds the full amount of the rotation each mouse move.

If you want m_lookAt to point in the direction of the yaw angle, use a base lookat vector each time.

Something like:

m_lookAt = Vector3.Transform(Vector3(0,0,1),yawMatrix);

In the above line, change Vector3(0,0,1) to the camera direction when the yaw angle = 0.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement