mathglpp::GLVector4< T > Class Template Reference

#include <GLVector.h>

Collaboration diagram for mathglpp::GLVector4< T >:

Collaboration graph
[legend]
List of all members.

Detailed Description

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

a 3D rational vector class for OpenGL

Definition at line 885 of file GLVector.h.

Public Types

enum  { D = 4 }
 Keep the dimensions as a defined enum. More...

Public Member Functions

 GLVector4 ()
 Create an uninitialised vector.
 GLVector4 (const T &v)
 Create an initialised vector.
 GLVector4 (const T &v1, const T &v2, const T &v3, const T &v4)
 Create an initialised vector from values.
 GLVector4 (const GLVector4 &gv)
 Copy a vector.
 GLVector4 (const T *f)
 Create a vector from an array.
 ~GLVector4 ()
 Default destructor.
void set (const T &v1, const T &v2, const T &v3, const T &v4)
 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 GLVector4 operator+ (const GLVector4 &gv) const
 Get the sum of this and a vector.
const GLVector4 operator- (const GLVector4 &gv) const
 Get the difference of this and a vector.
const GLVector4 operator * (const GLVector4 &gv) const
 Get the element-by-element product of this and a vector.
const GLVector4 operator/ (const GLVector4 &gv) const
 Get the element-by-element quota of this and a vector.
const GLVector4 operator * (const T &v) const
 Get the element-by-element product of this and a scalar.
const GLVector4 operator/ (const T &v) const
 Get the element-by-element quota of this and a scalar.
GLVector4operator+= (const GLVector4 &gv)
 Add a vector to this.
GLVector4operator-= (const GLVector4 &gv)
 Subtract a vector from this.
GLVector4operator *= (const T &f)
 Multiply this by a scalar.
GLVector4operator/= (const T &f)
 Divide this by a scalar.
GLVector4operator= (const GLVector4 &gv)
 copy this from a vector
bool operator== (const GLVector4 &v)
 Equality check. NB. May not be constant time, depending on memcmp.
const GLVector4 operator- () const
 negate this
const T dot (const GLVector4 &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 GLVector4 getCross (const GLVector4 &gv) const
 Get the cross-product of this and a vector.
GLVector4cross (const GLVector4 &gv)
 Apply the cross-product of this and a vector.
const GLVector4 unit () const
 Get the the unit vector of this.
GLVector4normalize ()
 Normalize this, makes this a unit vector, US spelling.
const T projection (const GLVector4 &in) const
 Get the projection of this and a vector.
GLVector4 orthogonalProjection (const GLVector4 &in) const
 Get the orthogonal projection of this and a vector.
GLVector4 vectorProjection (const GLVector4 &in) const
 Get the vector projection of this and a vector.
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
template<>
const GLVector4< GLfloat > operator/ (const GLfloat &v) const
template<>
const GLVector4< GLdouble > operator/ (const GLdouble &v) const

Public Attributes

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


Member Enumeration Documentation

template<typename T>
anonymous enum

Keep the dimensions as a defined enum.

Enumerator:
D 

Definition at line 889 of file GLVector.h.

00889 { D = 4 };


Constructor & Destructor Documentation

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

Create an uninitialised vector.

Definition at line 892 of file GLVector.h.

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

00893     { }

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

Create an initialised vector.

Definition at line 896 of file GLVector.h.

References mathglpp::GLVector4< T >::w, mathglpp::GLVector4< T >::x, mathglpp::GLVector4< T >::y, and mathglpp::GLVector4< T >::z.

00897     {   x = y = z = w = v; }

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

Create an initialised vector from values.

Definition at line 900 of file GLVector.h.

References mathglpp::GLVector4< T >::w, mathglpp::GLVector4< T >::x, mathglpp::GLVector4< T >::y, and mathglpp::GLVector4< T >::z.

00901     {   x = v1; y = v2; z = v3; w = v4; }

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

Copy a vector.

Definition at line 904 of file GLVector.h.

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

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

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

Create a vector from an array.

Definition at line 908 of file GLVector.h.

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

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

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

Default destructor.

Definition at line 912 of file GLVector.h.

00912 {}


Member Function Documentation

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

element by element initialiser

Definition at line 915 of file GLVector.h.

References mathglpp::GLVector4< T >::w, mathglpp::GLVector4< T >::x, mathglpp::GLVector4< T >::y, and mathglpp::GLVector4< T >::z.

00916     {   x = v1; y = v2; z = v3; w = v4;}

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

element by element accessor

Definition at line 919 of file GLVector.h.

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

00920     {   return val[ind]; }

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

implicit casting to a pointer

Definition at line 923 of file GLVector.h.

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

00924     {   return val; }

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

implicit casting to a const pointer

Definition at line 927 of file GLVector.h.

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

00928     {   return val; }

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

GL interface, glScale().

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

GL interface, glRotate().

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

GL interface, glTranslate().

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

GL interface, glVertex().

Definition at line 937 of file GLVector.h.

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

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

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

GL interface, glNormal().

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

copy values to a array

Definition at line 942 of file GLVector.h.

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

Referenced by mathglpp::GLCubicHermiteCurve4< T >::GLCubicHermiteCurve4().

00943     {   memmove(vec,val,D*sizeof(T)); }

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

Get the sum of this and a vector.

Definition at line 946 of file GLVector.h.

References mathglpp::GLVector4< T >::GLVector4(), mathglpp::GLVector4< T >::w, mathglpp::GLVector4< T >::x, mathglpp::GLVector4< T >::y, and mathglpp::GLVector4< T >::z.

00947     {
00948         return GLVector4(x+gv.x,y+gv.y,z+gv.z,w+gv.w);
00949     }

Here is the call graph for this function:

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

Get the difference of this and a vector.

Definition at line 952 of file GLVector.h.

References mathglpp::GLVector4< T >::GLVector4(), mathglpp::GLVector4< T >::w, mathglpp::GLVector4< T >::x, mathglpp::GLVector4< T >::y, and mathglpp::GLVector4< T >::z.

00953     {
00954         return GLVector4(x-gv.x,y-gv.y,z-gv.z,w-gv.w);
00955     }

Here is the call graph for this function:

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

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

Definition at line 958 of file GLVector.h.

References mathglpp::GLVector4< T >::GLVector4(), mathglpp::GLVector4< T >::w, mathglpp::GLVector4< T >::x, mathglpp::GLVector4< T >::y, and mathglpp::GLVector4< T >::z.

00959     {
00960         return GLVector4(x*gv.x,y*gv.y,z*gv.z,w*gv.w);
00961     }

Here is the call graph for this function:

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

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

Definition at line 964 of file GLVector.h.

References mathglpp::GLVector4< T >::GLVector4(), mathglpp::GLVector4< T >::w, mathglpp::GLVector4< T >::x, mathglpp::GLVector4< T >::y, and mathglpp::GLVector4< T >::z.

00965     {
00966         return GLVector4(x/gv.x,y/gv.y,z/gv.z,w/gv.w);
00967     }

Here is the call graph for this function:

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

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

Definition at line 970 of file GLVector.h.

References mathglpp::GLVector4< T >::GLVector4(), mathglpp::GLVector4< T >::w, mathglpp::GLVector4< T >::x, mathglpp::GLVector4< T >::y, and mathglpp::GLVector4< T >::z.

00971     {
00972         return GLVector4(x*v,y*v,z*v,w*v);
00973     }

Here is the call graph for this function:

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

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

Definition at line 977 of file GLVector.h.

References mathglpp::GLVector4< T >::GLVector4(), mathglpp::GLVector4< T >::w, mathglpp::GLVector4< T >::x, mathglpp::GLVector4< T >::y, and mathglpp::GLVector4< T >::z.

00978     {
00979         return GLVector4(x/v,y/v,z/v,w/v);
00980     }

Here is the call graph for this function:

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

Add a vector to this.

Definition at line 983 of file GLVector.h.

References mathglpp::GLVector4< T >::w, mathglpp::GLVector4< T >::x, mathglpp::GLVector4< T >::y, and mathglpp::GLVector4< T >::z.

00984     {
00985         x += gv.x;
00986         y += gv.y;
00987         z += gv.z;
00988         w += gv.w;
00989         return *this;
00990     }

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

Subtract a vector from this.

Definition at line 993 of file GLVector.h.

References mathglpp::GLVector4< T >::w, mathglpp::GLVector4< T >::x, mathglpp::GLVector4< T >::y, and mathglpp::GLVector4< T >::z.

00994     {
00995         x -= gv.x;
00996         y -= gv.y;
00997         z -= gv.z;
00998         w -= gv.w;
00999         return *this;
01000     }

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

Multiply this by a scalar.

Definition at line 1003 of file GLVector.h.

References mathglpp::GLVector4< T >::w, mathglpp::GLVector4< T >::x, mathglpp::GLVector4< T >::y, and mathglpp::GLVector4< T >::z.

01004     {
01005         x *= f;
01006         y *= f;
01007         z *= f;
01008         w *= f;
01009         return *this;
01010     }

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

Divide this by a scalar.

Definition at line 1013 of file GLVector.h.

References mathglpp::GLVector4< T >::w, mathglpp::GLVector4< T >::x, mathglpp::GLVector4< T >::y, and mathglpp::GLVector4< T >::z.

01014     {
01015         x /= f;
01016         y /= f;
01017         z /= f;
01018         w /= f;
01019         return *this;
01020     }

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

copy this from a vector

Definition at line 1023 of file GLVector.h.

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

01024     {   memmove(val,gv.val,D*sizeof(T)); return *this; }

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

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

Definition at line 1027 of file GLVector.h.

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

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

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

negate this

Definition at line 1031 of file GLVector.h.

References mathglpp::GLVector4< T >::GLVector4(), mathglpp::GLVector4< T >::w, mathglpp::GLVector4< T >::x, mathglpp::GLVector4< T >::y, and mathglpp::GLVector4< T >::z.

01032     {
01033         return GLVector4(-x,-y,-z,-w);
01034     }

Here is the call graph for this function:

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

Get the dot product of this and a vector.

Definition at line 1037 of file GLVector.h.

References mathglpp::GLVector4< T >::w, mathglpp::GLVector4< T >::x, mathglpp::GLVector4< T >::y, and mathglpp::GLVector4< T >::z.

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

01038     {   return x*gv.x + y*gv.y + z*gv.z + w*gv.w;  }

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

Get the length of this.

Definition at line 1041 of file GLVector.h.

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

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

01042     {   return sqrt(lengthSqr()); }

Here is the call graph for this function:

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

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

Definition at line 1045 of file GLVector.h.

References mathglpp::GLVector4< T >::w, mathglpp::GLVector4< T >::x, mathglpp::GLVector4< T >::y, and mathglpp::GLVector4< T >::z.

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

01046     {   return x*x + y*y + z*z + w*w;  }

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

Get the cross-product of this and a vector.

Definition at line 1049 of file GLVector.h.

References mathglpp::GLVector4< T >::GLVector4(), mathglpp::GLVector4< T >::w, mathglpp::GLVector4< T >::x, mathglpp::GLVector4< T >::y, and mathglpp::GLVector4< T >::z.

01050     {
01051         return GLVector4(y*gv.z-z*gv.y,z*gv.w-w*gv.z,w*gv.x-x*gv.w,x*gv.y-y*gv.x);
01052     }

Here is the call graph for this function:

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

Apply the cross-product of this and a vector.

Definition at line 1055 of file GLVector.h.

References mathglpp::GLVector4< T >::w, mathglpp::GLVector4< T >::x, mathglpp::GLVector4< T >::y, and mathglpp::GLVector4< T >::z.

01056     {
01057         T temp[] = { x, y, z, w };
01058 
01059         x = temp[1] * gv.z - temp[2] * gv.y;
01060         y = temp[2] * gv.w - temp[3] * gv.z;
01061         z = temp[3] * gv.x - temp[0] * gv.w;
01062         w = temp[0] * gv.y - temp[1] * gv.x;
01063 
01064         return *this;
01065     }

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

Get the the unit vector of this.

Definition at line 1068 of file GLVector.h.

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

01069     {
01070         return (*this)/length();
01071     }

Here is the call graph for this function:

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

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

Definition at line 1074 of file GLVector.h.

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

01075     {
01076         (*this)/=length();
01077         return *this;
01078     }

Here is the call graph for this function:

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

Get the projection of this and a vector.

Definition at line 1081 of file GLVector.h.

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

01082     {   return dot(in); }

Here is the call graph for this function:

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

Get the orthogonal projection of this and a vector.

Definition at line 1085 of file GLVector.h.

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

01086     {   return in - vectorProjection(in); }

Here is the call graph for this function:

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

Get the vector projection of this and a vector.

Definition at line 1089 of file GLVector.h.

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

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

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

Here is the call graph for this function:

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

Closest possible fit

Definition at line 227 of file GLVector.cpp.

References mathglpp::GLVector4< T >::w, mathglpp::GLVector4< T >::x, mathglpp::GLVector4< T >::y, and mathglpp::GLVector4< T >::z.

00228 {
00229     ::glVertex4s(x,y,z,w); 
00230 }


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