Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

/home/jeroen/FOX/fox/fox-1.7.33/include/FXQuatf.h
00001 /********************************************************************************
00002 *                                                                               *
00003 *              S i n g l e - P r e c i s i o n  Q u a t e r n i o n             *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 1994,2012 by Jeroen van der Zijp.   All Rights Reserved.        *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or modify          *
00009 * it under the terms of the GNU Lesser General Public License as published by   *
00010 * the Free Software Foundation; either version 3 of the License, or             *
00011 * (at your option) any later version.                                           *
00012 *                                                                               *
00013 * This library is distributed in the hope that it will be useful,               *
00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                 *
00016 * GNU Lesser General Public License for more details.                           *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public License      *
00019 * along with this program.  If not, see <http://www.gnu.org/licenses/>          *
00020 ********************************************************************************/
00021 #ifndef FXQUATF_H
00022 #define FXQUATF_H
00023 
00024 
00025 namespace FX {
00026 
00027 
00029 class FXAPI FXQuatf {
00030 public:
00031   FXfloat x;
00032   FXfloat y;
00033   FXfloat z;
00034   FXfloat w;
00035 public:
00036 
00038   FXQuatf(){}
00039 
00041   FXQuatf(const FXQuatf& q):x(q.x),y(q.y),z(q.z),w(q.w){}
00042 
00044   FXQuatf(const FXfloat v[]):x(v[0]),y(v[1]),z(v[2]),w(v[3]){}
00045 
00047   FXQuatf(FXfloat xx,FXfloat yy,FXfloat zz,FXfloat ww):x(xx),y(yy),z(zz),w(ww){}
00048 
00050   FXQuatf(const FXVec3f& fr,const FXVec3f& to);
00051 
00053   FXQuatf(const FXVec3f& axis,FXfloat phi=0.0f);
00054 
00056   FXQuatf(FXfloat roll,FXfloat pitch,FXfloat yaw);
00057 
00059   FXQuatf(const FXVec3f& ex,const FXVec3f& ey,const FXVec3f& ez);
00060 
00062   FXfloat& operator[](FXint i){return (&x)[i];}
00063 
00065   const FXfloat& operator[](FXint i) const {return (&x)[i];}
00066 
00068   FXQuatf& operator=(const FXQuatf& v){x=v.x;y=v.y;z=v.z;w=v.w;return *this;}
00069 
00071   FXQuatf& operator=(const FXfloat v[]){x=v[0];y=v[1];z=v[2];w=v[3];return *this;}
00072 
00074   FXQuatf& set(const FXQuatf& v){x=v.x;y=v.y;z=v.z;w=v.w;return *this;}
00075 
00077   FXQuatf& set(const FXfloat v[]){x=v[0];y=v[1];z=v[2];w=v[3];return *this;}
00078 
00080   FXQuatf& set(FXfloat xx,FXfloat yy,FXfloat zz,FXfloat ww){x=xx;y=yy;z=zz;w=ww;return *this;}
00081 
00083   FXQuatf& operator*=(FXfloat n){ return set(x*n,y*n,z*n,w*n); }
00084   FXQuatf& operator/=(FXfloat n){ return set(x/n,y/n,z/n,w/n); }
00085   FXQuatf& operator+=(const FXQuatf& v){ return set(x+v.x,y+v.y,z+v.z,w+v.w); }
00086   FXQuatf& operator-=(const FXQuatf& v){ return set(x-v.x,y-v.y,z-v.z,w-v.w); }
00087   FXQuatf& operator*=(const FXQuatf& b){ return set(w*b.x+x*b.w+y*b.z-z*b.y, w*b.y+y*b.w+z*b.x-x*b.z, w*b.z+z*b.w+x*b.y-y*b.x, w*b.w-x*b.x-y*b.y-z*b.z); }
00088   FXQuatf& operator/=(const FXQuatf& b){ return *this*=b.invert(); }
00089 
00091   operator FXfloat*(){return &x;}
00092   operator const FXfloat*() const {return &x;}
00093 
00095   FXbool operator!() const {return x==0.0f && y==0.0f && z==0.0f && w==0.0f; }
00096 
00098   FXQuatf operator+() const { return *this; }
00099   FXQuatf operator-() const { return FXQuatf(-x,-y,-z,-w); }
00100 
00102   FXfloat length2() const { return x*x+y*y+z*z+w*w; }
00103   FXfloat length() const { return sqrtf(length2()); }
00104 
00106   FXQuatf& adjust();
00107 
00109   void setAxisAngle(const FXVec3f& axis,FXfloat phi=0.0f);
00110 
00112   void getAxisAngle(FXVec3f& axis,FXfloat& phi) const;
00113 
00115   void setRollPitchYaw(FXfloat roll,FXfloat pitch,FXfloat yaw);
00116   void getRollPitchYaw(FXfloat& roll,FXfloat& pitch,FXfloat& yaw) const;
00117 
00119   void setYawPitchRoll(FXfloat yaw,FXfloat pitch,FXfloat roll);
00120   void getYawPitchRoll(FXfloat& yaw,FXfloat& pitch,FXfloat& roll) const;
00121 
00123   void setRollYawPitch(FXfloat roll,FXfloat yaw,FXfloat pitch);
00124   void getRollYawPitch(FXfloat& roll,FXfloat& yaw,FXfloat& pitch) const;
00125 
00127   void setPitchRollYaw(FXfloat pitch,FXfloat roll,FXfloat yaw);
00128   void getPitchRollYaw(FXfloat& pitch,FXfloat& roll,FXfloat& yaw) const;
00129 
00131   void setPitchYawRoll(FXfloat pitch,FXfloat yaw,FXfloat roll);
00132   void getPitchYawRoll(FXfloat& pitch,FXfloat& yaw,FXfloat& roll) const;
00133 
00135   void setYawRollPitch(FXfloat yaw,FXfloat roll,FXfloat pitch);
00136   void getYawRollPitch(FXfloat& yaw,FXfloat& roll,FXfloat& pitch) const;
00137 
00139   void setAxes(const FXVec3f& ex,const FXVec3f& ey,const FXVec3f& ez);
00140 
00142   void getAxes(FXVec3f& ex,FXVec3f& ey,FXVec3f& ez) const;
00143 
00145   FXVec3f getXAxis() const;
00146 
00148   FXVec3f getYAxis() const;
00149 
00151   FXVec3f getZAxis() const;
00152 
00154   FXQuatf exp() const;
00155 
00157   FXQuatf log() const;
00158 
00160   FXQuatf pow(FXfloat t) const;
00161 
00163   FXQuatf invert() const;
00164 
00166   FXQuatf unitinvert() const;
00167 
00169   FXQuatf conj() const;
00170 
00172   FXVec3f operator*(const FXVec3f& v) const;
00173 
00175  ~FXQuatf(){}
00176   };
00177 
00179 inline FXQuatf operator*(const FXQuatf& a,FXfloat n){return FXQuatf(a.x*n,a.y*n,a.z*n,a.w*n);}
00180 inline FXQuatf operator*(FXfloat n,const FXQuatf& a){return FXQuatf(n*a.x,n*a.y,n*a.z,n*a.w);}
00181 inline FXQuatf operator/(const FXQuatf& a,FXfloat n){return FXQuatf(a.x/n,a.y/n,a.z/n,a.w/n);}
00182 inline FXQuatf operator/(FXfloat n,const FXQuatf& a){return FXQuatf(n/a.x,n/a.y,n/a.z,n/a.w);}
00183 
00185 inline FXQuatf operator*(const FXQuatf& a,const FXQuatf& b){ return FXQuatf(a.w*b.x+a.x*b.w+a.y*b.z-a.z*b.y, a.w*b.y+a.y*b.w+a.z*b.x-a.x*b.z, a.w*b.z+a.z*b.w+a.x*b.y-a.y*b.x, a.w*b.w-a.x*b.x-a.y*b.y-a.z*b.z); }
00186 inline FXQuatf operator/(const FXQuatf& a,const FXQuatf& b){ return a*b.invert(); }
00187 
00189 inline FXQuatf operator+(const FXQuatf& a,const FXQuatf& b){ return FXQuatf(a.x+b.x,a.y+b.y,a.z+b.z,a.w+b.w); }
00190 inline FXQuatf operator-(const FXQuatf& a,const FXQuatf& b){ return FXQuatf(a.x-b.x,a.y-b.y,a.z-b.z,a.w-b.w); }
00191 
00193 inline FXbool operator==(const FXQuatf& a,FXfloat n){return a.x==n && a.y==n && a.z==n && a.w==n;}
00194 inline FXbool operator!=(const FXQuatf& a,FXfloat n){return a.x!=n || a.y!=n || a.z!=n || a.w!=n;}
00195 inline FXbool operator==(FXfloat n,const FXQuatf& a){return n==a.x && n==a.y && n==a.z && n==a.w;}
00196 inline FXbool operator!=(FXfloat n,const FXQuatf& a){return n!=a.x || n!=a.y || n!=a.z || n!=a.w;}
00197 
00199 inline FXbool operator==(const FXQuatf& a,const FXQuatf& b){ return a.x==b.x && a.y==b.y && a.z==b.z && a.w==b.w; }
00200 inline FXbool operator!=(const FXQuatf& a,const FXQuatf& b){ return a.x!=b.x || a.y!=b.y || a.z!=b.z || a.w!=b.w; }
00201 
00202 
00204 extern FXAPI FXQuatf arc(const FXVec3f& a,const FXVec3f& b);
00205 
00207 extern FXAPI FXQuatf lerp(const FXQuatf& u,const FXQuatf& v,FXfloat f);
00208 
00210 extern FXAPI FXQuatf lerpdot(const FXQuatf& u,const FXQuatf& v,FXfloat f);
00211 
00213 extern FXAPI FXStream& operator<<(FXStream& store,const FXQuatf& v);
00214 
00216 extern FXAPI FXStream& operator>>(FXStream& store,FXQuatf& v);
00217 
00218 }
00219 
00220 #endif

Copyright © 1997-2011 Jeroen van der Zijp