calculating the angle camera/normals


How could I calculate the angle between the camera view point and the normals of the polygons for hidden face removal purposes please?



The dot product of two vectors A and B is defined as the length of A times the length of B times the cosine of the angle between them.

Say your camera direction vector is A and the face normal is B. If all your normals are unit-length, and you can normalize your camera angle at the start of the frame, then you can ignore the lengths and the angle is just acos(A dot B).

BTW, for hidden face removal you’re almost certainly better off letting OpenGL do face culling for you.

I need to do some hidden face removal as I’d like to draw the edges shared by one front-facing face and one back-facing one…

When I move the object, how could I update either the normals or the camera viewpoint?.. I don’t get it…



I would also suggest to let OpenGL do the culling.

Nevertheless, like for the OpenGL lighting calculations, where the normals have to be transformed by the inverse transpose modelview matrix, you have to do the same but with the final projection matrix.

And no, I don’t have the code at hand. Perhaps you’ll have a peek into the MESA implementation for the calculations or build the inverse matrix parallel to the other transformations.
It’s rather easy to inverse rotate, translate, and scale. But I don’t remember if the projection was that simple(?)