Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


4x4 rotation matrix

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

Hello everyone, In DirectX 8.0, assuming i already got 3 normalized D3DXVECTOR3 vectors: a forward vector, an up vector, and a right vector, how can i use these to build up a rotation matrix that can be multiplied by the world matrix with the translation matrix for displaying an object. I already got the direction vectors (as stated above), i just need to know how to put them into the 4x4 matrix (where they go in the D3DXMATRIX) and use that as the rotation matrix or can you not use that data directly for the rotation matrix and some how have to build one up? Sincerely, Scott Richmond Viper Digital

Share this post

Link to post
Share on other sites
Your question is not very clear, that is why the reply below may or may not be what you looking for.

you store your object translation, and rotation in matrecies which you look to know that.Then you combine all those matrecies together to produce the final behavior of the object, nothing about the object orientation on 3d and on the screen yet.

The view and projection matrecies are set indpendent of each other and indpendent of the object transformation matrix.

Then as you indicated you multiply the three matrices to transfer the vertecies from there own axis into the screen axis.

There are plenty of tutorials that clearly explains this subject, you may wana look to the sdk/samples/multimedia/direct3d/tutorials/tutorial3

If love is illusion and hate is real, I would rather be crazy

Share this post

Link to post
Share on other sites

Here's one way that will work, though probably not the most efficient (I'm curious to see the methods posted by others).

A thread a few days ago had to do with how to rotate a "monster" character to face the camera. I am getting some of this algorithm from the code suggested by nyStagmus in that thread.

Here's some C++ (untested, mind you):

// D3DXVECTOR3 translation; // translation offsets

// D3DXVECTOR3 lookAt, up; // look-at, up vectors

D3DXMatrix inverseMatrix, worldMatrix;

D3DXMatrixLookAtLH(&inverseMatrix, &translation, &lookAt, &up);
D3DXMatrixInverse(&worldMatrix, NULL, &inverseMatrix);

// NOTE: the following block of code may not be necessary...

worldMatrix._41 = translation.x;
worldMatrix._42 = translation.y;
worldMatrix._43 = translation.z;

Note that I do not know if the last block of code is necessary or not; I don't know if D3DXMatrixLookAtLH actually creates a translation offset from parameter 2 or if it just uses parameter 2 to compute rotation angles. Try it yourself and see!

(edit: replaced "right" vector with "up" vector in code.)

[edited by - HoozitWhatzit on July 23, 2002 1:55:03 AM]

Share this post

Link to post
Share on other sites
If you already have the 3 vectors, and they''re all normalised and at right angles to each other (and they weren''t expensive to calculate, a few crossprods is still usually cheaper than an inverse):

1. Set the matrix to identity (to clear out the elements you aren''t using).

2. Set the following members of the matrix:
_11 = right.x;
_21 = right.y;
_31 = right.z;
_12 = up.x;
_22 = up.y;
_32 = up.z;
_13 = forward.x;
_23 = forward.y;
_33 = forward.z;

The top 3x3 part of a 4x4 matrix is the bit which does rotations.
The 3, normalised, perpendicular vectors are known as an orthonormal basis (if you want to search for it to get yourself up to speed on the maths).

Simon O''Connor
Creative Asylum Ltd

Share this post

Link to post
Share on other sites

  • 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!