Voxelyze
Public Member Functions | Public Attributes | Friends
Vec3D< T > Class Template Reference

A generic 3D vector template. More...

#include <Vec3D.h>

List of all members.

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
Vec3Doperator= (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 Vec3Doperator+= (const Vec3D &s)
 overload add and set
const Vec3Doperator-= (const Vec3D &s)
 overload subract and set
const Vec3Doperator*= (const T f)
 overload multiply and set
const Vec3Doperator/= (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.
getX (void) const
 returns the x value
getY (void) const
 returns the y value
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
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.
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.
Length () const
 Returns the length (magnitude) of this vector. This vector is not modified.
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.
Min () const
 Returns the smallest of x, y, or z of this vector. This vector is not modified.
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.
Dist (const Vec3D &v) const
 Returns the euclidian distance between this vector and the specified vector "v". This vector is not modified.
Dist2 (const Vec3D &v) const
 Returns the euclidian distance squared between this vector and the specified vector "v". This vector is not modified.
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

x
 The current X value.
y
 The current Y value.
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.

Detailed Description

template<typename T = double>
class Vec3D< T >

A generic 3D vector template.

The template parameter is assumed to be either float or double depending on the desired numerical resolution.


Member Function Documentation

template<typename T = double>
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.

Parameters:
[in]targettarget vector.
[out]rotaxUnit vector of rotation axis.
template<typename T = double>
Vec3D Vec3D< T >::Cross ( const Vec3D< T > &  v) const [inline]

Returns the cross product of this vector crossed by the provided vector "v". This vector is not modified.

Parameters:
[in]vVector to cross by.
template<typename T = double>
T Vec3D< T >::Dist ( const Vec3D< T > &  v) const [inline]

Returns the euclidian distance between this vector and the specified vector "v". This vector is not modified.

Parameters:
[in]vVector to compare with.
template<typename T = double>
T Vec3D< T >::Dist2 ( const Vec3D< T > &  v) const [inline]

Returns the euclidian distance squared between this vector and the specified vector "v". This vector is not modified.

Parameters:
[in]vVector to compare with.
template<typename T = double>
T Vec3D< T >::Dot ( const Vec3D< T > &  v) const [inline]

Returns the dot product of this vector dotted with the provided vector "v". This vector is not modified.

Parameters:
[in]vVector to dot with.
template<typename T = double>
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.

Parameters:
[in]svector to compare this position to.
[in]threshEuclidian distance to determine if the other vector is within.
template<typename T = double>
Vec3D Vec3D< T >::Max ( const Vec3D< T > &  s) const [inline]

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.

Parameters:
[in]sSecond vector to consider.
template<typename T = double>
Vec3D Vec3D< T >::Min ( const Vec3D< T > &  s) const [inline]

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.

Parameters:
[in]sSecond vector to consider.
template<typename T = double>
Vec3D Vec3D< T >::Rot ( const Vec3D< T >  u,
const T  a 
) [inline]

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.

Parameters:
[in]uaxis to rotate this vector about. Must be normalized.
[in]aThe amount to rotate in radians.
template<typename T = double>
void Vec3D< T >::RotX ( const T  a) [inline]

Rotates this vector about the X axis "a" radians. Note: function changes this vector.

Parameters:
[in]aRadians to rotate by.
template<typename T = double>
void Vec3D< T >::RotY ( const T  a) [inline]

Rotates this vector about the Y axis "a" radians. Note: function changes this vector.

Parameters:
[in]aRadians to rotate by.
template<typename T = double>
void Vec3D< T >::RotZ ( const T  a) [inline]

Rotates this vector about the Z axis "a" radians. Note: function changes this vector.

Parameters:
[in]aRadians to rotate by.
template<typename T = double>
Vec3D Vec3D< T >::Scale ( const Vec3D< T > &  v) const [inline]

Returns a vector where each value of this vector is scaled by its respective value in vector "v". This vector is not modified.

Parameters:
[in]vVector with scaling values.
template<typename T = double>
Vec3D Vec3D< T >::ScaleInv ( const Vec3D< T > &  v) const [inline]

Returns a vector where each value of this vector is inversely scaled by its respective value in vector "v". This vector is not modified.

Parameters:
[in]vVector with scaling values.

The documentation for this class was generated from the following file:
 All Classes Functions Variables Enumerations Enumerator Friends