Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualDJTN

Posted 17 November 2012 - 01:43 PM

Previously I posted about a rotation issue with my camera. I thought I had solved the problem by adding frame time to the camera’s movement calculation but unfortunately this only masked the real problem, which I think is a precision issue with floats. I noticed this when I rotate not only the camera but other objects as well.

I striped my render code down to the basics in an effort to identify the issue:

[source lang="cpp"]Camera CalculationsCameraTarget.X = CameraPosition.X + Sin(vRadians)CameraTarget.Y = CameraPosition.Y + (Cos(vRadians) * Cos(hRadians))CameraTarget.Z = CameraPosition.Z + (Cos(vRadians) * Sin(hRadians))CameraUp.X = 0;CameraUp.Y = 1;CameraUp.Z = 0;Update View Matrix:D3DXMatrixLookAtLH(View_Matrix, CameraPosition, CameraTarget, CameraUp);[/source]

To make things as simple as possible I’ll add 0.002 to the hRadians float each frame. This makes the camera rotate to the left but when I slow the frame rate down I can clearly see the camera is not turning the same amount each frame. This also happens when I calculate rotations for the world matrix before rendering 3D objects too. When rendering at 60 FPS and adding an easing calculation to movements it’s not as noticeable for moving forward, backwards, left and right but when rotating, it is very noticeable. Even with the easing code added you can tell the rotations are accelerating and decelerating, sometimes jerky.


I’ve tried to truncate the calculations for the CameraTarget and CameraPosition to regain some precision but to no avail, the issue still persists.


Is this a precision issue? And if so, how can I get more precision for rotations? If it’s a not a precision problem then what is it?

#2DJTN

Posted 17 November 2012 - 01:41 PM

Previously I posted about a rotation issue with my camera. I thought I had solved the problem by adding frame time to the camera’s movement calculation but unfortunately this only masked the real problem, which I think is a precision issue with floats. I noticed this when I rotate not only the camera but other objects as well.

I striped my render code down to the basics in an effort to identify the issue:

[source lang="cpp"]Camera CalculationsCameraTarget.X = CameraPosition.X + Sin(vRadians)CameraTarget.Y = CameraPosition.Y + (Cos(vRadians) * Cos(hRadians))CameraTarget.Z = CameraPosition.Z + (Cos(vRadians) * Sin(hRadians))CameraUp.X = 0;CameraUp.Y = 1;CameraUp.Z = 0;Update View Matrix:D3DXMatrixLookAtLH(View_Matrix, CameraPosition, CameraTarget, CameraUp);[/source]

To make things as simple as possible I’ll add 0.002 to the hRadians float each frame. This makes the camera rotate to the left but when I slow the frame rate down I can clearly see the camera is not turning the same amount each frame. This also happens when I calculate rotations for the world matrix before rendering 3D objects too. When rendering a 60 FPS and adding an easing calculation to movements it’s not as noticeable for moving forward, backwards, left and right but when rotating, it is very noticeable. Even with the easing code added you can tell the rotations are accelerating and decelerating, sometimes jerky.


I’ve tried to truncate the calculations for the CameraTarget and CameraPosition to regain some precision but to no avail, the issue still persists.


Is this a precision issue? And if so, how can I get more precision for rotations? If it’s a not a precision problem then what is it?

#1DJTN

Posted 17 November 2012 - 01:40 PM

Previously I posted about a rotation issue with my camera. I thought I had solved the problem by adding frame time to the camera’s movement calculation but unfortunately this only masked the real problem, which I think is a precision issue with floats. I noticed this when I rotate not only the camera but other objects as well.

I striped my render code down to the basics in an effort to identify the issue:

[source lang="cpp"]Camera CalculationsCameraTarget.X = CameraPosition.X + Sin(vRadians)CameraTarget.Y = CameraPosition.Y + (Cos(vRadians) * Cos(hRadians))CameraTarget.Z = CameraPosition.Z + (Cos(vRadians) * Sin(hRadians))CameraUp.X = 0;CameraUp.Y = 1;CameraUp.Z = 0;Update View Matrix:View = D3DXMatrixLookAtLH(View_Matrix, CameraPosition, CameraTarget, CameraUp);[/source]

To make things as simple as possible I’ll add 0.002 to the hRadians float each frame. This makes the camera rotate to the left but when I slow the frame rate down I can clearly see the camera is not turning the same amount each frame. This also happens when I calculate rotations for the world matrix before rendering 3D objects too. When rendering a 60 FPS and adding an easing calculation to movements it’s not as noticeable for moving forward, backwards, left and right but when rotating, it is very noticeable. Even with the easing code added you can tell the rotations are accelerating and decelerating, sometimes jerky.


I’ve tried to truncate the calculations for the CameraTarget and CameraPosition to regain some precision but to no avail, the issue still persists.


Is this a precision issue? And if so, how can I get more precision for rotations? If it’s a not a precision problem then what is it?

PARTNERS