0
101 Mar 15, 2009 at 11:12

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.

#### 2 Replies

0
103 Mar 15, 2009 at 11:17

You can use the view matrix to do it.

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.

0
101 Mar 15, 2009 at 19:22

Thanx rouncer, and what a quick reply. this will be of great help.