Jump to content
  • Advertisement

Archived

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

Bacardi34

Extracting Up, Look, and Right vectors

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

I am trying to extract the up Look and Right vectors from a D3DXMATRIX that stores the position of my camera but i am not sure if i am doing it correctly. Is it [right.x up.x look.x 0] [right.y up.y look.y 0] [right.z up.z look.z 0] [1 1 1 1] I want to make a camra that will not roll, so i need to be able to make the right vector always level. Thanks for the help.

Share this post


Link to post
Share on other sites
Advertisement
I think you either meant the view matrix or the camera''s world matrix. Both are NOT the camera''s position matrix, since a position (translation) matrix won''t have any rotation info in it, and thus no right/up/forward vector stuff.

The view matrix looks like the following: (see: Docs->D3DXMatrixLookAtLH() )

xaxis.x yaxis.x zaxis.x 0
xaxis.y yaxis.y zaxis.y 0
xaxis.z yaxis.z zaxis.z 0
-dot(xaxis, eye) -dot(yaxis, eye) -dot(zaxis, eye) 1


where xaxis/yaxis/zaxis are your right/up/forward vectors.

More on the rolling problem later.

Share this post


Link to post
Share on other sites
Your right coder, it is the world matrix that i needed to get the vectors out of, and all that is working fine now.
I also figured out how to counter the roll problems.
Now i am wondering how to get the Eye point from the cameras world matrix. I need to make sure my camera does not go beyond a certain height.
Thanks for your help.. again

Share this post


Link to post
Share on other sites
The camera''s world matrix is formed by rotating the camera, then translating it by eyePos.

Ex:

D3DXMATRIX matTrans, matRot, matCam;
// Init matrices
// .
// .
// .
matCam = matRot * matTrans;

Multiply the 2 matrices by hand (or using some math tool/calculator) and check how to extract the translation from it. (don''t have time to do it now, sorry)

Share this post


Link to post
Share on other sites
Coder, i am really having trouble understanding this.
I started with the standard ident matrix for the camera:
1 0 0
0 1 0
0 0 1
Where the eye pos is 0,0,0
and then given a new eye point of 4,5,6 the new matirx would look like
5 4 4
5 6 5
6 6 7
generated by hand, assuming no rotation.
So all i can come up with is if up.x & look.x are =, that is eye.x,
if look.y and right.y are =, that is eye.y,
if up.z and right.z are =, that is eye.z.
So then i left the eye point alone, and rotated the camera down, so the right vec stays the same, and i assigned a new vector for up, and used the cross product of up and right for the look vec.
that matrix looks like
5 4 -8
4 5 -5
6 7 7
So my theory goes right out the window, as i thought it would, it was weak anyway. so i have been staring at this all day, and multiplying all kinds of arbitrary matrices on my calc to see if i can come up with a pattern, or recognize what is going on but im just not seeing it.

Share this post


Link to post
Share on other sites
I was just using 3x3 to get the general idea. Also im not quite sure how to get the dot products for the 4th row of the matrix, the book i have about dots does not explain it very well

Share this post


Link to post
Share on other sites
quote:
I started with the standard ident matrix for the camera:
1 0 0
0 1 0
0 0 1
Where the eye pos is 0,0,0

This 3x3 matrix doesn''t have an eyePos at all. It just exposes 3 vectors: Right( 1,0,0 ), up( 0,1,0 ) and forward( 0,0,1)

quote:

and then given a new eye point of 4,5,6 the new matirx would look like
5 4 4
5 6 5
6 6 7
generated by hand, assuming no rotation

When you try to include 3d translation in a transformation matrix, make sure you use a 4x4 matrix.

Here:

// Multiplying the following 2 matrices
1 0 0 0 1 0 0 0
0 1 0 0 * 0 1 0 0
0 0 1 0 0 0 1 0
0 0 0 1 tx ty tz 1

// Gives you the following matrix
1 0 0 0
0 1 0 0
0 0 1 0
tx ty tz 1

// Multiplying these
1 0 0 0 1 0 0 0
0 1 0 0 * 0 1 0 0
0 0 1 0 0 0 1 0
tx1 ty1 tz1 1 tx2 ty2 tz2 1

// Gives this
1 0 0 0
0 1 0 0
0 0 1 0
tx1 + tx2 ty1 + ty2 tz1 + tz2 1


Cheers,
Muhammad Haggag.

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!