Skip to main content
gamedev.net
🔒 Locked

Extract camera position from view matrix?

Started by CamelFly Jun 16, 2002 at 6:39 AM 4 replies 9.4k views
Original Post
CamelFly
CamelFly
How do you extract the camera position from view matrix? I know it can be done but I dont really get it to work properly. thank.
[Insert cool signature here]
CamelFly
CamelFly
Thanks! I''ve tried several methods, none working. Will try your solution instantaniously.
[Insert cool signature here]
CamelFly
CamelFly
Are you sure of that? I''ve just tried it like this:


  
D3DXVECTOR3 Device::GetCameraPosition() {
D3DXMATRIX matView;
HRESULT hr = m_pDev->GetTransform(D3DTS_VIEW, &matView);
assert(!FAILED(hr));

D3DXVECTOR3 vDot(matView._41, matView._42, matView._43);
return vDot;
}


and it does not work. The Z axis is correct if negated as long as you do not turn the camera. If you turn the camera the values change around, which they shouldn''t as the camera stands still...
[Insert cool signature here]
Jim Adams
Jim Adams
It could be have been created another method, which makes the view matrix look like this:

Ux Vx Nx 0
Uy Vy Ny 0
Uz Vz Nz 0
-(U*C) -(V*C) -(N*C) 1

U, V, and N represent the up, right, and direction vectors, and c is the camera''s world space position.




Jim Adams
home.att.net/~rpgbook
Author, Programming Role-Playing Games with DirectX
CamelFly
CamelFly
I made the matrix by
D3DXMatrixLookAtLh() method

and I should correct myself

If you do not rotate the camera, everything works but is negated, if you rotate it the valueas are messed up

(you are a fast replyer )

Edit 1:
It probably does not look like the other type of matrix that you showed my, since the fourth collumn that I used when implmenting you other method contains values, they just get screwed up upon rotation.

Edit 2:
From the DirectX documentation it says:
This function uses the following formula to compute the returned matrix.

zaxis = normal(At - Eye)
xaxis = normal(cross(Up, 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, eye) -dot(yaxis, eye) -dot(zaxis, eye) 1

Which makes no sense to me, since i read the fourth column, and there was definitly not 0

[edited by - CamelFly on June 17, 2002 4:04:59 AM]

[edited by - CamelFly on June 17, 2002 4:07:02 AM]
[Insert cool signature here]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.