Jump to content
  • Advertisement
Sign in to follow this  
Dark_Bob

A problem while extrapolating the camera position from an object's matrix!!!

This topic is 5140 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

Ok the problem I'm having is that when I try to extrapolate an offset camera position and orientation from an object's transform matrix. It seems to work alright initially but goes wonky fast (as in as you move around the Z axis the camera starts to bob up and down a little very, very quickly it is completely uncontrolable). I use my own Matrix class with rotations: RotateX: 1 0 0 0 cos sin 0 -sin cos RotateY: cos 0 -sin 0 1 0 sin 0 cos RotateZ: cos sin 0 -sin COS 0 0 0 1 Each frame I update the objects rotation matrix from the mouse movement multiplied by the time elapsed between frames. I use the Z axis as the up axis and the Y axis as the forward axis. Matrix3x3 rotX, rotZ, out; rotX.RotateX(MouseDeltaY*TElapse); rotZ.RotateZ(MouseDeltaX*TElapse); // rows * cols out = rotX * rotZ; object.mat = out * object.mat; I then set the camera up using D3DXMatrixLookAtLH() but I'm pretty sure this works so the problem is with my maths. The function takes a camera position, a position to look at, an up vector and returns a viewMatrix that is used to transform the view. As the camera position I pass: D3DXVECTOR3 camPos(object.pos.x-30.f*object.mat[1][0], object.pos.y-30.f*object.mat[1][1], object.pos.z-3.f*object.mat[1][2]); D3DXVECTOR3 lookAt(object.pos.x, object.pos.y, object.pos.z); D3DXVECTOR3 upVector(object.mat[2][0], object.mat[2][1], object.mat[2][2]); D3DXMATRIX matView; D3DXMatrixLookAtLH(&matView, &camPos, &lookAt, &upVector); m_pD3DDevice->SetTransform(D3DTS_VIEW, &matView); This works while rotating the object about one axis but as soon as I involve a second axis it goes out of whack. In the maths books I've read the y say the first row of a rotation matrix is the X axis vector, the second row of a rotation matrix is the Y axis vector and the third row of a rotation matrix is the Z axis vector. Maybe I've taken this too literally and it is not so but if anbody could describe the correct method I'd greatly appreciate it. Thanks for taking the time to read this!!

Share this post


Link to post
Share on other sites
Advertisement
perhaps there is something wrong with the way you multiply your matrix? can you show the code for matrix multiplication of your Matrix3x3 class please?

PS: I don't see where the extrapolation comes in? do you mean, extraction?

Share this post


Link to post
Share on other sites
Hey SpaceDude, thanks for the reply. Through some serious debugging I managed to figure out that it was floating point precision that was messing me up because I multiplied the change in rotation back into the objects transform matrix every frame the quickly the precision got all screwed. By regenerating the orientation part of the transform matrix every frame it works sweet!!!

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!