# Frustum has wrong normals?

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

## Recommended Posts

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

##### Share on other sites

I think i'm building my projection matrix wrong :(

With the above code, my scene looks like this:

If i negate element _43 like so

proj._43 *= -1.0f;


My scene looks as expected

I did that just for visualization porpuses, where i changed the code inside the GetFrustum function. If i change the function that creates my projection matrix, then i can't see anything on screen anymore  :(

It might be worth mentioning that while i use a direct-x like math library i'm rendering with OpenGL.

I don't consider this issue solved, i know how to fix it, but i don't know why its broken...

Update: i've confirmed that my Projection function returns the same matrix as: D3DXMatrixPerspectiveFovLH

Edited by mathematical

##### Share on other sites

SOLVED!

The problem was in my visualization code! The frustum was not being drawn in the correct position!