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.