# Thread: Backface Culling in Lesson10 NeheGL Tutorials

1. ## Backface Culling in Lesson10 NeheGL Tutorials

I have tried to perform backface culling in the code of lesson10 nehe's tutorials, and i succeeded.

1. I suppose that the camera position is 0,0,0 and it's direction is 0,0,-1 initially.

2. I rotate the camera direction in the same direction as the rotation of the scene, but translate the camera position in opposite direction.

3. I then apply the plane eqn. taking the camera as a plane and check all vertices of all polys again it.

4. If all vertices of a polygon lie to the back of the camera, I mark it as not to be displayed.

5. It works!

6. Why ?

(note : nothing else works - I've tried everything else)

plz. help

3. Not sure what you are asking here. Backface culling works because if a polygon is facing in a positive z direction, it is facing away from the camera/viewer. If it is facing in a negative direction then it is facing the camera/viewer.

By taking the cross-product of two adjacent edges of the polygon you can determine which way the polygon is facing.

However, there is a catch. In order for backface culling to work correctly you must know what type of coordinate system you are using.

This simple, and not always accurate, backface cull will only work when all polygons are designed so that when they are viewed from their visible sides, the vertexes proceed around the polygon in a counterclockwise direction.

z=(x1-x0)*(y2-y0)-(y1-y0)*(x2-x0) where

x0,y0,z0 = first vertex
x1,y1,z1 = second vertex
x2,y2,z2= third vertex

This is a simpler version of backface culling. It will only work when objects are close to the center of your display.

For a better backface cull:
(used float, but recommend fixed point)
float c=
(x3*((z1*y2)-(y1*z2)))+
(y3*((x1*z2)-(z1*x2)))+
(z3*((y1*x2)-(x1*y2)));