reopen: D3DXMatrixLookAtRH & D3DXMatrixLookAtLH

Started by
3 comments, last by sparrow666 15 years, 7 months ago
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.
Advertisement
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

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

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.
Quote:Original post by sparrow666
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.
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

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

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?

This topic is closed to new replies.

Advertisement