Vector2< T > Class Template Reference

A 2D vector template. More...

#include <Math/Vector.h>

List of all members.

Public Member Functions

 Vector2 ()
 Default constructor. Constructs the zero vector.
 Vector2 (T _x, T _y)
 Constructs a spacific vector.
void Set (T _x, T _y)
 Sets the x and y values of the vector.
Dot (const Vector2 &v) const
 Computes the dot product.
Length () const
 Computes the length of this vector.
SquaredLength () const
 Computes the squared length of this vector.
Angle (const Vector2 &v) const
 Computes the angle in radians between this vector and v.
void Normalize ()
 Normalizes this the vector.
const Vector2 Reflect (const Vector2 &n) const
 Reflects this vector about the vector n.
const Vector2 Refract (const Vector2 &n, T index=1.0f) const
 Refracts this vector about the vector n with index of refraction index.
const Vector2 Project (const Vector2 &L) const
 Projects this vector onto the vector L.
const Vector2 Perp () const
 Computes a vector perpendicular to this vector.
const Vector2 operator+ (const Vector2 &v) const
 Overloaded vector addition operator.
const Vector2 operator- (const Vector2 &v) const
 Overloaded vector subtraction operator.
Vector2< T > operator- () const
 Overloaded vector negation operator.
const Vector2 operator* (T c) const
 Overloaded constant multiplication operator.
const Vector2 operator/ (T c) const
 Overloaded constant division operator.
T & operator[] (int i)
 Overloaded array access operator.
operator[] (int i) const
 Overloaded array access operator.

Public Attributes

x
 The (x,y) vector data.

Friends

const Vector2 operator* (T c, const Vector2 &v)
 Overloaded constant-vector multiplication operator.

Detailed Description

template<class T>
class Vector2< T >

A 2D vector template.

Template Parameters:
T the type that x and y take. Usually float or double.

A 2D vector template that provides useful methods for manipulating 2D vectors.


Constructor & Destructor Documentation

template<class T>
Vector2< T >::Vector2 ( _x,
_y 
) [inline]

Constructs a spacific vector.

Parameters:
[in] _x the value x is set to.
[in] _y the value y is set to.

Member Function Documentation

template<class T>
T Vector2< T >::Angle ( const Vector2< T > &  v  )  const [inline]

Computes the angle in radians between this vector and v.

Parameters:
[in] v the vector used to compute and angle between.
Returns:
The angle in radians between this vector and v.
template<class T>
T Vector2< T >::Dot ( const Vector2< T > &  v  )  const [inline]

Computes the dot product.

Parameters:
[in] v the vector to compute the dot product with.
Returns:
The dot product between this vector and the input vector v. $v_1\cdot v_2 = x_1*x_2 + y_1*y_2$
template<class T>
T Vector2< T >::Length (  )  const [inline]

Computes the length of this vector.

Returns:
the length of this vector $\sqrt{x^2 + y^2}$
template<class T>
void Vector2< T >::Normalize (  )  [inline]

Normalizes this the vector.

Changes x and y such that the length of this vector is 1 and the direction is preserved.

template<class T>
const Vector2 Vector2< T >::operator* ( c  )  const [inline]

Overloaded constant multiplication operator.

Parameters:
[in] c the constant to multiply by.
Returns:
The vector result of multiply this vector by c.
template<class T>
const Vector2 Vector2< T >::operator+ ( const Vector2< T > &  v  )  const [inline]

Overloaded vector addition operator.

Parameters:
[in] v the vector to add.
Returns:
The vector result of adding this vector to v.
template<class T>
Vector2<T> Vector2< T >::operator- (  )  const [inline]

Overloaded vector negation operator.

Returns:
The negation of this vector.
template<class T>
const Vector2 Vector2< T >::operator- ( const Vector2< T > &  v  )  const [inline]

Overloaded vector subtraction operator.

Parameters:
[in] v the vector to subtract.
Returns:
The vector result of subtracting v font this vector.
template<class T>
const Vector2 Vector2< T >::operator/ ( c  )  const [inline]

Overloaded constant division operator.

Parameters:
[in] c the constant to divide by.
Returns:
The vector result of divideing this vector by c.
template<class T>
T Vector2< T >::operator[] ( int  i  )  const [inline]

Overloaded array access operator.

Parameters:
[in] i must be either 0 for x or 1 for y
Returns:
Either x if i = 0 or y if i = 1
template<class T>
T& Vector2< T >::operator[] ( int  i  )  [inline]

Overloaded array access operator.

Parameters:
[in] i must be either 0 for x or 1 for y
Returns:
Either a referance to x if i = 0 or a referance to y if i = 1
template<class T>
const Vector2 Vector2< T >::Perp (  )  const [inline]

Computes a vector perpendicular to this vector.

Returns:
The perpendicular vector.
template<class T>
const Vector2 Vector2< T >::Project ( const Vector2< T > &  L  )  const [inline]

Projects this vector onto the vector L.

Parameters:
[in] L the vector to project onto.
Returns:
The projected vector $L(v\cdot L)$
template<class T>
const Vector2 Vector2< T >::Reflect ( const Vector2< T > &  n  )  const [inline]

Reflects this vector about the vector n.

Parameters:
[in] n the vector that to reflect against.
Returns:
The reflected vector. $v_2 = v_1 - 2n(v_1\cdot n)$
template<class T>
const Vector2 Vector2< T >::Refract ( const Vector2< T > &  n,
index = 1.0f 
) const [inline]

Refracts this vector about the vector n with index of refraction index.

Parameters:
[in] n the vector that to refract against.
[in] index the index of refraction.
Returns:
The refracted vector.
template<class T>
void Vector2< T >::Set ( _x,
_y 
) [inline]

Sets the x and y values of the vector.

Parameters:
[in] _x the value x is set to.
[in] _y the value y is set to.
template<class T>
T Vector2< T >::SquaredLength (  )  const [inline]

Computes the squared length of this vector.

Returns:
The squared length of this vector $x^2 + y^2$

Friends And Related Function Documentation

template<class T>
const Vector2 operator* ( c,
const Vector2< T > &  v 
) [friend]

Overloaded constant-vector multiplication operator.

Parameters:
[in] c the constant.
[in] v the vector.
Returns:
The vector result c*v.

The documentation for this class was generated from the following file:
Generated on Mon Apr 5 19:08:06 2010 for BrickOut |ReDuX| by  doxygen 1.6.3