Original Post
🔒 Locked
Extract camera position from view matrix?
Advertisement
The view position (or rather the inverse translation) is stored in _41, _42, and _43 of the D3DMATRIX/D3DXMATRIX structure.
Jim Adams
home.att.net/~rpgbook
Author, Programming Role-Playing Games with DirectX
Jim Adams
home.att.net/~rpgbook
Author, Programming Role-Playing Games with DirectX
Are you sure of that? I''ve just tried it like this:
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...
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...
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
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
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]
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]
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement