mathglpp::GLVector2< T > Class Template Reference

#include <GLVector.h>

Collaboration diagram for mathglpp::GLVector2< T >:

Collaboration graph
[legend]
List of all members.

Detailed Description

template<typename T>
class mathglpp::GLVector2< T >

a 2D vector class for OpenGL

Definition at line 36 of file GLVector.h.

Public Types

enum  { D = 2 }

Public Member Functions

 GLVector2 ()
 Create an uninitialised vector.
 GLVector2 (const T &v)
 Create an initialised vector.
 GLVector2 (const T &v1, const T &v2)
 Create an initialised vector from values.
 GLVector2 (const GLVector2 &gv)
 Copy a vector.
 GLVector2 (const T *f)
 Create a vector from an array.
 ~GLVector2 ()
 Default destructor.
void set (const T &v1, const T &v2)
 element by element initialiser
T & operator[] (int ind)
 element by element accessor
 operator T * (void)
 implicit casting to a pointer
 operator const T * (void) const
 implicit casting to a const pointer
void glScale () const
 GL interface, glScale().
void glRotate (const T &ang) const
 GL interface, glRotate().
void glTranslate () const
 GL interface, glTranslate().
void glVertex () const
 GL interface, glVertex().
void glNormal () const
 GL interface, glNormal().
void copyTo (T *vec) const
 copy values to a array
const GLVector2 operator+ (const GLVector2 &gv) const
 Get the sum of this and a vector.
const GLVector2 operator- (const GLVector2 &gv) const
 Get the difference of this and a vector.
const GLVector2 operator * (const GLVector2 &gv) const
 Get the element-by-element product of this and a vector.
const GLVector2 operator/ (const GLVector2 &gv) const
 Get the element-by-element quota of this and a vector.
const GLVector2 operator * (const T &v) const
 Get the element-by-element product of this and a scalar.
const GLVector2 operator/ (const T &v) const
 Get the element-by-element quota of this and a scalar.
GLVector2operator+= (const GLVector2 &gv)
 Add a vector to this.
GLVector2operator-= (const GLVector2 &gv)
 Subtract a vector from this.
GLVector2operator *= (const T &f)
 Multiply this by a scalar.
GLVector2operator/= (const T &f)
 Divide this by a scalar.
GLVector2operator= (const GLVector2 &v)
 copy this from a vector
bool operator== (const GLVector2 &v)
 Equality check. NB. May not be constant time, depending on memcmp.
const GLVector2 operator- () const
 negate this
const T dot (const GLVector2 &gv) const
 Get the dot product of this and a vector.
length () const
 Get the length of this.
lengthSqr () const
 Get the length squared, less computation than length().
const GLVector2 unit () const
 Get the the unit vector of this.
GLVector2normalize ()
 Normalize this, makes this a unit vector, US spelling.
const T projection (const GLVector2 &in) const
 Get the projection of this and a vector.
GLVector2 orthogonalProjection (const GLVector2 &in) const
 Get the orthogonal projection of this and a vector.
GLVector2 vectorProjection (const GLVector2 &in) const
 Get the vector projection of this and a vector.
template<>
void glScale () const
template<>
void glScale () const
template<>
void glScale () const
template<>
void glScale () const
template<>
void glScale () const
template<>
void glRotate (const GLfloat &ang) const
template<>
void glRotate (const GLdouble &ang) const
template<>
void glTranslate () const
template<>
void glTranslate () const
template<>
void glVertex () const
template<>
void glNormal () const
template<>
void glNormal () const

Public Attributes

union {
   T   val [D]
   struct {
      T   x
      T   y
   } 
}; 
 Value array Anonymous union and struct by sebastien bloc (sebastien.bloc@free.fr).


Member Enumeration Documentation

template<typename T>
anonymous enum

Enumerator:
D 

Definition at line 39 of file GLVector.h.

00039 { D = 2 };


Constructor & Destructor Documentation

template<typename T>
mathglpp::GLVector2< T >::GLVector2 (  )  [inline]

Create an uninitialised vector.

Definition at line 42 of file GLVector.h.

Referenced by mathglpp::GLVector2< T >::operator *(), mathglpp::GLVector2< T >::operator+(), mathglpp::GLVector2< T >::operator-(), and mathglpp::GLVector2< T >::operator/().

00043     { }

template<typename T>
mathglpp::GLVector2< T >::GLVector2 ( const T &  v  )  [inline]

Create an initialised vector.

Definition at line 46 of file GLVector.h.

References mathglpp::GLVector2< T >::x, and mathglpp::GLVector2< T >::y.

00047     {   x = y = v; }

template<typename T>
mathglpp::GLVector2< T >::GLVector2 ( const T &  v1,
const T &  v2 
) [inline]

Create an initialised vector from values.

Definition at line 50 of file GLVector.h.

References mathglpp::GLVector2< T >::x, and mathglpp::GLVector2< T >::y.

00051     {   x = v1; y = v2; }

template<typename T>
mathglpp::GLVector2< T >::GLVector2 ( const GLVector2< T > &  gv  )  [inline]

Copy a vector.

Definition at line 54 of file GLVector.h.

References mathglpp::GLVector2< T >::D, and mathglpp::GLVector2< T >::val.

00055     {   memmove(val,gv.val,D*sizeof(T)); }

template<typename T>
mathglpp::GLVector2< T >::GLVector2 ( const T *  f  )  [inline]

Create a vector from an array.

Definition at line 58 of file GLVector.h.

References mathglpp::GLVector2< T >::D, and mathglpp::GLVector2< T >::val.

00059     {   memmove(val,f,D*sizeof(T)); }

template<typename T>
mathglpp::GLVector2< T >::~GLVector2 (  )  [inline]

Default destructor.

Definition at line 62 of file GLVector.h.

00062 {}


Member Function Documentation

template<typename T>
void mathglpp::GLVector2< T >::set ( const T &  v1,
const T &  v2 
) [inline]

element by element initialiser

Definition at line 65 of file GLVector.h.

References mathglpp::GLVector2< T >::x, and mathglpp::GLVector2< T >::y.

00066     {   x = v1; y = v2; }

template<typename T>
T& mathglpp::GLVector2< T >::operator[] ( int  ind  )  [inline]

element by element accessor

Definition at line 69 of file GLVector.h.

References mathglpp::GLVector2< T >::val.

00070     {   return val[ind]; }

template<typename T>
mathglpp::GLVector2< T >::operator T * ( void   )  [inline]

implicit casting to a pointer

Definition at line 73 of file GLVector.h.

References mathglpp::GLVector2< T >::val.

00074     {   return val; }

template<typename T>
mathglpp::GLVector2< T >::operator const T * ( void   )  const [inline]

implicit casting to a const pointer

Definition at line 77 of file GLVector.h.

References mathglpp::GLVector2< T >::val.

00078     {   return val; }

template<typename T>
void mathglpp::GLVector2< T >::glScale (  )  const [inline]

GL interface, glScale().

template<typename T>
void mathglpp::GLVector2< T >::glRotate ( const T &  ang  )  const [inline]

GL interface, glRotate().

template<typename T>
void mathglpp::GLVector2< T >::glTranslate (  )  const [inline]

GL interface, glTranslate().

template<typename T>
void mathglpp::GLVector2< T >::glVertex (  )  const [inline]

GL interface, glVertex().

Definition at line 87 of file GLVector.h.

References mathglpp::GLVector2< T >::val.

00087 { mathglpp::glVertexv<D,T>(val); }

template<typename T>
void mathglpp::GLVector2< T >::glNormal (  )  const [inline]

GL interface, glNormal().

template<typename T>
void mathglpp::GLVector2< T >::copyTo ( T *  vec  )  const [inline]

copy values to a array

Definition at line 92 of file GLVector.h.

References mathglpp::GLVector2< T >::val.

00093     {   memmove(vec,val,2*sizeof(T)); }

template<typename T>
const GLVector2 mathglpp::GLVector2< T >::operator+ ( const GLVector2< T > &  gv  )  const [inline]

Get the sum of this and a vector.

Definition at line 96 of file GLVector.h.

References mathglpp::GLVector2< T >::GLVector2(), mathglpp::GLVector2< T >::x, and mathglpp::GLVector2< T >::y.

00097     {
00098         return GLVector2(x+gv.x,y+gv.y);
00099     }

Here is the call graph for this function:

template<typename T>
const GLVector2 mathglpp::GLVector2< T >::operator- ( const GLVector2< T > &  gv  )  const [inline]

Get the difference of this and a vector.

Definition at line 102 of file GLVector.h.

References mathglpp::GLVector2< T >::GLVector2(), mathglpp::GLVector2< T >::x, and mathglpp::GLVector2< T >::y.

00103     {
00104         return GLVector2(x-gv.x,y-gv.y);
00105     }

Here is the call graph for this function:

template<typename T>
const GLVector2 mathglpp::GLVector2< T >::operator * ( const GLVector2< T > &  gv  )  const [inline]

Get the element-by-element product of this and a vector.

Definition at line 108 of file GLVector.h.

References mathglpp::GLVector2< T >::GLVector2(), mathglpp::GLVector2< T >::x, and mathglpp::GLVector2< T >::y.

00109     {
00110         return GLVector2(x*gv.x,y*gv.y);
00111     }

Here is the call graph for this function:

template<typename T>
const GLVector2 mathglpp::GLVector2< T >::operator/ ( const GLVector2< T > &  gv  )  const [inline]

Get the element-by-element quota of this and a vector.

Definition at line 114 of file GLVector.h.

References mathglpp::GLVector2< T >::GLVector2(), mathglpp::GLVector2< T >::x, and mathglpp::GLVector2< T >::y.

00115     {
00116         return GLVector2(x/gv.x,y/gv.y);
00117     }

Here is the call graph for this function:

template<typename T>
const GLVector2 mathglpp::GLVector2< T >::operator * ( const T &  v  )  const [inline]

Get the element-by-element product of this and a scalar.

Definition at line 120 of file GLVector.h.

References mathglpp::GLVector2< T >::GLVector2(), mathglpp::GLVector2< T >::x, and mathglpp::GLVector2< T >::y.

00121     {
00122         return GLVector2(x*v,y*v);
00123     }

Here is the call graph for this function:

template<typename T>
const GLVector2 mathglpp::GLVector2< T >::operator/ ( const T &  v  )  const [inline]

Get the element-by-element quota of this and a scalar.

Definition at line 126 of file GLVector.h.

References mathglpp::GLVector2< T >::GLVector2(), mathglpp::GLVector2< T >::x, and mathglpp::GLVector2< T >::y.

00127     {
00128         return GLVector2(x/v,y/v);
00129     }

Here is the call graph for this function:

template<typename T>
GLVector2& mathglpp::GLVector2< T >::operator+= ( const GLVector2< T > &  gv  )  [inline]

Add a vector to this.

Definition at line 132 of file GLVector.h.

References mathglpp::GLVector2< T >::x, and mathglpp::GLVector2< T >::y.

00133     {
00134         x += gv.x;
00135         y += gv.y;
00136         return *this;
00137     }

template<typename T>
GLVector2& mathglpp::GLVector2< T >::operator-= ( const GLVector2< T > &  gv  )  [inline]

Subtract a vector from this.

Definition at line 140 of file GLVector.h.

References mathglpp::GLVector2< T >::x, and mathglpp::GLVector2< T >::y.

00141     {
00142         x -= gv.x;
00143         y -= gv.y;
00144         return *this;
00145     }

template<typename T>
GLVector2& mathglpp::GLVector2< T >::operator *= ( const T &  f  )  [inline]

Multiply this by a scalar.

Definition at line 148 of file GLVector.h.

References mathglpp::GLVector2< T >::x, and mathglpp::GLVector2< T >::y.

00149     {
00150         x *= f;
00151         y *= f;
00152         return *this;
00153     }

template<typename T>
GLVector2& mathglpp::GLVector2< T >::operator/= ( const T &  f  )  [inline]

Divide this by a scalar.

Definition at line 156 of file GLVector.h.

References mathglpp::GLVector2< T >::x, and mathglpp::GLVector2< T >::y.

00157     {
00158         x /= f;
00159         y /= f;
00160         return *this;
00161     }

template<typename T>
GLVector2& mathglpp::GLVector2< T >::operator= ( const GLVector2< T > &  v  )  [inline]

copy this from a vector

Definition at line 164 of file GLVector.h.

References mathglpp::GLVector2< T >::D, and mathglpp::GLVector2< T >::val.

00165     {   memmove(val, v.val, D*sizeof(T)); return *this; }

template<typename T>
bool mathglpp::GLVector2< T >::operator== ( const GLVector2< T > &  v  )  [inline]

Equality check. NB. May not be constant time, depending on memcmp.

Definition at line 168 of file GLVector.h.

References mathglpp::GLVector2< T >::D, and mathglpp::GLVector2< T >::val.

00169     {   return memcmp(val, v.val, D*sizeof(T))==0;  }

template<typename T>
const GLVector2 mathglpp::GLVector2< T >::operator- (  )  const [inline]

negate this

Definition at line 172 of file GLVector.h.

References mathglpp::GLVector2< T >::GLVector2(), mathglpp::GLVector2< T >::x, and mathglpp::GLVector2< T >::y.

00173     {
00174         return GLVector2(-x,-y);
00175     }

Here is the call graph for this function:

template<typename T>
const T mathglpp::GLVector2< T >::dot ( const GLVector2< T > &  gv  )  const [inline]

Get the dot product of this and a vector.

Definition at line 178 of file GLVector.h.

References mathglpp::GLVector2< T >::x, and mathglpp::GLVector2< T >::y.

Referenced by mathglpp::GLVector2< T >::projection(), and mathglpp::GLVector2< T >::vectorProjection().

00179     {   return x*gv.x + y*gv.y; }

template<typename T>
T mathglpp::GLVector2< T >::length (  )  const [inline]

Get the length of this.

Definition at line 182 of file GLVector.h.

References mathglpp::GLVector2< T >::lengthSqr().

Referenced by mathglpp::GLVector2< T >::normalize(), and mathglpp::GLVector2< T >::unit().

00183     {   return sqrt(lengthSqr()); }

Here is the call graph for this function:

template<typename T>
T mathglpp::GLVector2< T >::lengthSqr (  )  const [inline]

Get the length squared, less computation than length().

Definition at line 186 of file GLVector.h.

References mathglpp::GLVector2< T >::x, and mathglpp::GLVector2< T >::y.

Referenced by mathglpp::GLVector2< T >::length().

00187     {   return x * x + y * y; }

template<typename T>
const GLVector2 mathglpp::GLVector2< T >::unit (  )  const [inline]

Get the the unit vector of this.

Definition at line 190 of file GLVector.h.

References mathglpp::GLVector2< T >::length().

00191     {
00192         return (*this)/length();
00193     }

Here is the call graph for this function:

template<typename T>
GLVector2& mathglpp::GLVector2< T >::normalize (  )  [inline]

Normalize this, makes this a unit vector, US spelling.

Definition at line 196 of file GLVector.h.

References mathglpp::GLVector2< T >::length().

00197     {
00198         (*this)/=length();
00199         return *this;
00200     }

Here is the call graph for this function:

template<typename T>
const T mathglpp::GLVector2< T >::projection ( const GLVector2< T > &  in  )  const [inline]

Get the projection of this and a vector.

Definition at line 203 of file GLVector.h.

References mathglpp::GLVector2< T >::dot().

00204     {   return dot(in); }

Here is the call graph for this function:

template<typename T>
GLVector2 mathglpp::GLVector2< T >::orthogonalProjection ( const GLVector2< T > &  in  )  const [inline]

Get the orthogonal projection of this and a vector.

Definition at line 207 of file GLVector.h.

References mathglpp::GLVector2< T >::vectorProjection().

00208     {   return in - vectorProjection(in); }

Here is the call graph for this function:

template<typename T>
GLVector2 mathglpp::GLVector2< T >::vectorProjection ( const GLVector2< T > &  in  )  const [inline]

Get the vector projection of this and a vector.

Definition at line 211 of file GLVector.h.

References mathglpp::GLVector2< T >::dot().

Referenced by mathglpp::GLVector2< T >::orthogonalProjection().

00212     {   return (*this) * dot(in); }

Here is the call graph for this function:

template<>
void mathglpp::GLVector2< GLbyte >::glVertex (  )  const [inline]

Closest possible fit

Definition at line 85 of file GLVector.cpp.

References mathglpp::GLVector2< T >::x, and mathglpp::GLVector2< T >::y.

00086 {
00087     ::glVertex2s(x,y); 
00088 }


Member Data Documentation

union { ... }

Value array Anonymous union and struct by sebastien bloc (sebastien.bloc@free.fr).


The documentation for this class was generated from the following file:
Generated on Wed Oct 3 12:50:53 2007 for MathGL++ by  doxygen 1.5.2