Game Development Reference
In-Depth Information
Vector Subtraction: The − Operator
This subtraction operator subtracts vector v from vector u according to the formula:
u v = (u x − v x ) i + (u y − v y ) j + (u z − v z ) k
Here's the code:
inline Vector operator-(Vector u, Vector v)
{
return Vector(u.x - v.x, u.y - v.y, u.z - v.z);
}
Vector Cross Product: The ^ Operator
This cross-product operator takes the vector cross product between vectors u and v ( u
× v ) and returns a vector perpendicular to both u and v according to the formula:
u × v = (u y * v z − u z * v y ) i + (−u x * v z + u z * v x ) j + (u x * v y
u y * v x ) k
The resulting vector is perpendicular to the plane that contains vectors u and v . The
direction in which this resulting vector points can be determined by the right hand
rule . If you place the two vectors u and v tail to tail, as shown in Figure A-7 , and curl
your fingers (of your right hand) in the direction from u to v , then your thumb will
point in the direction of the resulting vector.
Figure A-7. Vector cross product
In this case, the resulting vector points out of the page along the z-axis since the vectors
u and v lie in the plane formed by the x- and y-axes.
 
Search Nedrilad ::




Custom Search