Geometric approach to finding 8 points of the view frustum?

Started by
2 comments, last by terryeverlast 9 years, 2 months ago

vfpoints2.gif

If the camera is positioned at (-20,35,-50)

And finding the d – a vector with the direction of the camera’s view ray. In here it is assumed that this vector has been normalized

which d = w ..in the picture below and it is normalized.

camera is positioned at (–20, 35, –50) and looking at the point (10, 0, 30).

T = (10, 0, 30)

241pbh2.jpg

So with that info, and the formula

fc = p + d * farDist

1. fc is the center of the far plane of the view frustum

2. p is the position of the camera

3. d is the direction of the camera view

4. farDist is the distance between the camera and the farplane

Im using this perspective matrix

jv4v3b.jpg

Which the distance is 200 from the camera and the far plane.

so does fc(farplane center) = (44.98,-40.82,123.28)

Advertisement

I found another way.

Take
(0,0,0) Bottom Left Near,
(0,0,1) Bottom Left Far,
(0,1,0) Bottom Right Near...and so on

and multiply it by (viewMatrix*ProjectionMatrix)-1 .......the inverse of those multiplied together.

is this right?

Ok..i think I got it but I need someone to verify this code if it is right.


#include <iostream>
#include <conio.h>
#include <D3dx9math.h>
using namespace std;
void main()
{


	D3DXMATRIXA16 mat;
D3DXVECTOR3 vecFrustum[8];

 D3DXMATRIX matView;
 D3DXMATRIX matProj;

matView._11 = 0.9363f;
matView._12 = 0.1331f;
matView._13 = 0.3249f;
matView._14 = 0.0f;
matView._21 = 0.0f;
matView._22 = 0.9253f;
matView._23 = -0.3791f;
matView._24 = 0.0f;
matView._31 = -0.3511f;
matView._32 = 0.3549f;
matView._33 = 0.8664f;
matView._34 = 0.0f;
matView._41 = 1.170f;
matView._42 = -11.98f;
matView._43 = 63.09f;
matView._44 = 1.0f;

matProj._11 = 1.86603;
matProj._12 = 0.0;
matProj._13 = 0.0f;
matProj._14 = 0.0f;
matProj._21 = 0.0f;
matProj._22 = 3.73205f;
matProj._23 = 0.0;
matProj._24 = 0.0f;
matProj._31 = 0.0f;
matProj._32 = 0.0f;
matProj._33 = 1.02564f;
matProj._34 = 1.0f;
matProj._41 = 0.0f;
matProj._42 = 0.0f;
matProj._43 = -5.12821f;
matProj._44 = 0.0f;




//1. multiply the matrices together
D3DXMatrixMultiply( &mat, &matView, &matProj );
D3DXMatrixInverse( &mat, NULL, &mat );

//2. create the 8 points of a cube in unit-space
vecFrustum[0] = D3DXVECTOR3(-1.0f, -1.0f,  0.0f); // xyz
vecFrustum[1] = D3DXVECTOR3( 1.0f, -1.0f,  0.0f); // Xyz
vecFrustum[2] = D3DXVECTOR3(-1.0f,  1.0f,  0.0f); // xYz
vecFrustum[3] = D3DXVECTOR3( 1.0f,  1.0f,  0.0f); // XYz
vecFrustum[4] = D3DXVECTOR3(-1.0f, -1.0f,  1.0f); // xyZ
vecFrustum[5] = D3DXVECTOR3( 1.0f, -1.0f,  1.0f); // XyZ
vecFrustum[6] = D3DXVECTOR3(-1.0f,  1.0f,  1.0f); // xYZ
vecFrustum[7] = D3DXVECTOR3( 1.0f,  1.0f,  1.0f); // XYZ

//3. transform all 8 points by the view/proj matrix. Doing this
//	 gives us that ACTUAL 8 corners of the frustum area.
for( int i = 0; i < 8; i++ )
    D3DXVec3TransformCoord( &vecFrustum[i], &vecFrustum[i], &mat );




cout << "(" << vecFrustum[0].x << "," << vecFrustum[0].y << "," << vecFrustum[0].z << ")" << " NBLC";
cout << endl;
cout << "(" << vecFrustum[1].x << "," << vecFrustum[1].y << "," << vecFrustum[1].z << ")" << " NBRC";
cout << endl;
cout << "(" << vecFrustum[2].x << "," << vecFrustum[2].y << "," << vecFrustum[2].z << ")" << " NTLC";
cout << endl;
cout << "(" << vecFrustum[3].x << "," << vecFrustum[3].y << "," << vecFrustum[3].z << ")" << " NTRC";
cout << endl;
cout << "(" << vecFrustum[4].x << "," << vecFrustum[4].y << "," << vecFrustum[4].z << ")" << " FBLC";
cout << endl;
cout << "(" << vecFrustum[5].x << "," << vecFrustum[5].y << "," << vecFrustum[5].z << ")" << " FBRC";
cout << endl;
cout << "(" << vecFrustum[6].x << "," << vecFrustum[6].y << "," << vecFrustum[6].z << ")" << " FTLC";
cout << endl;		
cout << "(" << vecFrustum[7].x << "," << vecFrustum[7].y << "," << vecFrustum[7].z << ")" << " FTRC";
cout << endl;



	getch();
}

Never mind. I got it with this link after looking for days

http://gamedev.stackexchange.com/questions/19774/determine-corners-of-a-specific-plane-in-the-frustum

This topic is closed to new replies.

Advertisement