DOT product... i keep forgetting it :(
Vector1 (x1, y1, z1) and Vector2 (x2, y2, z2).
DotProduct = (x1*x2 + y1*y2 + z1*z2)
The value is the cosine of the angle between the two input vectors, multiplied by the lengths of those vectors.
So, you can easily calculate the cosine of the angle by either, making sure that your two vectors are both of length 1, or dividing the dot product by the lengths.
Cos(theta) = DotProduct(v1,v2) / (length(v1) * length(v2))
Backface culling
When deciding if a polygon is facing the camera, you need only calculate the dot product of the normal vector of that polygon, with a vector from the camera to one of the polygon's vertices. If the dot product is less than zero, the polygon is facing the camera. If the value is greater than zero, it is facing away from the camera.
DotProduct = (x1*x2 + y1*y2 + z1*z2)
The value is the cosine of the angle between the two input vectors, multiplied by the lengths of those vectors.
So, you can easily calculate the cosine of the angle by either, making sure that your two vectors are both of length 1, or dividing the dot product by the lengths.
Cos(theta) = DotProduct(v1,v2) / (length(v1) * length(v2))
- Values range from 1 to -1.
- If the two input vectors are pointing in the same direction, then the return value will be 1.
- If the two input vectors are pointing in opposite directions, then the return value will be -1.
- If the two input vectors are at right angles, then the return value will be 0. So, in effect,
Backface culling
When deciding if a polygon is facing the camera, you need only calculate the dot product of the normal vector of that polygon, with a vector from the camera to one of the polygon's vertices. If the dot product is less than zero, the polygon is facing the camera. If the value is greater than zero, it is facing away from the camera.
0 Comments:
Post a Comment
<< Home