Voxelyze
|
A generic 3D vector template. More...
#include <Vec3D.h>
Public Member Functions | |
Vec3D () | |
Constructor. Initialzes x, y, z to zero. | |
Vec3D (const T dx, const T dy, const T dz) | |
Constructor with specified individual values. | |
Vec3D (const Vec3D &s) | |
Copy constructor. | |
bool | IsValid () const |
Returns true if all values are valid numbers. | |
template<typename U > | |
Vec3D (const Vec3D< U > &s) | |
Copy constructor from another template type. | |
template<typename U > | |
operator Vec3D< U > () const | |
overload conversion operator for different template types | |
template<typename U > | |
Vec3D< T > | operator= (const Vec3D< U > &s) |
equals operator for different template types | |
template<typename U > | |
const Vec3D< T > | operator+ (const Vec3D< U > &s) |
addition operator for different template types | |
template<typename U > | |
const Vec3D< T > | operator- (const Vec3D< U > &s) |
subtraction operator for different template types | |
template<typename U > | |
const Vec3D< T > | operator* (const U &f) const |
multiplication operator for different template types | |
template<typename U > | |
const Vec3D< T > & | operator+= (const Vec3D< U > &s) |
add and set for different template types | |
template<typename U > | |
const Vec3D< T > & | operator-= (const Vec3D< U > &s) |
subract and set for different template types | |
Vec3D & | operator= (const Vec3D &s) |
overload equals. | |
const Vec3D | operator+ (const Vec3D &v) const |
overload addition. | |
const Vec3D | operator- (const Vec3D &v) const |
overload subtraction. | |
const Vec3D | operator- () const |
overload negation (unary). | |
const Vec3D | operator* (const T &f) const |
overload multiplication. | |
const Vec3D | operator/ (const T &f) const |
overload division. | |
bool | operator== (const Vec3D &v) |
overload is equal. | |
bool | operator!= (const Vec3D &v) |
overload is not equal. | |
const Vec3D & | operator+= (const Vec3D &s) |
overload add and set | |
const Vec3D & | operator-= (const Vec3D &s) |
overload subract and set | |
const Vec3D & | operator*= (const T f) |
overload multiply and set | |
const Vec3D & | operator/= (const T f) |
overload divide and set | |
const T & | operator[] (int index) const |
overload index operator. 0 ("vec3_X") is x, 1 ("vec3_Y") is y and 2 ("vec3_Z") is z. | |
T & | operator[] (int index) |
overload index operator. 0 ("vec3_X") is x, 1 ("vec3_Y") is y and 2 ("vec3_Z") is z. | |
T | getX (void) const |
returns the x value | |
T | getY (void) const |
returns the y value | |
T | getZ (void) const |
returns the z value | |
void | setX (const T XIn) |
sets the x value | |
void | setY (const T YIn) |
sets the y value | |
void | setZ (const T ZIn) |
sets the z value | |
T | Normalize () |
Normalizes this vector. Returns the previous magnitude of this vector before normalization. Note: function changes this vector. | |
void | NormalizeFast () |
Normalizes this vector slightly faster than Normalize() by not returning a value. Note: function changes this vector. | |
Vec3D | Rot (const Vec3D u, const T a) |
Rotates this vector about an axis definied by "u" an angle "a". (http://www.cprogramming.com/tutorial/3d/rotation.html) Note: function changes this vector. | |
void | RotZ (const T a) |
Rotates this vector about the Z axis "a" radians. Note: function changes this vector. | |
void | RotY (const T a) |
Rotates this vector about the Y axis "a" radians. Note: function changes this vector. | |
void | RotX (const T a) |
Rotates this vector about the X axis "a" radians. Note: function changes this vector. | |
Vec3D | Cross (const Vec3D &v) const |
Returns the cross product of this vector crossed by the provided vector "v". This vector is not modified. | |
T | Dot (const Vec3D &v) const |
Returns the dot product of this vector dotted with the provided vector "v". This vector is not modified. | |
Vec3D | Abs () const |
Returns the absolute value of this vector. This vector is not modified. | |
Vec3D | Normalized () const |
Returns a normalized version of this vector. Unlike Normalize() or NormalizeFast(), this vector is not modified. | |
bool | IsNear (const Vec3D &s, const T thresh) |
Returns true if this vector is within "thresh" distance of the specified vector "s". Neither vector is modified. | |
T | Length () const |
Returns the length (magnitude) of this vector. This vector is not modified. | |
T | Length2 () const |
Returns the length (magnitude) squared of this vector. This vector is not modified. | |
Vec3D | Min (const Vec3D &s) const |
Returns a vector populated by the minimum x, y, and z value of this vector and the specified vector "s". This vector is not modified. | |
Vec3D | Max (const Vec3D &s) const |
Returns a vector populated by the maximum x, y, and z value of this vector and the specified vector "s". This vector is not modified. | |
T | Min () const |
Returns the smallest of x, y, or z of this vector. This vector is not modified. | |
T | Max () const |
Returns the largest of x, y, or z of this vector. This vector is not modified. | |
Vec3D | Scale (const Vec3D &v) const |
Returns a vector where each value of this vector is scaled by its respective value in vector "v". This vector is not modified. | |
Vec3D | ScaleInv (const Vec3D &v) const |
Returns a vector where each value of this vector is inversely scaled by its respective value in vector "v". This vector is not modified. | |
T | Dist (const Vec3D &v) const |
Returns the euclidian distance between this vector and the specified vector "v". This vector is not modified. | |
T | Dist2 (const Vec3D &v) const |
Returns the euclidian distance squared between this vector and the specified vector "v". This vector is not modified. | |
T | AlignWith (const Vec3D target, Vec3D &rotax) const |
Returns a rotation amount in radians and a unit vector (returned via the rotax argument) that will align this vector with target vector "target'. This vector is not modified. | |
Vec3D | ArbitraryNormal () const |
Generates and returns an arbitrary vector that is normal to this one. This vector is not modified. | |
Public Attributes | |
T | x |
The current X value. | |
T | y |
The current Y value. | |
T | z |
The current Z value. | |
Friends | |
template<typename U > | |
const friend Vec3D< T > | operator* (const U f, const Vec3D< T > &v) |
multiplication operator for different template types with number first. Therefore must be a friend because scalar value comes first. | |
const friend Vec3D | operator* (const T f, const Vec3D &v) |
overload multiplication with number first. |
A generic 3D vector template.
The template parameter is assumed to be either float or double depending on the desired numerical resolution.
T Vec3D< T >::AlignWith | ( | const Vec3D< T > | target, |
Vec3D< T > & | rotax | ||
) | const [inline] |
Returns a rotation amount in radians and a unit vector (returned via the rotax argument) that will align this vector with target vector "target'. This vector is not modified.
[in] | target | target vector. |
[out] | rotax | Unit vector of rotation axis. |
Returns the cross product of this vector crossed by the provided vector "v". This vector is not modified.
[in] | v | Vector to cross by. |
Returns the euclidian distance between this vector and the specified vector "v". This vector is not modified.
[in] | v | Vector to compare with. |
Returns the euclidian distance squared between this vector and the specified vector "v". This vector is not modified.
[in] | v | Vector to compare with. |
Returns the dot product of this vector dotted with the provided vector "v". This vector is not modified.
[in] | v | Vector to dot with. |
bool Vec3D< T >::IsNear | ( | const Vec3D< T > & | s, |
const T | thresh | ||
) | [inline] |
Returns true if this vector is within "thresh" distance of the specified vector "s". Neither vector is modified.
[in] | s | vector to compare this position to. |
[in] | thresh | Euclidian distance to determine if the other vector is within. |
Returns a vector populated by the maximum x, y, and z value of this vector and the specified vector "s". This vector is not modified.
[in] | s | Second vector to consider. |
Returns a vector populated by the minimum x, y, and z value of this vector and the specified vector "s". This vector is not modified.
[in] | s | Second vector to consider. |
Rotates this vector about an axis definied by "u" an angle "a". (http://www.cprogramming.com/tutorial/3d/rotation.html) Note: function changes this vector.
[in] | u | axis to rotate this vector about. Must be normalized. |
[in] | a | The amount to rotate in radians. |
Rotates this vector about the X axis "a" radians. Note: function changes this vector.
[in] | a | Radians to rotate by. |
Rotates this vector about the Y axis "a" radians. Note: function changes this vector.
[in] | a | Radians to rotate by. |
Rotates this vector about the Z axis "a" radians. Note: function changes this vector.
[in] | a | Radians to rotate by. |
Returns a vector where each value of this vector is scaled by its respective value in vector "v". This vector is not modified.
[in] | v | Vector with scaling values. |
Returns a vector where each value of this vector is inversely scaled by its respective value in vector "v". This vector is not modified.
[in] | v | Vector with scaling values. |