Game Development Reference
In-Depth Information
double ny = Z * v.X - X * v.Z;
double nz = X * v.Y - Y * v.X;
return new Vector(nx, ny, nz);
}
The cross-product is very useful for working out the normal of a surface. For
instance, you may have a train that you want to move forward in the 3D world.
The train could be at any angle, so it's hard to know what forward means. First,
you really need a normal vector that faces the same way as the train. If you found
a polygon on the train facing the way you want, the cross-product of two sides of
this polygon will give you a vector that is facing outward from it along the train,
as shown in Figure 8.17. This vector can be normalized so it is just a direction.
This direction multiplied by some scalar can be added to the train's position and
it will move forward that scalar amount.
Figure 8.16
The cross-product operation.
Search WWH ::




Custom Search