Game Development Reference
In-Depth Information
F IGURE 2.4
The geometry of scalar-vector multiplication.
F IGURE 2.5
The geometry of vector addition.
In code it is very easy to add vectors together or subtract them. For two vectors a
and b , their sum is given by
⎦ +
⎦ =
a x
a y
a z
b x
b y
b z
a x +
b x
a
+
b
=
a y +
b y
a z +
b z
where a x , a y ,and a z are the x , y ,and z components of the vector a :wewillnormally
use this notation rather than x , y ,and z to avoid confusion when dealing with more
than one vector.
Vector addition is achieved by adding the components of the two vectors together.
This can be implemented for the + operator:
Excerpt from include/cyclone/core.h
class Vector3
{
// ... Other Vector3 code as before ...
/** Adds the given vector to this. */
void operator+=(const Vector3& v)
Search Nedrilad ::




Custom Search