Add Vector3::normalized()
Makes a copy of the vector, normalizes it, and returns it.
This commit is contained in:
parent
c80a6e9ac7
commit
d44fa4dd2a
2 changed files with 15 additions and 2 deletions
|
|
@ -220,8 +220,6 @@ Vector3::cross(const Vector3 &v)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Vector3::normalize --
|
* Vector3::normalize --
|
||||||
*
|
|
||||||
* Normalize this vector in place. That is, make this vector's magnitude (length) 1.0.
|
|
||||||
*/
|
*/
|
||||||
Vector3 &
|
Vector3 &
|
||||||
Vector3::normalize()
|
Vector3::normalize()
|
||||||
|
|
@ -231,6 +229,17 @@ Vector3::normalize()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Vector3::normalized --
|
||||||
|
*/
|
||||||
|
Vector3
|
||||||
|
Vector3::normalized()
|
||||||
|
const
|
||||||
|
{
|
||||||
|
return *this / length();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* operator* --
|
* operator* --
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -47,8 +47,12 @@ struct Vector3
|
||||||
Double dot(const Vector3 &v) const;
|
Double dot(const Vector3 &v) const;
|
||||||
Vector3 cross(const Vector3 &v) const;
|
Vector3 cross(const Vector3 &v) const;
|
||||||
|
|
||||||
|
/** Normalize and return a reference to this vector. */
|
||||||
Vector3 &normalize();
|
Vector3 &normalize();
|
||||||
|
|
||||||
|
/** Return a copy of this vector, normalized. Does not modify this vector. */
|
||||||
|
Vector3 normalized() const;
|
||||||
|
|
||||||
static const Vector3 Zero;
|
static const Vector3 Zero;
|
||||||
// Unit vectors in each of the three cartesian directions.
|
// Unit vectors in each of the three cartesian directions.
|
||||||
static const Vector3 X, Y, Z;
|
static const Vector3 X, Y, Z;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue