Jump to content
  • Advertisement
Sign in to follow this  
MeshMan

Up/Right/Look

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

Hi guys, I'm trying to extract the 3 Up, Right, LookAt vectors from a D3DXMATRIXA16 rotation matrix. I do the following: eyeX = mat._11; eyeY = mat._12; eyeZ = mat._13; upX = mat._21; upY = mat._22; upZ = mat._23; atX = mat._31; atY = mat._32; atZ = mat._33; Then im fiddling with the vectors and placing them back into the matrix but I'm getting some crazy results! So my question is, is it the EYE/UP/LOOKAT vectors that are in the matrix and am i extracting the elements correctly (such as eye vector is in _11, _12, _13, or is it _11, _21, _31?)? Thanks, Meshy

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by MeshMan
Then im fiddling with the vectors and placing them back into the matrix but I'm getting some crazy results!

Not too surprising [smile]

A matrix isn't just a storage for the raw values, it is itself a composition of various equations. It's often difficult, if not impossible, to "decode" a given 4x4 back down to the original parameters.

Quote:
Original post by MeshMan
So my question is, is it the EYE/UP/LOOKAT vectors that are in the matrix and am i extracting the elements correctly (such as eye vector is in _11, _12, _13, or is it _11, _21, _31?)?

If you're specifically messing with them on a regular basis, why not reconstruct the matrix. In truth, unless you're doing ridiculously complex view-transform operations you're unlikely to hit any performance problems by just calling another D3DXMatrixLookAtLH() / D3DXMatrixLookAtRH()...

hth
Jack

Share this post


Link to post
Share on other sites
Hey there Jack,

I've always had a fear of matrices because everytime I try to fiddle with them, I cannot get the kind of results I want (camera and object transformations oh my!).

I'm trying to get the 'Direction of Facing' of an object and apply it onto another object.
So what I'm trying to do is grab the positive Z axis from the matrix (this is usually referred to as the look-at vector) and stuff it into another matrix making sure I rebuild the +X (right) axis in the matrix by doing a cross-product with the Z-Y axies.

Share this post


Link to post
Share on other sites
It's not difficult to decompose the matrix into vectors. Here's an example of calculating a matrix based on the 'lookat' of a character. Assuming the character is unable to 'roll' so his right axis is always perpendicular to world up and such.

D3DXMATRIX mat;
D3DXVECTOR3 worldUpVec(0, 1, 0);
D3DXVECTOR3 xAxis;
D3DXVECTOR3 yAxis;
D3DXVECTOR3 zAxis = lookAtVector;

D3DXVec3Normalize( &zAxis, &zAxis );
D3DXVec3Cross( &xAxis, &worldUpVec, &zAxis );
D3DXVec3Normalize( &xAxis, &xAxis );

D3DXVec3Cross( &yAxis, &zAxis, &xAxis );
D3DXVec3Normalize( &yAxis, &yAxis);

mat._11 = xAxis.x;
mat._12 = xAxis.y;
mat._13 = xAxis.z;
mat._14 = 0;

mat._21 = yAxis.x;
mat._22 = yAxis.y;
mat._23 = yAxis.z;
mat._24 = 0;

mat._31 = zAxis.x;
mat._32 = zAxis.y;
mat._33 = zAxis.z;
mat._34 = 0;

mat._41 = position.x;
mat._42 = position.y;
mat._43 = position.z;
mat._44 = 1;

It's a simple example, and probably isn't correct if there should be scale taken into account, not sure.

Share this post


Link to post
Share on other sites
Right, I understand all that.

Why doesn't anyone implement any camera classes or physics movement with Z-Axis roll taken into account? Is it hard?

Share this post


Link to post
Share on other sites
Most games don't allow camera roll, and it gets more complex if you don't have a known axis to use in the computations(in this case world up)

Share this post


Link to post
Share on other sites
Ah I see.
I'm hoping to just pull the inverse positive Z-Axis vector from my camera matrix, send it to the other players (in my multiplayer FPS) which they can apply to my model as they see me.

I'm also going to want to do camera shake where I roll my camera on the Z like Quake3 did when you walk. That shouldn't affect the look-at vector at all though should it?

Share this post


Link to post
Share on other sites
Quote:
Original post by MeshMan
Right, I understand all that.

Why doesn't anyone implement any camera classes or physics movement with Z-Axis roll taken into account? Is it hard?

Take a look at D3DSmartCamera.

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!