frrustum clipping?

Started by
6 comments, last by iNsAn1tY 18 years, 10 months ago
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?
Take back the internet with the most awsome browser around, FireFox
Advertisement
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)
yeah, but how do you find the frustum?
Take back the internet with the most awsome browser around, FireFox
There's a good beginning article about it here: http://www.flipcode.com/articles/article_frustumculling.shtml
search and look up some open source engines, nearly every engine has a frustum class, even simplest ones..
+-+-+-+-+-STR
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.
Take back the internet with the most awsome browser around, FireFox
Sorry, but here is the codee I have now:

// Global frustum constants//#define	D3DFRUSTUM_NEAR		0#define	D3DFRUSTUM_FAR		1#define	D3DFRUSTUM_LEFT		2#define	D3DFRUSTUM_RIGHT	3#define	D3DFRUSTUM_TOP		4#define D3DFRUSTUM_BOTTOM	5// Build view frustum's clipping planes//D3DXMatrixMultiply( &xMult, &xView, &xProj ) ;g_vFrustum[ 0 ].a = xMult._14 + xMult._13 ; // Nearg_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 ; // Farg_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 ; // Leftg_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 ; // Rightg_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 ; // Topg_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 ; // Bottomg_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.
Take back the internet with the most awsome browser around, FireFox
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...
My opinion is a recombination and regurgitation of the opinions of those around me. I bring nothing new to the table, and as such, can be safely ignored.[ Useful things - Firefox | GLee | Boost | DevIL ]

This topic is closed to new replies.

Advertisement