Facing camera?

Blitz3D Forums/Blitz3D Programming/Facing camera?

Dabbede(Posted 2003) [#1]
Hi! I need to know if a triangle in a mesh is facing camera or not... I have the normals of the face but I don't know how to use them to solve the problems! :)
Any help?


Bot Builder(Posted 2003) [#2]
Get the normals of the camera orientation, and then do a dotproduct between the normals. dot_product= n1x*n2x+n1y*n2y+n1z*n2z . this should output a number from -1 to 1. If a face is facing the camera, the dot pruduct is either above zero or less than 0 ---I forgot which,but I know it's one of them. I'm sure someone else knows.

Oh yeah, and if you are thinking of trying Backface culling, don't put out the effort. blitz already does it for you.


jhocking(Posted 2003) [#3]
Thanks for the quick primer on a specific 3D math task. If and when I get around to experimenting with drawing black outlines for cel shading that information will help. The way to determine an outline edge (ie. where black outlines have to be drawn) you look for adjacent polygons where one is facing the camera and one is facing away.


Bot Builder(Posted 2003) [#4]
did a tieny bit of research and when the dotproduct<=0, the triangle is facing the camera.


Dabbede(Posted 2003) [#5]
Thanks a lot bot builder! This will help me a lot...
jhocking, I was thinking the same!


Mr Snidesmin(Posted 2005) [#6]
anyone got any code for this? I can't be bothered to think about it right now and just want to have something that works. I'm sure you've all been there! :O)