In D3DXMATRIX structure, which part is xyz?

Started by
9 comments, last by Jiia 19 years ago
Hi in the D3DXMATRIX structure, I was wondering which part represents the xyz?
Quote: typedef struct D3DXMATRIX { FLOAT _11, FLOAT _12, FLOAT _13, FLOAT _14, FLOAT _21, FLOAT _22, FLOAT _23, FLOAT _24, FLOAT _31, FLOAT _32, FLOAT _33, FLOAT _34, FLOAT _41, FLOAT _42, FLOAT _43, FLOAT _44 ); } D3DXMATRIX;
thanks
Advertisement
Normally,

X: _11, _12, _13
Y: _21, _22, _23
Z: _31, _32, _33
T: _41, _42, _42
0: _14, _24, _34
1: _44

"T" means translation.

BTW, OpenGL is the same.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
hmm saying it was the view matrix, how would I get the position of the camera?

Thanks
Quote:Original post by johnnyBravo
hmm saying it was the view matrix, how would I get the position of the camera?

Thanks


You must invert the view matrix to get the position and orientation of the camera.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
ok well if you want to transform a matrix along the x, y, or z you would use ._41, ._42, ._43 respectively ... not sure what this other dude's talking about.
The view matrix generated by D3DXMatrixLookAtLH is: 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)  1where the eye vector represent the camera's position.Considering that:dot(V1,V2) = V1.x*V2.x + V1.y*V2.y + V1.z*V2.zand E11 E12 E13 E14E21 E22 E23 E24E31 E32 E33 E34E41 E42 E43 E44are the elements from a view matrix, based on the matrix generated by D3DXMatrixLookAtLH we can say:E41 = -(E11*eye.x + E21*eye.y + E31*eye.z)E42 = -(E12*eye.x + E22*eye.y + E32*eye.z)E43 = -(E13*eye.x + E23*eye.y + E33*eye.z)or in a matricial form:                        E11 E12 E13[eye.x, eye.y, eye.z] * E21 E22 E23 = -[E41, E42, E43]                        E31 E32 E33 You must solve this system to find the camera's position (eye), that is:eye * M = -V   =>   eye = -V * inverse(M)Since the camera coordinate system is an orthonormal entity:inverse(M) = transpose(M)So:                                           E11 E21 E31[eye.x, eye.y, eye.z] = -[E41, E42, E43] * E12 E22 E32                                            E13 E23 E33 


A simple way, as JohnBolton said, is inverting the view matrix. Why?... think a bit about that [wink].
Probably just a repeat of what has already been posted here, but this helped me.
You guys are all backwards [smile]

You don't have a matrix for your camera's state? It has to be one of the most useful matrices. Why invert the view matrix to get the camera matrix? Why not invert a camera matrix to get the view matrix?

Then later you can use quaternions or such to change the camera matrix and your view matrix calculation always stays the same.
Quote:Original post by Jiia
Why invert the view matrix to get the camera matrix? Why not invert a camera matrix to get the view matrix?

Maybe we are using different names for the same thing [smile]. What did you mean with camera matrix? For me, the camera matrix and the view matrix are the same thing.
The view matrix is just a math resource that transforms vector coordinates from the world space to the view space. Inverting the view matrix will result a matrix that transforms vector coordinates from the view space to the world space.
OK, clearing up the things:

The camera's eye position is expressed relative to the world coordinate system. Since it is the origin of the camera coordinate system, its coordinates are (0,0,0) when expressed relative to the camera coordinate system.

As I mentioned on my last post, by inverting the view matrix we can transform vector coordinates from the view space to the world space. So, we just need to transform the origin of the camera coordinate system to the world space, as shown below:

Eye = [0,0,0] * inverse(view matrix)


Using the Direct3D functions, we just need to do:

// supposing that you already created the view matrix
D3DXMatrixInverse( &matView, NULL, &matView );
D3DXVec3TransformCoord( &Eye, &D3DXVECTOR3(0.0f,0.0f,0.0f), &matView );

This topic is closed to new replies.

Advertisement