Hi,
Im want to calculate the visible horizontal XZ plane in my viewport.
My known variables are.
Horizontal FOV = 45 degrees
the vector from my camera to the camera target(the world origin)
The width and height of my viewport = 600 * 400 pixels
What i want to calculate is the visible 3d points on the horizontal plane at the upper left, right and the lower left and right of my viewport.
thanx in advance
calculate visible horizontal plane in viewport?
Started by MMWizard, Mar 15 2009 11:12 AM
2 replies to this topic
#1
Posted 15 March 2009 - 11:12 AM
#2
Posted 15 March 2009 - 11:17 AM
You can use the view matrix to do it.
plug the corners of the screen into the x and y coordinate and you achieve worldspace vectors for the corners of the screen, and these make the frustrum planes.
void inverse_project(MAT view, MAT proj, float x, float y, float width, float height, VEC &orig, VEC &dir)
{
D3DXVECTOR3 vPickRayDir;
D3DXVECTOR3 vPickRayOrig;
D3DXMATRIX matProj;
matProj=proj;
// Compute the vector of the pick ray in screen space
D3DXVECTOR3 v;
v.x = ( ( ( 2.0f * x ) / width) - 1 ) / matProj._11;
v.y = -( ( ( 2.0f * y ) / height) - 1 ) / matProj._22;
v.z = 1.0f;
// Get the inverse view matrix
D3DXMATRIX matView, m;
matView=view;
D3DXMatrixInverse( &m, NULL, &matView );
// Transform the screen space pick ray into 3D space
vPickRayDir.x = v.x*m._11 + v.y*m._21 + v.z*m._31;
vPickRayDir.y = v.x*m._12 + v.y*m._22 + v.z*m._32;
vPickRayDir.z = v.x*m._13 + v.y*m._23 + v.z*m._33;
vPickRayOrig.x = m._41;
vPickRayOrig.y = m._42;
vPickRayOrig.z = m._43;
orig=vPickRayOrig;
dir=vPickRayDir;
}
plug the corners of the screen into the x and y coordinate and you achieve worldspace vectors for the corners of the screen, and these make the frustrum planes.
#3
Posted 15 March 2009 - 07:22 PM
Thanx rouncer, and what a quick reply. this will be of great help.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











