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>

List of all members.

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
normalize ()
 Normalizes this Vector and returns the old magnitude.
getMagnitude () const
getMagnitude2 () const
getDistance (const Vector< N, T > &v) const
getDistance2 (const Vector< N, T > &v) const
getSum () const
getAverage () const
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_tcosRandom (const Vector< 3, real_t > &normal)

Public Attributes

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.

Author:
Travis Fischer (fisch0920@gmail.com)
Date:
Fall 2008

Definition at line 34 of file Vector.h.


Constructor & Destructor Documentation

template<unsigned N, typename T>
Vector< N, T >::Vector ( const T *  srcData  )  [inline]

Expects N arguments of type T.

Definition at line 20 of file Vector.inl.

template<unsigned N, typename T>
Vector< N, T >::Vector (  )  [inline]

Constructs a zero Vector.

Definition at line 26 of file Vector.inl.

template<unsigned N, typename T>
Vector< N, T >::Vector ( const Vector< N, T > &  v  )  [inline]

Copy Constructor.

Definition at line 32 of file Vector.inl.

template<unsigned N, typename T>
Vector< N, T >::Vector ( const T &  v0,
const T &  v1 = 0,
const T &  v2 = 0 
) [inline, explicit]

Convenience Constructor.

Definition at line 339 of file Vector.inl.


Member Function Documentation

template<unsigned N = 3, typename T = real_t>
static Vector<N, T> Vector< N, T >::zero (  )  [inline, static]

Generates a vector full of zeroes.

Definition at line 58 of file Vector.h.

template<unsigned N = 3, typename T = real_t>
static Vector<N, T> Vector< N, T >::ones (  )  [inline, static]

Generates a vector full of ones.

Definition at line 63 of file Vector.h.

template<unsigned N = 3, typename T = real_t>
static Vector<N, T> Vector< N, T >::fill ( const T &  val  )  [inline, static]

Generates a vector filled with the specified value.

Definition at line 68 of file Vector.h.

template<unsigned N = 3, typename T = real_t>
static Vector<N, T> Vector< N, T >::min ( const Vector< N, T > &  v1,
const Vector< N, T > &  v2 
) [inline, static]

Returns:
the element-wise minimum vector from the two given vectors

Definition at line 78 of file Vector.h.

template<unsigned N = 3, typename T = real_t>
static Vector<N, T> Vector< N, T >::max ( const Vector< N, T > &  v1,
const Vector< N, T > &  v2 
) [inline, static]

Returns:
the element-wise maximum vector from the two given vectors

Definition at line 88 of file Vector.h.

template<unsigned N = 3, typename T = real_t>
static Vector<N, T> Vector< N, T >::infinity (  )  [inline, static]

Generates a vector filled with the maximum T (infinity).

Definition at line 98 of file Vector.h.

template<unsigned N = 3, typename T = real_t>
static Vector<N, T> Vector< N, T >::negativeInfinity (  )  [inline, static]

Generates a vector filled with the minimum T (negative infinity).

Definition at line 103 of file Vector.h.

template<unsigned N = 3, typename T = real_t>
static Vector<3, T> Vector< N, T >::fromSpherical ( theta,
phi 
) [inline, static]

theta is latitude angle; phi is longitude angle

Definition at line 111 of file Vector.h.

template<unsigned N = 3, typename T = real_t>
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)

template<unsigned N, typename T>
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.

template<unsigned N, typename T>
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.

template<unsigned N, typename T>
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.

template<unsigned N, typename T>
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.

template<unsigned N, typename T>
bool Vector< N, T >::operator== ( const Vector< N, T > &  v  )  const [inline]

Definition at line 73 of file Vector.inl.

template<unsigned N, typename T>
bool Vector< N, T >::operator!= ( const Vector< N, T > &  v  )  const [inline]

Definition at line 83 of file Vector.inl.

template<unsigned N, typename T>
Vector< N, T > & Vector< N, T >::operator= ( const Vector< N, T > &  v  )  [inline]

Definition at line 92 of file Vector.inl.

template<unsigned N, typename T>
Vector< N, T > & Vector< N, T >::operator+= ( const Vector< N, T > &  rhs  )  [inline]

Definition at line 100 of file Vector.inl.

template<unsigned N, typename T>
Vector< N, T > & Vector< N, T >::operator-= ( const Vector< N, T > &  rhs  )  [inline]

Definition at line 109 of file Vector.inl.

template<unsigned N, typename T>
Vector< N, T > & Vector< N, T >::operator*= ( const T &  scale  )  [inline]

Definition at line 118 of file Vector.inl.

template<unsigned N, typename T>
Vector< N, T > & Vector< N, T >::operator/= ( const T &  scale  )  [inline]

Definition at line 126 of file Vector.inl.

template<unsigned N, typename T>
Vector< N, T > Vector< N, T >::operator+ ( const Vector< N, T > &  rhs  )  const [inline]

Definition at line 143 of file Vector.inl.

template<unsigned N, typename T>
Vector< N, T > Vector< N, T >::operator- ( const Vector< N, T > &  rhs  )  const [inline]

Definition at line 154 of file Vector.inl.

template<unsigned N, typename T>
Vector< N, T > Vector< N, T >::operator* ( const Vector< N, T > &  rhs  )  const [inline]

Returns:
element-wise multiplication of two vectors

Definition at line 165 of file Vector.inl.

template<unsigned N, typename T>
Vector< N, T > Vector< N, T >::operator* ( const T &  scale  )  const [inline]

Definition at line 177 of file Vector.inl.

template<unsigned N, typename T>
Vector< N, T > Vector< N, T >::operator/ ( const T &  scale  )  const [inline]

Definition at line 187 of file Vector.inl.

template<unsigned N, typename T>
bool Vector< N, T >::isUnit (  )  const [inline]

Returns:
whether or not this Vector is unitized

Definition at line 204 of file Vector.inl.

template<unsigned N, typename T>
bool Vector< N, T >::isZero (  )  const [inline]

Returns:
whether or not this Vector is the zero vector

Definition at line 210 of file Vector.inl.

template<unsigned N, typename T>
Vector< N, T > Vector< N, T >::getNormalized (  )  const [inline]

Returns:
a normalized version of this vector

Definition at line 221 of file Vector.inl.

template<unsigned N, typename T>
Vector< N, T > Vector< N, T >::getReciprocal (  )  const [inline]

Returns:
the reciprocal version of this vector (1.0 / this)

Definition at line 245 of file Vector.inl.

template<unsigned N, typename T>
T Vector< N, T >::normalize (  )  [inline]

Normalizes this Vector and returns the old magnitude.

Definition at line 256 of file Vector.inl.

template<unsigned N, typename T>
T Vector< N, T >::getMagnitude (  )  const [inline]

Returns:
the magnitude of this vector

Definition at line 276 of file Vector.inl.

template<unsigned N, typename T>
T Vector< N, T >::getMagnitude2 (  )  const [inline]

Returns:
the squared magnitude of this vector

Definition at line 282 of file Vector.inl.

template<unsigned N, typename T>
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.

template<unsigned N, typename T>
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.

template<unsigned N, typename T>
T Vector< N, T >::getSum (  )  const [inline]

Returns:
the sum of the components in this Vector

Definition at line 307 of file Vector.inl.

template<unsigned N, typename T>
T Vector< N, T >::getAverage (  )  const [inline]

Returns:
the average of the components in this Vector

Definition at line 318 of file Vector.inl.

template<unsigned N, typename T>
T Vector< N, T >::dot ( const Vector< N, T > &  rhs  )  const [inline]

Returns:
the dot (inner) product of two vectors

Definition at line 324 of file Vector.inl.

template<unsigned N, typename T>
unsigned Vector< N, T >::getMaxDimension (  )  const [inline]

Returns:
dimension (0,1,...,N) of maximum length

Definition at line 403 of file Vector.inl.

template<unsigned N, typename T>
unsigned Vector< N, T >::getMinDimension (  )  const [inline]

Returns:
dimension (0,1,...,N) of minimum length

Definition at line 421 of file Vector.inl.

template<unsigned N, typename T>
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.

template<unsigned N, typename T>
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.

template<unsigned N, typename T>
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.

template<unsigned N, typename T>
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.

template<unsigned N, typename T>
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

template<unsigned N = 3, typename T = real_t>
T Vector< N, T >::data[(N)]

Underlying data stored as an N-length array of type T.

Definition at line 37 of file Vector.h.


The documentation for this class was generated from the following files:

Generated on 28 Feb 2009 for Milton by doxygen 1.5.6