Hi guys,
I'm trying to construct a view frustum for my camera. The frustum gets created and looks correct, however the normals of the frustum face the wrong way (outside, not inside). This is the code i'm using to create the frustum:
Frustum Camera::GetFrustum() {
Frustum result;
mat4 vp = GetViewMatrix() * GetProjectionMatrix();
vec3 col1(vp._11, vp._21, vp._31);//, vp._41
vec3 col2(vp._12, vp._22, vp._32);//, vp._42
vec3 col3(vp._13, vp._23, vp._33);//, vp._43
vec3 col4(vp._14, vp._24, vp._34);//, vp._44
// Find plane magnitudes
result.left.normal = col4 + col1;
result.right.normal = col4 - col1;
result.bottom.normal= col4 + col2;
result.top.normal = col4 - col2;
result.near.normal = col3;
result.far.normal = col4 - col3;
// Find plane distances
result.left.distance = vp._44 + vp._41;
result.right.distance = vp._44 - vp._41;
result.bottom.distance = vp._44 + vp._42;
result.top.distance = vp._44 - vp._42;
result.near.distance = vp._43;
result.far.distance = vp._44 - vp._43;
// Normalize all 6 planes
for (int i = 0; i < 6; ++i) {
float mag = 1.0f / Magnitude(result.planes[i].normal);
Normalize(result.planes[i].normal);
result.planes[i].distance *= mag;
// If i uncomment these lines, the normals face the right way
//result.planes[i].distance *= -1.0f;
//result.planes[i].normal *= -1.0f;
}
return result;
}
I'm using row major, left handed matrices with pre-multiplication. I guess my question is, why would the normals be facing the wrong way? Every tutorial / book i've found on DirectX says this should be correct. My only guess would be that maybe i'm feeding in the wrong view or projection matrices? This is how i create my projection matrix and my view matrix