# 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 §, 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 ®, 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.Normal = View;
Planes.Distance = this->Origin.Dot( View );

// Left Plane
Planes.Normal = M1 + M1;
Planes.Normal = M1 + M1;
Planes.Normal = M1 + M1;
Planes.Distance = -M1 - M1;

// Bottom Plane
Planes.Normal = M1 + M1;
Planes.Normal = M1 + M1;
Planes.Normal = M1 + M1;
Planes.Distance = -M1 - M1;

// Top Plane
Planes.Normal = M1 - M1;
Planes.Normal = M1 - M1;
Planes.Normal = M1 - M1;
Planes.Distance = -M1 + M1;

// Right Plane
Planes.Normal = M1 - M1;
Planes.Normal = M1 - M1;
Planes.Normal = M1 - M1;
Planes.Distance = M1 - M1;

// 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.