# reopen: D3DXMatrixLookAtRH & D3DXMatrixLookAtLH

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

## Recommended Posts

link to the closed thread: http://www.gamedev.net/community/forums/topic.asp?topic_id=505156 I am trying to get for every moment in the game the vector of the camera position and the vector where camera is looking at. And i would also like to set those parameters. For the games that use D3DXMatrixLookAtRH or D3DXMatrixLookAtLH that should be possible.

##### Share on other sites
Those two functions are defined as WINAPI so I'd imagine you can hook them using normal DLL injection stuff. Must admit to not having bothered with this myself so I'll refrain from commenting!

Doing a little digging around it wasn't too hard to find the definitions for those two functions:

Right-Handed:
zaxis = normal(cameraPosition - cameraTarget)xaxis = normal(cross(cameraUpVector, zaxis))yaxis = cross(zaxis, xaxis) xaxis.x                      yaxis.x                      zaxis.x                     0 xaxis.y                      yaxis.y                      zaxis.y                     0 xaxis.z                      yaxis.z                      zaxis.z                     0-dot(xaxis, cameraPosition)  -dot(yaxis, cameraPosition)  -dot(zaxis, cameraPosition)  1

Left-Handed:
zaxis = normal(cameraTarget - cameraPosition)xaxis = normal(cross(cameraUpVector, zaxis))yaxis = cross(zaxis, xaxis) xaxis.x                      yaxis.x                      zaxis.x                     0 xaxis.y                      yaxis.y                      zaxis.y                     0 xaxis.z                      yaxis.z                      zaxis.z                     0-dot(xaxis, cameraPosition)  -dot(yaxis, cameraPosition)  -dot(zaxis, cameraPosition)  1

Obviously, finding the camera direction is trivial from either of the above matrices.

Deriving the camera position shouldn't be too hard, but probably just requires solving a three-way simultaneous equation:

M41 = -(xaxis.x * cameraPosition.x + xaxis.y * cameraPosition.y + xaxis.z * cameraPosition.z)M42 = -(yaxis.x * cameraPosition.x + yaxis.y * cameraPosition.y + yaxis.z * cameraPosition.z)M43 = -(zaxis.x * cameraPosition.x + zaxis.y * cameraPosition.y + zaxis.z * cameraPosition.z)cameraPosition.x = (-M41 - xaxis.y * cameraPosition.y - xaxis.z * cameraPosition.z) / xaxis.xcameraPosition.y = (-M42 - yaxis.x * cameraPosition.x - yaxis.z * cameraPosition.z) / yaxis.ycameraPosition.z = (-M43 - zaxis.x * cameraPosition.x - zaxis.y * cameraPosition.y) / zaxis.z=> cameraPosition.x = (-M41 - xaxis.y * ((-M42 - yaxis.x * cameraPosition.x - yaxis.z * ((-M43 - zaxis.x * cameraPosition.x - zaxis.y * cameraPosition.y) / zaxis.z)) / yaxis.y) - xaxis.z * ((-M43 - zaxis.x * cameraPosition.x - zaxis.y * cameraPosition.y) / zaxis.z)) / xaxis.x

etc...etc... [smile]

Probably a much easier/simpler way of doing it, but i'm a little rusty on my linear algebra [sad]

hth
Jack

##### Share on other sites
Jack thank you very much for the reply!

I am sorry I was not clear on what my problem is. The thing is that I would like to get this for all games that exist out there and all games do not use D3DXMatrixLookAtRH or D3DXMatrixLookAtLH functions. For the ones that use these functions the problem is trivial.

But there are some games, that have custom written transform functions and do not use D3DXMatrixLookAtRH or D3DXMatrixLookAtLH. So I was wondering how could I get that information from there.

##### Share on other sites
Quote:
 Original post by sparrow666But there are some games, that have custom written transform functions and do not use D3DXMatrixLookAtRH or D3DXMatrixLookAtLH. So I was wondering how could I get that information from there.
With difficulty and no guarantees I would imagine!

Much like Steve commented in your previous thread - if a game uses old fixed function routines you can just hook ::SetTransform(), but if shaders are involved you can only really make a guess as to what to hook. Complex reflection via D3D10 might well yield some good hints as to which registers/variables the matrices are stored in, but there is no guarantee of reliability here.

In particular, most games will pass in world*view*proj as a single matrix into a shader. This just makes it a royal PITA to try and decompose back to the basic inputs!

hth
Jack

##### Share on other sites
I see.

So the only way to get the view matrix from the newer applications would be hooking game specific function that handles the view matrix?

1. 1
2. 2
frob
20
3. 3
Rutin
17
4. 4
5. 5

• 13
• 13
• 10
• 9
• 18
• ### Forum Statistics

• Total Topics
632555
• Total Posts
3007040

×