THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 29/04/2011 at 19:33, xxxxxxxx wrote:
Cinema 4D Version: 12
Platform: Mac OSX ;
Language(s) : C++ ;
BackfaceCulling() is not accurately telling me whether a non-planar poly is displayed. It works fine for planar polys.
The normal passed to BackfaceCulling() is calculated using CalcFaceNormal(). Its orientation is the same as the normal displayed in the editor for a selected poly.
Below is a non-planar poly at its Backface Culling visibility threshold for the scene camera (within 0.001°). The normal for switching backfacing visibility should be vertical in this view.
How is this normal internally calculated by C4D?
On 02/05/2011 at 06:57, xxxxxxxx wrote:
I would triangulate the mesh for exact results.
On 04/05/2011 at 07:11, xxxxxxxx wrote:
Thanks for the tip, I think this has put me on the right track.
I've triangulated several quads and have found that a correctly oriented normal is derived from either one of the tris or the average of the normals of both tris.
I'll post results as soon as I've had time to test further.
On 08/05/2011 at 02:07, xxxxxxxx wrote:
Okay, I've worked it out.
Instead of triangulating a quad, I'm creating two matrices. The first is derived from poly.a, poly.c and poly.d. and the second from poly.a, poly.b and poly.c. The 'normals' are the Z axes of the matrices.
Two normals determine whether a non-planar poly is backfacing: the normal from the first matrix, and the average of this and the other normal. When both are pointing away from the camera, the poly is hidden. If either is pointing towards the camera, the poly is displayed.
BackfaceCulling() will determine whether a normal is pointing towards the camera. A normal's threshold angle in perspective camera space varies with poly position. In this case, the 'face center' position passed to the function must be correct.
The position passed with the first normal is averaged from its 3 matrix points. The position passed with the second normal is averaged from poly.a and poly.c.
All values are calculated in global space before being converted to camera space.