Vector< N, T > Class Template Reference
A Vector is templated to store N elements of data of type T. If left off, T will default to a "real_t" data type, where a real_t is assumed to be either a float or a double. More...
#include <Vector.h>
Public Member Functions | |
Constructors | |
| Vector (const T *srcData) | |
| Expects N arguments of type T. | |
| Vector () | |
| Constructs a zero Vector. | |
| Vector (const Vector< N, T > &v) | |
| Copy Constructor. | |
Accessor Operators | |
| const T & | operator[] (const unsigned index) const |
| T & | operator[] (const unsigned index) |
| const T * | operator* () const |
| T * | operator* () |
Equality Operators | |
| bool | operator== (const Vector< N, T > &v) const |
| bool | operator!= (const Vector< N, T > &v) const |
Mutator Operators | |
| Vector< N, T > & | operator= (const Vector< N, T > &v) |
| Vector< N, T > & | operator+= (const Vector< N, T > &rhs) |
| Vector< N, T > & | operator-= (const Vector< N, T > &rhs) |
Scalar Mutator Operators | |
| Vector< N, T > & | operator*= (const T &scale) |
| Vector< N, T > & | operator/= (const T &scale) |
Arithmetic Operators | |
| Vector< N, T > | operator+ (const Vector< N, T > &rhs) const |
| Vector< N, T > | operator- (const Vector< N, T > &rhs) const |
| Vector< N, T > | operator* (const Vector< N, T > &rhs) const |
Scalar Arithmetic Operators | |
| Vector< N, T > | operator* (const T &scale) const |
| Vector< N, T > | operator/ (const T &scale) const |
More Complex Functionality | |
| bool | isUnit () const |
| bool | isZero () const |
| Vector< N, T > | getNormalized () const |
| Vector< N, T > | getReciprocal () const |
| T | normalize () |
| Normalizes this Vector and returns the old magnitude. | |
| T | getMagnitude () const |
| T | getMagnitude2 () const |
| T | getDistance (const Vector< N, T > &v) const |
| T | getDistance2 (const Vector< N, T > &v) const |
| T | getSum () const |
| T | getAverage () const |
| T | dot (const Vector< N, T > &rhs) const |
| unsigned | getMaxDimension () const |
| unsigned | getMinDimension () const |
| void | cleanup () |
| Cleans up vector (0's out entries that are less than epsilon). | |
Specialized Vector Functionality | |
| Vector (const T &v0, const T &v1=0, const T &v2=0) | |
| Convenience Constructor. | |
| Vector< N, T > | cross (const Vector< N, T > &rhs) const |
| Vector< N, T > | reflectVector (const Vector< N, T > &normal) const |
| Vector< N, T > | refractVector (const Vector< N, T > &normal, real_t in, real_t out=1.0f) const |
| void | getOrthonormalBasis (Vector< N, T > &U, Vector< N, T > &V) |
Static Public Member Functions | |
Static convenience constructors to generate common vectors | |
| static Vector< N, T > | zero () |
| Generates a vector full of zeroes. | |
| static Vector< N, T > | ones () |
| Generates a vector full of ones. | |
| static Vector< N, T > | fill (const T &val) |
| Generates a vector filled with the specified value. | |
| static Vector< N, T > | min (const Vector< N, T > &v1, const Vector< N, T > &v2) |
| static Vector< N, T > | max (const Vector< N, T > &v1, const Vector< N, T > &v2) |
| static Vector< N, T > | infinity () |
| Generates a vector filled with the maximum T (infinity). | |
| static Vector< N, T > | negativeInfinity () |
| Generates a vector filled with the minimum T (negative infinity). | |
| static Vector< 3, T > | fromSpherical (T theta, T phi) |
| theta is latitude angle; phi is longitude angle | |
| static Vector< 3, real_t > | cosRandom (const Vector< 3, real_t > &normal) |
Public Attributes | |
| T | data [(N)] |
| Underlying data stored as an N-length array of type T. | |
Detailed Description
template<unsigned N = 3, typename T = real_t>
class Vector< N, T >
A Vector is templated to store N elements of data of type T. If left off, T will default to a "real_t" data type, where a real_t is assumed to be either a float or a double.
Provides basic functionality for a constant-sized Vector.
Included in this definition are typedefs for the most commonly used vectors (Vector4, Vector3, etc), and these can be thought of as shortcuts to reference their associated Vector templates. For example, Vector4 can be used to refer to Vector<4, real_t>.
A Vector stores its data internally as an N-length array of type T.
- Date:
- Fall 2008
Definition at line 34 of file Vector.h.
Constructor & Destructor Documentation
Member Function Documentation
| static Vector<3, real_t> Vector< N, T >::cosRandom | ( | const Vector< 3, real_t > & | normal | ) | [static] |
Samples a random vector distributed according to a cosine-falloff about the given normal vector (within the upward hemisphere defined by the normal)
| const T & Vector< N, T >::operator[] | ( | const unsigned | index | ) | const [inline] |
- Returns:
- a const reference to the element at the given index
Definition at line 42 of file Vector.inl.
| T & Vector< N, T >::operator[] | ( | const unsigned | index | ) | [inline] |
- Returns:
- a reference to the element at the given index
- Note:
- changes to the returned element will affect this vector
Definition at line 51 of file Vector.inl.
| const T * Vector< N, T >::operator* | ( | ) | const [inline] |
- Returns:
- a pointer to the underlying data (N-length array of type T)
Definition at line 59 of file Vector.inl.
| T * Vector< N, T >::operator* | ( | ) | [inline] |
- Returns:
- a pointer to the underlying data (N-length array of type T)
Definition at line 65 of file Vector.inl.
| bool Vector< N, T >::operator== | ( | const Vector< N, T > & | v | ) | const [inline] |
Definition at line 73 of file Vector.inl.
| bool Vector< N, T >::operator!= | ( | const Vector< N, T > & | v | ) | const [inline] |
Definition at line 83 of file Vector.inl.
| Vector< N, T > & Vector< N, T >::operator= | ( | const Vector< N, T > & | v | ) | [inline] |
Definition at line 92 of file Vector.inl.
| Vector< N, T > & Vector< N, T >::operator+= | ( | const Vector< N, T > & | rhs | ) | [inline] |
Definition at line 100 of file Vector.inl.
| Vector< N, T > & Vector< N, T >::operator-= | ( | const Vector< N, T > & | rhs | ) | [inline] |
Definition at line 109 of file Vector.inl.
| Vector< N, T > & Vector< N, T >::operator*= | ( | const T & | scale | ) | [inline] |
Definition at line 118 of file Vector.inl.
| Vector< N, T > & Vector< N, T >::operator/= | ( | const T & | scale | ) | [inline] |
Definition at line 126 of file Vector.inl.
| Vector< N, T > Vector< N, T >::operator+ | ( | const Vector< N, T > & | rhs | ) | const [inline] |
Definition at line 143 of file Vector.inl.
| Vector< N, T > Vector< N, T >::operator- | ( | const Vector< N, T > & | rhs | ) | const [inline] |
Definition at line 154 of file Vector.inl.
| Vector< N, T > Vector< N, T >::operator* | ( | const T & | scale | ) | const [inline] |
Definition at line 177 of file Vector.inl.
| Vector< N, T > Vector< N, T >::operator/ | ( | const T & | scale | ) | const [inline] |
Definition at line 187 of file Vector.inl.
| bool Vector< N, T >::isUnit | ( | ) | const [inline] |
| bool Vector< N, T >::isZero | ( | ) | const [inline] |
- Returns:
- the reciprocal version of this vector (1.0 / this)
Definition at line 245 of file Vector.inl.
| T Vector< N, T >::normalize | ( | ) | [inline] |
| T Vector< N, T >::getMagnitude | ( | ) | const [inline] |
| T Vector< N, T >::getMagnitude2 | ( | ) | const [inline] |
| T Vector< N, T >::getDistance | ( | const Vector< N, T > & | v | ) | const [inline] |
- Returns:
- the magnitude of the vector connecting this vector to the one passed in
Definition at line 294 of file Vector.inl.
| T Vector< N, T >::getDistance2 | ( | const Vector< N, T > & | v | ) | const [inline] |
- Returns:
- the squared magnitude of the vector connecting this vector to the one passed in
Definition at line 301 of file Vector.inl.
| T Vector< N, T >::getSum | ( | ) | const [inline] |
| T Vector< N, T >::getAverage | ( | ) | const [inline] |
| unsigned Vector< N, T >::getMaxDimension | ( | ) | const [inline] |
| unsigned Vector< N, T >::getMinDimension | ( | ) | const [inline] |
| void Vector< N, T >::cleanup | ( | ) | [inline] |
Cleans up vector (0's out entries that are less than epsilon).
Definition at line 434 of file Vector.inl.
| Vector< N, T > Vector< N, T >::cross | ( | const Vector< N, T > & | rhs | ) | const [inline] |
- Returns:
- the cross product of two vectors
- Note:
- only have to implement for 3 or 4 dimensions (in either case, just use hardcoded cross product for 3 dimensions and if N is 4, set 'w' to 0)
Definition at line 353 of file Vector.inl.
| Vector< N, T > Vector< N, T >::reflectVector | ( | const Vector< N, T > & | normal | ) | const [inline] |
Assumes normal is normalized, incident vector is incoming and resultant vector is exiting
- Note:
- only defined for Vector3
Definition at line 445 of file Vector.inl.
| Vector< N, T > Vector< N, T >::refractVector | ( | const Vector< N, T > & | normal, | |
| real_t | in, | |||
| real_t | out = 1.0f | |||
| ) | const [inline] |
Definition at line 453 of file Vector.inl.
| void Vector< N, T >::getOrthonormalBasis | ( | Vector< N, T > & | U, | |
| Vector< N, T > & | V | |||
| ) | [inline] |
- Returns:
- an orthonormal basis constructed from this vector in out parameters U and V
- Note:
- only defined for Vector3
Definition at line 512 of file Vector.inl.
Member Data Documentation
The documentation for this class was generated from the following files:
Generated on 28 Feb 2009 for Milton by
1.5.6