Sign in to follow this  
resle

Yet another frustum question

Recommended Posts

resle    129
Hi, I've correctly implemented a frustum class, so at least the question is not about "how to build a frustum" as usual ;) When I create a frustum plane, I end it with a D3DXPlaneNormalize call. I don't know how to express myself exactly but.. isn't the "translation" component of the View matrix lost in this process? I am asking this because then I check some vertices against the frustum, and said vertices' coordinates are relative to the whole "world". So for example: - I've got this far far vertex at Vec3(3000,2500,7000). - I translate the view matrix to (3000,2500,6950) - The vertex is now viewable at a certain distance in the middle of the screen - I build the frustum - Check the frustum against Vec3(3000,2500,7000) : fail Should I somehow... uhm... "normalize" the vertex as well perhaps?

Share this post


Link to post
Share on other sites
resle    129
Frustum building:


// AS SEEN A BILLION TIMES ON A MILLION TUTORIALS...


function tfrustum.Build(mat_view, mat_proj:d3dxmatrix;
begin
D3DXMatrixInverse(mat_comb, nil, mat_view);
D3DXMatrixMultiply(mat_comb, matrix_proj, mat_comb);

// Left clipping plane
planes[0].a := matComb._14 + matComb._11;
planes[0].b := matComb._24 + matComb._21;
planes[0].c := matComb._34 + matComb._31;
planes[0].d := matComb._44 + matComb._41;
D3DXPlaneNormalize(planes[0],planes[0]);

// Right clipping plane
planes[1].a := matComb._14 - matComb._11;
planes[1].b := matComb._24 - matComb._21;
planes[1].c := matComb._34 - matComb._31;
planes[1].d := matComb._44 - matComb._41;
D3DXPlaneNormalize(planes[1],planes[1]);

// Top clipping plane
planes[2].a := matComb._14 - matComb._12;
planes[2].b := matComb._24 - matComb._22;
planes[2].c := matComb._34 - matComb._32;
planes[2].d := matComb._44 - matComb._42;
D3DXPlaneNormalize(planes[2],planes[2]);

// Bottom clipping plane
planes[3].a := matComb._14 + matComb._12;
planes[3].b := matComb._24 + matComb._22;
planes[3].c := matComb._34 + matComb._32;
planes[3].d := matComb._44 + matComb._42;
D3DXPlaneNormalize(planes[3],planes[3]);

// Near clipping plane
planes[4].a := matComb._13;
planes[4].b := matComb._23;
planes[4].c := matComb._33;
planes[4].d := matComb._43;
D3DXPlaneNormalize(planes[4],planes[4]);

// Far clipping plane
planes[5].a := matComb._14 - matComb._13;
planes[5].b := matComb._24 - matComb._23;
planes[5].c := matComb._34 - matComb._33;
planes[5].d := matComb._44 - matComb._43;
D3DXPlaneNormalize(planes[5],planes[5]);



Frustum checking (sphere):



function tfrustum.RadiusInside(pos:d3dxvector; radius:float)
begin
result:=(D3DXPlaneDotCoord(planes[4], pos)>-radius)
and
(D3DXPlaneDotCoord(planes[3], pos)>-radius)
and
(D3DXPlaneDotCoord(planes[2], pos)>-radius)
and
(D3DXPlaneDotCoord(planes[1], pos)>-radius)
and
(D3DXPlaneDotCoord(planes[0], pos)>-radius)
and
(D3DXPlaneDotCoord(planes[5], pos)>-radius)
;
end;





Practical example:



// SETTING UP THE VIEW MATRIX TO POSITION 1000,0,1000, ROTATION 0,0,0
D3DXMatrixTranslation(matrix_pos,1000,0,1000);
D3DXQuaternionRotationYawPitchRoll(quaternion_rot,0,0,0);
D3Dxmatrixrotationquaternion(matrix_rot,quaternion_rot);
D3DXMatrixMultiply(matrix_view,matrix_rot,matrix_pos);


// BUILDING THE FRUSTUM (matrix_proj never changes)
frustum.Build(matrix_view, matrix_proj);

// CHECKING
if frustum.RadiusInside(d3dxvec3(1010,0,1010), 100) then
MessageBox('Pleasure') else MessageBox('Migraine');



Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this