Advertisement Jump to content
Sign in to follow this  

frrustum clipping?

This topic is 4964 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm not sure on how to do this, but I need to clip objects to the view frustum. I have object that move around in the scene but I need to keep them in view. For example, I have a sphere that bounces around and I can't let it for out of the view. So I *think* that I need to check for collision on the frustum planes so see if the object is trying to leave the view. How is this done?

Share this post

Link to post
Share on other sites
as you said, simply test the sphere position against the frustum planes, and do a different action for every plane (for example, if the sphere hurts the left plane, change it's direction)

Share this post

Link to post
Share on other sites
There's a good beginning article about it here:

Share this post

Link to post
Share on other sites
search and look up some open source engines, nearly every engine has a frustum class, even simplest ones..

Share this post

Link to post
Share on other sites
Okay, my next qustion is, is this the best solution in my case? I have little enemy objects running around on the screen. Also, the player is on the screen so I have to make sure they don't fly off.

For example, I have an enemy ship that flys back and forh. I need to make sure the when it hits a side, that is when it goes a different direction.

This is sort of hard for me becaue I don't know how to handle this. How do you scale a world to fit in a view frustum? This is pretty muc hthe same thing as clipping sprites in 2D graphics. Yet, its 3D and I'm dealing with 3D objects (meshes) not sprites.

Share this post

Link to post
Share on other sites
Sorry, but here is the codee I have now:

// Global frustum constants
#define D3DFRUSTUM_FAR 1
#define D3DFRUSTUM_TOP 4

// Build view frustum's clipping planes
D3DXMatrixMultiply( &xMult, &xView, &xProj ) ;

g_vFrustum[ 0 ].a = xMult._14 + xMult._13 ; // Near
g_vFrustum[ 0 ].b = xMult._24 + xMult._23 ;
g_vFrustum[ 0 ].c = xMult._34 + xMult._33 ;
g_vFrustum[ 0 ].d = xMult._44 + xMult._43 ;
D3DXPlaneNormalize( &g_vFrustum[ 0 ], &g_vFrustum[ 0 ] ) ;

g_vFrustum[ 1 ].a = xMult._14 - xMult._13 ; // Far
g_vFrustum[ 1 ].b = xMult._24 - xMult._23 ;
g_vFrustum[ 1 ].c = xMult._34 - xMult._33 ;
g_vFrustum[ 1 ].d = xMult._44 - xMult._43 ;
D3DXPlaneNormalize( &g_vFrustum[ 1 ], &g_vFrustum[ 1 ] ) ;

g_vFrustum[ 2 ].a = xMult._14 + xMult._11 ; // Left
g_vFrustum[ 2 ].b = xMult._24 + xMult._21 ;
g_vFrustum[ 2 ].c = xMult._34 + xMult._31 ;
g_vFrustum[ 2 ].d = xMult._44 + xMult._41 ;
D3DXPlaneNormalize( &g_vFrustum[ 2 ], &g_vFrustum[ 2 ] ) ;

g_vFrustum[ 3 ].a = xMult._14 - xMult._11 ; // Right
g_vFrustum[ 3 ].b = xMult._24 - xMult._21 ;
g_vFrustum[ 3 ].c = xMult._34 - xMult._31 ;
g_vFrustum[ 3 ].d = xMult._44 - xMult._41 ;
D3DXPlaneNormalize( &g_vFrustum[ 3 ], &g_vFrustum[ 3 ] ) ;

g_vFrustum[ 4 ].a = xMult._14 + xMult._12 ; // Top
g_vFrustum[ 4 ].b = xMult._24 + xMult._22 ;
g_vFrustum[ 4 ].c = xMult._34 + xMult._32 ;
g_vFrustum[ 4 ].d = xMult._44 + xMult._42 ;
D3DXPlaneNormalize( &g_vFrustum[ 4 ], &g_vFrustum[ 4 ] ) ;

g_vFrustum[ 5 ].a = xMult._14 - xMult._12 ; // Bottom
g_vFrustum[ 5 ].b = xMult._24 - xMult._22 ;
g_vFrustum[ 5 ].c = xMult._34 - xMult._32 ;
g_vFrustum[ 5 ].d = xMult._44 - xMult._42 ;
D3DXPlaneNormalize( &g_vFrustum[ 5 ], &g_vFrustum[ 5 ] ) ;

// Return the distance(clip) of point to frustum plane
FLOAT __stdcall UTClipFrustum( UINT uClippingPlane, D3DXVECTOR3 vPos )
return ( D3DXPlaneDotCoord( &g_vFrustum[ uClippingPlane ], &vPos ) ) ;

So the successfully clips a point. Or in better terms returns the distancec of a point to the chosen plane. I would guess, that I just make sure objects always stay a certain positive distance from each plane. The Near and far planes are not really needed because hte Y axis is not used in my program. The top, bottom, left and right planes are of intrest.

This just seams a little odd to me right now. The planes are tilted, correct? Forming a pyramid. I actually wanted them more straight like a cube.

Share this post

Link to post
Share on other sites
Well, the sides of a frustum for a perspective projection matrix will always have "tilted" sides, due to perspective foreshortening (far objects being smaller than near objects). If you want straight frustum planes, you'll have to create an orthographic projection.

PM me if you want to discuss this a bit more. I've just done a lot of work with frustums and frustum culling just lately...

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!