Public Attributes

CS123Vector< N, T > Struct Template Reference

A CS123Vector is templated to store N elements of data of type T. If left off, T will default to a "REAL" data type. More...

#include <CS123Vector.h>

List of all members.

Public Member Functions

Constructors

 CS123Vector (const T *srcData)
 Expects N arguments of type T.
 CS123Vector ()
 Constructs a zero Vector.
 CS123Vector (const CS123Vector< 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 CS123Vector< N, T > &v) const
bool operator!= (const CS123Vector< N, T > &v) const
Mutator Operators

CS123Vector< N, T > & operator= (const CS123Vector< N, T > &v)
CS123Vector< N, T > & operator+= (const CS123Vector< N, T > &rhs)
CS123Vector< N, T > & operator-= (const CS123Vector< N, T > &rhs)
Scalar Mutator Operators

CS123Vector< N, T > & operator*= (const T &scale)
CS123Vector< N, T > & operator/= (const T &scale)
Arithmetic Operators

CS123Vector< N, T > operator+ (const CS123Vector< N, T > &rhs) const
CS123Vector< N, T > operator- (const CS123Vector< N, T > &rhs) const
Scalar Arithmetic Operators

CS123Vector< N, T > operator* (const T &scale) const
CS123Vector< N, T > operator/ (const T &scale) const
More Complex Functionality

bool isUnit () const
bool isZero () const
CS123Vector< N, T > getNormalized () const
normalize ()
 Normalizes this Vector and returns the old magnitude.
getMagnitude () const
getMagnitude2 () const
getDistance (const CS123Vector< N, T > &v) const
getDistance2 (const CS123Vector< N, T > &v) const
getSum () const
getAverage () const
dot (const CS123Vector< N, T > &rhs) const
void cleanup ()
 Cleans up vector (0's out entries that are less than epsilon).
Specialized Vector Functionality

 CS123Vector (const T &v0, const T &v1=0, const T &v2=0, const T &v3=0)
 Convenience Constructor.
CS123Vector< N, T > cross (const CS123Vector< N, T > &rhs) const
CS123Vector< N, T > reflectVector (const CS123Vector< N, T > &normal) const
CS123Vector< N, T > refractVector (const CS123Vector< N, T > &normal, REAL in, REAL out=1.0f) const

Static Public Member Functions

Static convenience constructors to generate common matrices

static CS123Vector< N, T > zero ()
 Generates a vector full of zeroes.
static CS123Vector< N, T > ones ()
 Generates a vector full of ones.
static CS123Vector< N, T > fill (const T &val)
 Generates a vector filled with the specified value.
static CS123Vector< N, T > min (const CS123Vector< N, T > &v1, const CS123Vector< N, T > &v2)
static CS123Vector< N, T > max (const CS123Vector< N, T > &v1, const CS123Vector< N, T > &v2)
static CS123Vector< N, T > infinity ()
 Generates a vector filled with the maximum T (infinity).
static CS123Vector< N, T > negativeInfinity ()
 Generates a vector filled with the minimum T (negative infinity).

Public Attributes

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

Detailed Description

template<unsigned N = 3, typename T = REAL>
struct CS123Vector< N, T >

A CS123Vector is templated to store N elements of data of type T. If left off, T will default to a "REAL" data type.

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 CS123Vector templates. For example, Vector4 can be used to refer to CS123Vector<4, REAL>.

A CS123Vector stores its data internally as an N-length array of type T.


Member Function Documentation

template<unsigned N, typename T>
CS123Vector< N, T > CS123Vector< N, T >::cross ( const CS123Vector< 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)
template<unsigned N, typename T>
T CS123Vector< N, T >::dot ( const CS123Vector< N, T > &  rhs  )  const [inline]
Returns:
the dot (inner) product of two vectors
template<unsigned N, typename T >
T CS123Vector< N, T >::getAverage (  )  const [inline]
Returns:
the average of the components in this Vector
template<unsigned N, typename T>
T CS123Vector< N, T >::getDistance ( const CS123Vector< N, T > &  v  )  const [inline]
Returns:
the magnitude of the vector connecting this vector to the one passed in
template<unsigned N, typename T>
T CS123Vector< N, T >::getDistance2 ( const CS123Vector< N, T > &  v  )  const [inline]
Returns:
the squared magnitude of the vector connecting this vector to the one passed in
template<unsigned N, typename T >
T CS123Vector< N, T >::getMagnitude (  )  const [inline]
Returns:
the magnitude of this vector
template<unsigned N, typename T >
T CS123Vector< N, T >::getMagnitude2 (  )  const [inline]
Returns:
the squared magnitude of this vector
template<unsigned N, typename T >
CS123Vector< N, T > CS123Vector< N, T >::getNormalized (  )  const [inline]
Returns:
a normalized version of this vector
template<unsigned N, typename T >
T CS123Vector< N, T >::getSum (  )  const [inline]
Returns:
the sum of the components in this Vector
template<unsigned N, typename T >
bool CS123Vector< N, T >::isUnit (  )  const [inline]
Returns:
whether or not this Vector is unitized
template<unsigned N, typename T >
bool CS123Vector< N, T >::isZero (  )  const [inline]
Returns:
whether or not this Vector is the zero vector
template<unsigned N = 3, typename T = REAL>
static CS123Vector<N, T> CS123Vector< N, T >::max ( const CS123Vector< N, T > &  v1,
const CS123Vector< N, T > &  v2 
) [inline, static]
Returns:
the element-wise maximum vector from the two given vectors
template<unsigned N = 3, typename T = REAL>
static CS123Vector<N, T> CS123Vector< N, T >::min ( const CS123Vector< N, T > &  v1,
const CS123Vector< N, T > &  v2 
) [inline, static]
Returns:
the element-wise minimum vector from the two given vectors
template<unsigned N, typename T >
const T * CS123Vector< N, T >::operator* (  )  const [inline]
Returns:
a pointer to the underlying data (N-length array of type T)
template<unsigned N, typename T >
T * CS123Vector< N, T >::operator* (  )  [inline]
Returns:
a pointer to the underlying data (N-length array of type T)
template<unsigned N, typename T >
T & CS123Vector< 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
template<unsigned N, typename T >
const T & CS123Vector< N, T >::operator[] ( const unsigned  index  )  const [inline]
Returns:
a const reference to the element at the given index
template<unsigned N, typename T>
CS123Vector< N, T > CS123Vector< N, T >::reflectVector ( const CS123Vector< N, T > &  normal  )  const

Assumes normal is normalized, incident vector is incoming and resultant vector is exiting

Note:
these two functions are strictly extra credit!

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