#### Archived

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

# 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.

## 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 on other sites
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 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.

##### 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 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 on other sites
as long as youre multiplying 3x3 matrices instead of 4x4 i dont think you will be getting anywhere.

##### 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 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 matrices1 0 0 0       1  0  0  00 1 0 0   *   0  1  0  00 0 1 0       0  0  1  00 0 0 1       tx ty tz 1// Gives you the following matrix1  0  0  00  1  0  00  0  1  0tx ty tz 1// Multiplying these1   0   0   0       1   0   0   00   1   0   0   *   0   1   0   00   0   1   0       0   0   1   0tx1 ty1 tz1 1       tx2 ty2 tz2 1// Gives this1          0          0          00          1          0          00          0          1          0tx1 + tx2  ty1 + ty2  tz1 + tz2  1

Cheers,

1. 1
2. 2
JoeJ
20
3. 3
frob
19
4. 4
5. 5

• 10
• 11
• 12
• 13
• 9
• ### Forum Statistics

• Total Topics
632206
• Total Posts
3004772

×