# View matrix look at.

This topic is 4966 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Ok, so I seem to have confused myself a bit in the wee hours of the night. I was trying to create a world transformation matrix that would translate my mesh and make it look at a specific point. I thought it would be simple and clever to use D3DXMatrixLookAtLH to create the matrix, by passing it my meshes position, look-at and up vectors. This didn't work, and after doing some investigating I remembered how the view matrix works. I just want to verify with you all that it all works the way I think it works. The D3DXMatrixLookAtLH function creates a look-at view matrix that transforms the points in worldspace such that the camera would be viewing from the origin and looking along the positive Z axis. Trying to use D3DXMatrixLookAtLH to transform my mesh from model space to look at a world space point, was in fact transforming the mesh to how it would appear as if viewed in model while looking at the look-at point of model space. So in other words I was orientating a "camera" in model space to view how the mesh was to appear in world space from the origin looking along the positive Z axis. Sound correct to everyone? Thanks for any comments/suggestions you all might have to help me wrap my head around this.

##### Share on other sites

in my opinion...

a lookat matrix transform vertices into the camera object space ( which is the one you described). So if you want to move your object space mesh into world space using a lookat camera you will have to use the Inverse of the lookat camera.

##### Share on other sites
I just use this standard matrix in OpenGL:
[ Sx Ux Fx Px ][ Sy Uy Fy Py ][ Sz Uz Fz Pz ][ 0  0  0  1  ]

It'd be the transpose of that I suppose for D3D...

##### Share on other sites
Quote:
 Original post by mizar77So if you want to move your object space mesh into world space using a lookat camera you will have to use the Inverse of the lookat camera.

That's what I tried, but I seem to be having a problem with my mesh being rotated 180 degrees on its up vector (it's facing backwards). I understand this from the camera point of view, but could someone try to explain why this? I think my problem is in visualizing the inverse of a matrix.

I was able to solve that by moving the lookAt point to the other side of the position by doing this. I don't really understand the math of why I have to do this.
lookAtVec = positionVec + (positionVec - lookAtVec);

So if I want my mesh to be translated into world space so that it is at
position: (10,10,10) up: (0,1,0) lookAt: (0,0,0), then I need to move the look at point to the colinear point equal distance to the position on the other side of the position, which is (20,20,20). Then create a view matrix with these parameters and take the inverse of it.

Well, it works. I can see why it works. But I don't understand why it works. I guess that the problem with using D3DX and other libraries.

Thanks for the help.

##### Share on other sites
Quote:
 Original post by python_regiousI just use this standard matrix in OpenGL:[ Sx Ux Fx Px ][ Sy Uy Fy Py ][ Sz Uz Fz Pz ][ 0 0 0 1 ]It'd be the transpose of that I suppose for D3D...

I was wondering if you could explain what the S U F and P vectors are.
I'm assuming that they are Side, Up, Forward, and Position vectors, is this correct?

and the transpose would be
[ Sx Sy Sz 0 ][ Ux Uy Uz 0 ][ Fx Fy Fz 0 ][ Px Py Pz 1 ]

I'll give it a shot thanks!

Edit: ok I tried it out and got the same results as using the d3dx function (atleast I think i did :D ). Thanks for shedding some light on the inner workings :)

Edit: typo

[Edited by - SiliconMunky on June 17, 2005 4:26:55 PM]

##### Share on other sites
Quote:
Original post by SiliconMunky
Quote:
 Original post by python_regiousI just use this standard matrix in OpenGL:[ Sx Ux Fx Px ][ Sy Uy Fy Py ][ Sz Uz Fz Pz ][ 0 0 0 1 ]It'd be the transpose of that I suppose for D3D...

I was wondering if you could explain what the S U F and P vectors are.
I'm assuming that they are Side, Up, Forward, and Position vectors, is this correct?

and the transpose would be
[ Sx Sy Sz 0 ][ Ux Uy Uz 0 ][ Fx Fy Fz 0 ][ Px Py Pz 1 ]

I'll give it a shot thanks!

Edit: ok I tried it out and got the same results as using the d3dx function (atleast I think i did :D ). Thanks for shedding some light on the inner workings :)

Edit: typo

Exactly correct [smile].

As for your problem, if you make the front vector point to the position you want the object to look at, and derive the other vectors from this, the object you apply this matrix to will "look" at that position. I've used this before for making models always face a certain direction.

##### Share on other sites
Correct me if I'm wrong - but for the translation part of the vector don't you have to dot each component with their axis

so

41 = -dot(T,S);
42 = -dot(T,U);
43 = -dot(T,F);

##### Share on other sites
It depends on what you're doing.

If you want to transform a point into a frame - for instance a camera transform, then yes, you would have the inverse of:
[ Sx Ux Fx Px ][ Sy Uy Fy Py ][ Sz Uz Fz Pz ][ 0  0  0  1  ]

Which is:
[ Sx Sy Sz -P.S ][ Ux Uy Uz -P.U ][ Fx Fy Fz -P.F ][ 0  0  0    1  ]

However, if you want to transform a point by a frame, then you don't.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 9
• 31
• 16
• 11
• 10
• ### Forum Statistics

• Total Topics
634122
• Total Posts
3015621
×