Return *this after normalizing
This commit is contained in:
parent
e76bf0f444
commit
fcde85c642
2 changed files with 4 additions and 8 deletions
|
@ -143,19 +143,15 @@ Vector3::dot(Vector3 v)
|
||||||
*
|
*
|
||||||
* Normalize this vector in place. That is, make this vector's magnitude (length) 1.0.
|
* Normalize this vector in place. That is, make this vector's magnitude (length) 1.0.
|
||||||
*/
|
*/
|
||||||
void
|
Vector3 &
|
||||||
Vector3::normalize()
|
Vector3::normalize()
|
||||||
{
|
{
|
||||||
float len2 = length2();
|
|
||||||
if (len2 <= 0.0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Multiplying by the inverse of the length is more efficient than dividing by the length.
|
// Multiplying by the inverse of the length is more efficient than dividing by the length.
|
||||||
float inverse_length = 1.0 / sqrtf(len2);
|
float inverse_length = 1.0 / sqrtf(length2());
|
||||||
x *= inverse_length;
|
x *= inverse_length;
|
||||||
y *= inverse_length;
|
y *= inverse_length;
|
||||||
z *= inverse_length;
|
z *= inverse_length;
|
||||||
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ struct Vector3
|
||||||
float length() const;
|
float length() const;
|
||||||
float dot(Vector3 v) const;
|
float dot(Vector3 v) const;
|
||||||
|
|
||||||
void normalize();
|
Vector3 &normalize();
|
||||||
|
|
||||||
static const Vector3 Zero;
|
static const Vector3 Zero;
|
||||||
float x, y, z;
|
float x, y, z;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue