# Frustum Culling

Hi, I’m trying to write an algorithm for frustum culling by following the tutorial at http://www.lighthouse3d.com/tutorials/view-frustum-culling/ and I can’t figure out what I’m doing wrong.

I’m 99% sure the problem is somewhere in my method to build the frustum.

top,bottom,left,right,front and back are Planes, defined by 4 points and a vector for the normal.
ftl, ftl, nbl, nbr…etc are vectors for the 8 points of the frustum. f = far, t = top, n = near, b = bottom, l = left, r = right

``````
void getFrustum(){
float tan = (float)Math.tan(angle);

float nearHeight = (float)(2 * tan * 0.00005);
float nearWidth = nearHeight * aspectRatio;

float farHeight = (float)(2 * tan * 100.0);
float farWidth = farHeight * aspectRatio;

farVector.x = player.cam.getX() + (camVector.x * 100.0f);
farVector.y = player.cam.getY() + (camVector.y * 100.0f);
farVector.z = player.cam.getZ() + (camVector.z * 100.0f);

nearVector.x = player.cam.getX() + (camVector.x * 0.00005f);
nearVector.y = player.cam.getY() + (camVector.y * 0.00005f);
nearVector.z = player.cam.getZ() + (camVector.z * 0.00005f);

upVector.set(a1,a2,a3);
rightVector = camVector.crossProduct(upVector);
rightVector.x = -rightVector.x;

ftl.set(farVector);
ftr.set(farVector);
fbl.set(farVector);
fbr.set(farVector);

tempVec1.set(upVector);
tempVec2.set(rightVector);

tempVec1.times(farHeight / 2.0f);
tempVec2.times(farWidth / 2.0f);

ftl.sub(tempVec2);

fbl.sub(tempVec1);
fbl.sub(tempVec2);

fbr.sub(tempVec1);

tempVec1.set(upVector);
tempVec2.set(rightVector);

tempVec1.times(nearHeight / 2.0f);
tempVec2.times(nearWidth / 2.0f);

ntl.set(nearVector);
ntr.set(nearVector);
nbl.set(nearVector);
nbr.set(nearVector);

ntl.sub(tempVec2);

nbl.sub(tempVec1);
nbl.sub(tempVec2);

nbr.sub(tempVec1);

front.set(ntl, ntr, nbl, nbr, camVector);
back.set(ftl, ftr, fbl, fbr, camVector.negate());

tempVec3.set(ftr);
tempVec3.sub(ntr);
tempVec4.set(nbr);
tempVec4.sub(ntr);
tempVec3 = tempVec3.crossProduct(tempVec4);
Vector3f norm = new Vector3f(tempVec3);
norm.normalize();
right.set(ntr, ftr, nbr, fbr, norm);

tempVec3.set(ftl);
tempVec3.sub(ntl);
tempVec4.set(nbl);
tempVec4.sub(ntl);
tempVec3 = tempVec3.crossProduct(tempVec4);
norm = new Vector3f(tempVec3);
norm.normalize();
left.set(ntl, ftl, nbl, fbl, norm.negate());

tempVec3.set(fbr);
tempVec3.sub(nbr);
tempVec4.set(nbl);
tempVec4.sub(nbr);
tempVec3 = tempVec3.crossProduct(tempVec4);
norm = new Vector3f(tempVec3);
norm.normalize();
bottom.set(nbr, fbr, nbl, fbl, norm.negate());

tempVec3.set(ftr);
tempVec3.sub(ntr);
tempVec4.set(ntl);
tempVec4.sub(ntr);
tempVec3 = tempVec3.crossProduct(tempVec4);
norm = new Vector3f(tempVec3);
norm.normalize();
top.set(ntl, ftl, ntr, ftr, norm.negate());
}

``````

Any help would be greatly appreciated. Thanks.

What exactly is the problem you’re encountering?

BTW, if you’re already looking at the Lighthouse, check the radar approach which is also described there. Very simple and very fast.