View Full Version : compare 2 normals
01-18-2009, 04:22 PM
I was wondering how to compare 2 normals.
An example: 3 objects in the scene, a teapot, box and light.
and now i would like to align the box on the teapot faces only if their faces have the same normal as the light.
01-18-2009, 05:27 PM
A light doesn't have a 'normal', if it is directional type of light (spot, direction, etc.) it will have a direction. Both of these are vectors, and are thus comparable. However, you need to determine whether you want to test against the light's direction, or against the vector from face/vertex to light, I cannot tell from your question (the results will be quite different).
You can use a dot product to compare two normalized vectors. A dot product of 1 means they are facing each other perfectly, 0 means they are perpendicular, -1 means they are parallel (ie, the normal is facing directly away from the light).
So for each vert, you can run:
nDotL = dot (getNormal <mesh> <vert_index_integer>) theLight.dir
--nDotL = dot (getNormal <mesh> <vert_index_integer>) ((normalize (getVert <mesh> <vert_index_integer>)) - normalize (theLight.pos)) --would use the vector from light to vert pos instead
if nDotL > 0 then ()
else if nDotL < 0 then ()
You'd need to use faces instead of verts though.
01-20-2009, 02:07 PM
thx for your answer :D
01-20-2009, 02:08 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2015, Jelsoft Enterprises Ltd.