mathglpp::GLVector3< T > Class Template Reference

#include <GLVector.h>

Collaboration diagram for mathglpp::GLVector3< T >:

Collaboration graph
[legend]
List of all members.

Detailed Description

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

a 3D vector class for OpenGL

Definition at line 501 of file GLVector.h.

Public Types

enum  { D = 3 }
typedef T value_type

Public Member Functions

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

Public Attributes

union {
   T   val [D]
   struct {
      T   x
      T   y
      T   z
   } 
}; 
 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 504 of file GLVector.h.

00504 { D = 3 };


Constructor & Destructor Documentation

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

Create an uninitialised vector.

Definition at line 508 of file GLVector.h.

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

00508 { }

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

Create an initialised vector.

Definition at line 511 of file GLVector.h.

00512     :x(v), y(v), z(v) { }

template<typename T>
mathglpp::GLVector3< T >::GLVector3 ( const T &  a,
const T &  b,
const T &  c 
) [inline]

Create an initialise vector.

Definition at line 515 of file GLVector.h.

00516     :x(a),y(b),z(c){}

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

Copy a vector.

Definition at line 519 of file GLVector.h.

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

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

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

Create a vector from an array.

Definition at line 523 of file GLVector.h.

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

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

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

Default destructor.

Definition at line 527 of file GLVector.h.

00527 {}


Member Function Documentation

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

element by element initialiser

Definition at line 530 of file GLVector.h.

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

00531     {   x = v1; y = v2; z = v3; }

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

element by element accessor

Definition at line 534 of file GLVector.h.

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

00535     {   return val[ind]; }

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

implicit casting to a pointer

Definition at line 538 of file GLVector.h.

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

00539     {   return val; }

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

implicit casting to a const pointer

Definition at line 542 of file GLVector.h.

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

00543     {   return val; }

template<typename T>
void mathglpp::GLVector3< T >::glScale (  )  const

GL interface, glScale().

template<typename T>
void mathglpp::GLVector3< T >::glRotate ( const T &  ang  )  const

GL interface, glRotate().

template<typename T>
void mathglpp::GLVector3< T >::glTranslate (  )  const

GL interface, glTranslate().

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

GL interface, glVertex().

Definition at line 552 of file GLVector.h.

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

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

template<typename T>
void mathglpp::GLVector3< T >::glNormal (  )  const

GL interface, glNormal().

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

copy values to a array

Definition at line 557 of file GLVector.h.

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

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

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

Get the sum of this and a vector.

Definition at line 561 of file GLVector.h.

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

00562     {
00563         return GLVector3(x+gv.x,y+gv.y,z+gv.z);
00564     }

Here is the call graph for this function:

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

Get the difference of this and a vector.

Definition at line 567 of file GLVector.h.

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

00568     {
00569         return GLVector3(x-gv.x,y-gv.y,z-gv.z);
00570     }

Here is the call graph for this function:

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

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

Definition at line 573 of file GLVector.h.

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

00574     {
00575         return GLVector3(x*gv.x,y*gv.y,z*gv.z);
00576     }

Here is the call graph for this function:

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

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

Definition at line 579 of file GLVector.h.

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

00580     {
00581         return GLVector3(x/gv.x,y/gv.y,z/gv.z);
00582     }

Here is the call graph for this function:

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

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

Definition at line 585 of file GLVector.h.

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

00586     {
00587         return GLVector3(x*v,y*v,z*v);
00588     }

Here is the call graph for this function:

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

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

Definition at line 592 of file GLVector.h.

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

00593     {
00594         return GLVector3(x/v,y/v,z/v);
00595     }

Here is the call graph for this function:

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

Add a vector to this.

Definition at line 598 of file GLVector.h.

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

00599     {
00600         x += gv.x;
00601         y += gv.y;
00602         z += gv.z;
00603         return *this;
00604     }

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

Subtract a vector from this.

Definition at line 607 of file GLVector.h.

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

00608     {
00609         x -= gv.x;
00610         y -= gv.y;
00611         z -= gv.z;
00612         return *this;
00613     }

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

Multiply this by a scalar.

Definition at line 616 of file GLVector.h.

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

00617     {
00618         x *= f;
00619         y *= f;
00620         z *= f;
00621         return *this;
00622     }

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

Divide this by a scalar.

Definition at line 625 of file GLVector.h.

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

00626     {
00627         x /= f;
00628         y /= f;
00629         z /= f;
00630         return *this;
00631     }

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

copy this from a vector

Definition at line 634 of file GLVector.h.

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

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

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

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

Definition at line 638 of file GLVector.h.

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

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

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

negate this

Definition at line 642 of file GLVector.h.

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

00643     {
00644         return GLVector3(-x,-y,-z);
00645     }

Here is the call graph for this function:

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

Get the dot product of this and a vector.

Definition at line 648 of file GLVector.h.

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

Referenced by mathglpp::GLPlane< T >::distanceToPoint(), mathglpp::GLPlane< T >::GLPlane(), mathglpp::GLPlane< T >::intersectionWithLine(), mathglpp::GLVector3< T >::orthogonalProjection(), mathglpp::GLPlane< T >::pointProjectionMatrix(), mathglpp::GLVector3< T >::projection(), mathglpp::GLPlane< T >::set(), and mathglpp::GLVector3< T >::vectorProjection().

00649     {   return x*gv.x + y*gv.y + z*gv.z;  }

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

Get the length of this.

Definition at line 652 of file GLVector.h.

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

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

00653     {   return sqrt(lengthSqr()); }

Here is the call graph for this function:

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

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

Definition at line 656 of file GLVector.h.

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

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

00657     {   return x*x + y*y + z*z;  }

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

Get the cross-product of this and a vector.

Definition at line 660 of file GLVector.h.

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

Referenced by mathglpp::GLPlane< T >::set().

00661     {
00662         return GLVector3(y*gv.z-z*gv.y,z*gv.x-x*gv.z,x*gv.y-y*gv.x);
00663     }

Here is the call graph for this function:

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

Apply the cross-product of this and a vector.

Definition at line 666 of file GLVector.h.

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

00667     {
00668         T temp[] = { x, y, z };
00669 
00670         x = temp[1] * gv.z - temp[2] * gv.y;
00671         y = temp[2] * gv.x - temp[0] * gv.z;
00672         z = temp[0] * gv.y - temp[1] * gv.x;
00673 
00674         return *this;
00675     }

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

Get the the unit vector of this.

Definition at line 678 of file GLVector.h.

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

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

00679     {
00680         return (*this)/length();
00681     }

Here is the call graph for this function:

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

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

Definition at line 684 of file GLVector.h.

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

Referenced by mathglpp::GLPlane< T >::GLPlane(), and mathglpp::GLPlane< T >::set().

00685     {
00686         (*this)/=length();
00687         return *this;
00688     }

Here is the call graph for this function:

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

Get the projection of this and a vector.

Definition at line 691 of file GLVector.h.

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

00692     {   return dot(in); }

Here is the call graph for this function:

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

Get the orthogonal projection of this and a vector.

Definition at line 695 of file GLVector.h.

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

00696     {   return in - (*this) * dot(in); }

Here is the call graph for this function:

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

Get the vector projection of this and a vector.

Definition at line 699 of file GLVector.h.

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

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

Here is the call graph for this function:

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

Closest possible fit

Definition at line 139 of file GLVector.cpp.

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

00140 {
00141     ::glVertex3s(x,y,z); 
00142 }


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