Culling Math

I need to take some math classes I think. In the meantime… I have a ‘how do I…’ question.

I have a player position (P), and a player direction vector (D).

I want to make 4 planes, that are view frustum planes (excluding near and far planes). Left (L), Right (R), Top (T), and Bottom (B).

Now, all I have to do, is set the normal of the clipping planes to (D). Then, I rotate the plane how I want it. My problem is, the player is not at coordinate 0, 0, 0. So, I have to set the ‘D’ (distance from origin) attribute of the planes. But, how do I figure this?

       y
       |
P      |
|      |
       |
       |

x----------|-----------
|
|
|
|
|

So in the crappy diagram above, the player is P and the line from P points in the direction he is facing. How do I get planes set up so it’s like an upside down ‘V’ with the planes meeting at the player’s position?

Keith Jackson

Hi.
Here’s how I do it:
As input it takes player’s origin and his (her ) view direction, so this should be what you need.

void Frustum_c::Build(const Vec3_c &Origin, const Vec3_c &View)
{
Matrix_c M1, M2;

this->Origin = Origin;

glGetFloatv(GL_PROJECTION_MATRIX, M1);
glGetFloatv(GL_MODELVIEW_MATRIX, M2);

M1.Mult(M2);

// Near Plane
Planes[0].Normal = View;
Planes[0].Distance = this->Origin.Dot( View );

// Left Plane
Planes[1].Normal[0] = M1[3] + M1[0];
Planes[1].Normal[1] = M1[7] + M1[4];
Planes[1].Normal[2] = M1[11] + M1[8];
Planes[1].Distance = -M1[15] - M1[12];

// Bottom Plane
Planes[2].Normal[0] = M1[3] + M1[1];
Planes[2].Normal[1] = M1[7] + M1[5];
Planes[2].Normal[2] = M1[11] + M1[9];
Planes[2].Distance = -M1[15] - M1[13];

// Top Plane
Planes[3].Normal[0] = M1[3] - M1[1];
Planes[3].Normal[1] = M1[7] - M1[5];
Planes[3].Normal[2] = M1[11] - M1[9];
Planes[3].Distance = -M1[15] + M1[13];

// Right Plane
Planes[4].Normal[0] = M1[3] - M1[0];
Planes[4].Normal[1] = M1[7] - M1[4];
Planes[4].Normal[2] = M1[11] - M1[8];
Planes[4].Distance = M1[12] - M1[15];

// Normalize them
for (int i = 0; i < 5; i++)
{
Planes[i].Normalize();
}
}

Hope it helps.

Ah, I need to add something - it assumes you have all of your translations set through OpenGL, so you can read in matrices.