Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

quaternion.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 
00003   quaternion.h - A quaternion class
00004 
00005   GLUI User Interface Toolkit (LGPL)
00006   Copyright (c) 1998 Paul Rademacher
00007 
00008   ---------------------------------------------------------------------
00009 
00010   WWW:    http://sourceforge.net/projects/glui/
00011   Forums: http://sourceforge.net/forum/?group_id=92496
00012 
00013   This library is free software; you can redistribute it and/or
00014   modify it under the terms of the GNU Lesser General Public
00015   License as published by the Free Software Foundation; either
00016   version 2.1 of the License, or (at your option) any later version.
00017 
00018   This library is distributed in the hope that it will be useful,
00019   but WITHOUT ANY WARRANTY; without even the implied warranty of
00020   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00021   Lesser General Public License for more details.
00022 
00023   You should have received a copy of the GNU Lesser General Public
00024   License along with this library; if not, write to the Free Software
00025   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00026 
00027 *****************************************************************************/
00028 
00029 #ifndef GLUI_QUATERNION_H
00030 #define GLUI_QUATERNION_H
00031 
00032 #include "algebra3.h"
00033 #include <cstdio>
00034 
00035 /* this line defines a new type: pointer to a function which returns a */
00036 /* float and takes as argument a float */
00037 typedef float (*V_FCT_PTR)(float);
00038 
00039 /****************************************************************
00040  *                    Quaternion                                *
00041  ****************************************************************/
00042 
00043 class quat
00044 {
00045   /*protected: */
00046 public:
00047 
00048   vec3  v;  /* vector component */
00049   float s;  /* scalar component */
00050 
00051   /*public: */
00052   
00053   /* Constructors */
00054 
00055   quat();
00056   quat(float x, float y, float z, float w);
00057   quat(const vec3 &v, float s); 
00058   quat(float   s, const vec3 &v);
00059   quat(const float  *d);     /* copy from four-element float array  */
00060   quat(const double *f);     /* copy from four-element double array */
00061   quat(const quat   &q);     /* copy from other quat                */
00062 
00063   /* Assignment operators */
00064 
00065   quat  &operator  = (const quat &v);      /* assignment of a quat            */
00066   quat  &operator += (const quat &v);      /* incrementation by a quat        */
00067   quat  &operator -= (const quat &v);      /* decrementation by a quat        */
00068   quat  &operator *= (float d);      /* multiplication by a constant    */
00069   quat  &operator /= (float d);      /* division by a constant          */
00070   
00071   /* special functions */
00072   
00073   float  length() const;                   /* length of a quat                */
00074   float  length2() const;                  /* squared length of a quat        */
00075   quat  &normalize();                      /* normalize a quat                */
00076   quat  &apply(V_FCT_PTR fct);             /* apply a func. to each component */
00077   vec3   xform(const vec3 &v );            /* q*v*q-1                         */
00078   mat4   to_mat4() const;
00079   void   set_angle(float f);               /* set rot angle (degrees)         */
00080   void   scale_angle(float f);             /* scale rot angle (degrees)       */
00081   float  get_angle() const;                /* set rot angle (degrees)         */
00082   vec3   get_axis()  const;                /* get axis                        */
00083 
00084   void   print( FILE *file, const char *name ) const;  /* print to a file     */
00085 
00086         float &operator [] (int i);        /* indexing                        */
00087   const float &operator [] (int i) const;  /* indexing                        */
00088 
00089   void   set(float x, float y, float z);   /* set quat                        */
00090   void   set(const vec3 &v, float s);      /* set quat                        */
00091 
00092   /* friends */
00093 
00094   friend quat operator - (const quat &v);                   /* -q1            */
00095   friend quat operator + (const quat &a, const quat &b);    /* q1 + q2        */
00096   friend quat operator - (const quat &a, const quat &b);    /* q1 - q2        */
00097   friend quat operator * (const quat &a, float d);          /* q1 * 3.0       */
00098   friend quat operator * (float d, const quat &a);          /* 3.0 * q1       */
00099   friend quat operator * (const quat &a, const quat &b);    /* q1 * q2        */
00100   friend quat operator / (const quat &a, float d);          /* q1 / 3.0       */
00101   friend int operator == (const quat &a, const quat &b);    /* q1 == q2 ?     */
00102   friend int operator != (const quat &a, const quat &b);    /* q1 != q2 ?     */
00103   friend void swap(quat &a, quat &b);                       /* swap q1  &q2   */
00104   /*friend quat min(const quat &a, const quat &b);          -- min(q1, q2)    */
00105   /*friend quat max(const quat &a, const quat &b);          -- max(q1, q2)    */
00106   friend quat prod(const quat &a, const quat &b);          /* term by term mult*/
00107 }; 
00108 
00109 /* Utility functions */
00110 
00111 quat quat_identity();        /* Returns quaternion identity element */
00112 quat quat_slerp(const quat &from, const quat &to, float t);
00113 
00114 #endif

Generated on Fri Sep 15 17:51:57 2006 for GLUI by doxygen 1.3.6