Game Development Reference
In-Depth Information
y *= s;
z *= s;
return *this;
}
Scalar Division: The /= Operator
This scalar division operator is similar to the scalar multiplication operator except each
vector component is divided by the passed scalar quantity:
inline Vector& Vector::operator/=(float s)
{
x /= s;
y /= s;
z /= s;
return *this;
}
Conjugate: The − Operator
The conjugate operator simply takes the negative of each vector component and can be
used when you are subtracting one vector from another or for reversing the direction
of the vector. Applying the conjugate operator is the same as reversing a vector, as
discussed earlier:
inline Vector Vector::operator-(void)
{
return Vector(-x, -y, -z);
}
Vector Functions and Operators
The following functions and overloaded operators are useful when you are performing
operations with two vectors, or with a vector and a scalar, where the vector is based on
the Vector class.
Vector Addition: The + Operator
This addition operator adds vector v to 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);
}
Search Nedrilad ::




Custom Search