Creating a Bounding Volume for Camera Frustums

So in my application I want to create a Bounding volume from my Camera’s Frustum to check collision with. I am not just looking to see if something is within view, My purpose is to make the Frustum edges to push objects around so that they are always in the field of view.
I think I have tried a few methods to do this,but my far planes’ x and y values go way beyond the edge of the view.
I will provide code


// Current Values of System
float fFOV_Y = 35.0;
float fNearPlane = 1.0;
float fFarPlane = 100.0;
Vector3 CamPos (0,0,-10);
Vector3 LookAt(0,0,1);
Vector3 Up(0,1,0);
Vector3 Right(0,1,0);

float fWidth = 320;     // Given by call to current display
float fHeight = 480;   // Given by call to current display
float fAspect = fWidth/fHeight;
glViewPort(0,0,Width, Height);
Matrix4x4 m_ViewMatrix = Matrix4x4::CreateLookAt(CamPos, LookAt, Up);
Matrix4x4 m_Projection = Matrix4x4::Frustum(FOV_Y, 320/480, NearPlane, FarPlane);
 /* Current Values
	m_ViewMatrix = { 	1,0, 0,0,
					0,1, 0,0,
					0,0, 1,0,
					0,0,-10,1};
	m_Projection = { 	4.75739193, 0,0,0,
					0,3.17159462,0,0,
					0,0,-1.02020204,-1,
					0,0,-2.02020192,1};
// If you need to know other values I can tell you
 */
	float fHeight = tan(_FOV_Y /2.0));  // -4.4459815
	float fWidth = fHeight * fAspect;   //  -2.96398783
	Vector3<float> lRight = Right;
	Vector3<float> lTop = Up;
	Vector3<float> lCenter = CamPos;
	Vector3<float> lTemp = LookAt;
	lRight.Scale(fWidth * FarPlane);  // (-296.398773,0,0)
	lTop.Scale(fHeight * FarPlane);  // (0,-444.598145,0)
	lTemp.Scale(-FarPlane);           // (0,0,-100)
	lCenter += lTemp;                    // (0,0,-110)

	Vector3<float> FTL = lCenter - lRight + lTop; // -296.398773, 444.598145, -110
	Vector3<float> FBR = lCenter + lRight - lTop; // 296.398773, -444.598145, -110
	Vector3<float> FTR = lCenter + lRight + lTop;//  296.398773   , 444.598145 , -110
	Vector3<float> FBL = lCenter - lRight - lTop;  //  -296.398773, -444.598145, -110
//End of function
// Below in my draw function I draw a Sphere that is translated
Sphere.Translate(37.5*fAspect, 37.5, -110);  // This is not the perfect corner position just 
									// something I kept working around to find a
									// close approximation of the corner (Radius of ~1.0)
// I also draw a line from FTL - FTR and a line from FBR - FBL to see where the points reach too... I only see ~1/4 of the sphere as the rest is off screen.
	

Is there something that seems out of place. Or maybe a one of my functions is not correct or I am just not doing this write.
I plan doing Triangle To Triangle collision with the frustum Walls.

Look at frustum diagrams in the Projection matrix section here:

Should have what you need. If you aren’t absolutely sure what l,r,b,t,n,f are in your case (symmetric perspective), see the glFrustum arguments in this gluPerspective work-alike here:

Quickly scanning your code, I don’t think your computation of lRight and lTop are right. For one thing they should have anything to do with the resolution.

Using your Frustum definition, write down the coordinates of the corners of the near clip plane, and I think you’ll then quickly see your errors in coming up with the coordinates of the far clip plane.

Which space are you trying to compute the frustum corners in? Eye space?

Its Eye Space. I am working on trying to make an object bounce around inside the First Person Perspective. To test if they object can still be seen at the corners I am putting a sphere there. I should only see ~1/4 of sphere as the rest of it would fall outside the Frustum

  • Thanks for the links I got it working. Yes it was something very stupid on my part.
    Corrections below

//M_PI is #define for (double)Pi 
	float fHeight = tan(FOV_Y * (M_PI * 180) * 0.5);  	// Should have named this fTop
	float fWidth = fHeight * AspectRatio;  			// Should have named this fRight
	float fPlaneRatio = fFarPlane / fNearPlane;
	Vector3<float> lRight = Right * fWidth;
	Vector3<float> lTop = Up * fTop;
	Vector3<float> lCenter = LookAt * -fNearPlane;
	Vector3<float> lFarCenter = LookAt  * -fFarPlane;
	Vector3<float> lFarRight = Right * fPlaneRatio;
	Vector3<float> lFarTop = Top * fPlaneRatio;
	
	Vector3<float> nTL = lCenter - lRight + lTop;
	Vector3<float> nBR = lCenter + lRight - lTop;
	Vector3<float> nTR = lCenter + lRight + lTop;
	Vector3<float> nBL = lCenter - lRight - lTop;
	Vector3<float> fTL = (lFarCenter) - (lFarRight) + (lFarTop);
	Vector3<float> fBR = (lFarCenter) + (lFarRight) - (lFarTop);
	Vector3<float> fTR = (lFarCenter) + (lFarRight) + (lFarTop);
	Vector3<float> fBL = (lFarCenter) - (lFarRight) - (lFarTop);


I use this code for a symmetrical frustum:

ecs_mm_frustum_aabb.a(0) = -FN_ratio * GetR(frustum);
ecs_mm_frustum_aabb.a(1) = aspect_ratio * ecs_mm_frustum_aabb.a(0);
ecs_mm_frustum_aabb.a(2) = -GetF(frustum);

ecs_mm_frustum_aabb.b =
-ecs_mm_frustum_aabb.a(0), -ecs_mm_frustum_aabb.a(1), -GetN(frustum);