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

FXQuatf.h
1 /********************************************************************************
2 * *
3 * 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 *
4 * *
5 *********************************************************************************
6 * Copyright (C) 1994,2017 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License as published by *
10 * the Free Software Foundation; either version 3 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public License *
19 * along with this program. If not, see <http://www.gnu.org/licenses/> *
20 ********************************************************************************/
21 #ifndef FXQUATF_H
22 #define FXQUATF_H
23 
24 namespace FX {
25 
26 
28 class FXAPI FXQuatf {
29 public:
30  FXfloat x;
31  FXfloat y;
32  FXfloat z;
33  FXfloat w;
34 public:
35 
37  FXQuatf(){}
38 
40  FXQuatf(const FXQuatf& q):x(q.x),y(q.y),z(q.z),w(q.w){}
41 
43  FXQuatf(const FXfloat v[]):x(v[0]),y(v[1]),z(v[2]),w(v[3]){}
44 
46  FXQuatf(FXfloat xx,FXfloat yy,FXfloat zz,FXfloat ww):x(xx),y(yy),z(zz),w(ww){}
47 
49  FXQuatf(const FXVec3f& fr,const FXVec3f& to);
50 
52  FXQuatf(const FXVec3f& axis,FXfloat phi=0.0f);
53 
55  FXQuatf(FXfloat roll,FXfloat pitch,FXfloat yaw);
56 
58  FXQuatf(const FXVec3f& ex,const FXVec3f& ey,const FXVec3f& ez);
59 
61  FXfloat& operator[](FXint i){return (&x)[i];}
62 
64  const FXfloat& operator[](FXint i) const {return (&x)[i];}
65 
67  FXQuatf& operator=(const FXQuatf& v){x=v.x;y=v.y;z=v.z;w=v.w;return *this;}
68 
70  FXQuatf& operator=(const FXfloat v[]){x=v[0];y=v[1];z=v[2];w=v[3];return *this;}
71 
73  FXQuatf& set(const FXQuatf& v){x=v.x;y=v.y;z=v.z;w=v.w;return *this;}
74 
76  FXQuatf& set(const FXfloat v[]){x=v[0];y=v[1];z=v[2];w=v[3];return *this;}
77 
79  FXQuatf& set(FXfloat xx,FXfloat yy,FXfloat zz,FXfloat ww){x=xx;y=yy;z=zz;w=ww;return *this;}
80 
82  FXQuatf& operator*=(FXfloat n){ return set(x*n,y*n,z*n,w*n); }
83  FXQuatf& operator/=(FXfloat n){ return set(x/n,y/n,z/n,w/n); }
84  FXQuatf& operator+=(const FXQuatf& v){ return set(x+v.x,y+v.y,z+v.z,w+v.w); }
85  FXQuatf& operator-=(const FXQuatf& v){ return set(x-v.x,y-v.y,z-v.z,w-v.w); }
86  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); }
87  FXQuatf& operator/=(const FXQuatf& b){ return *this*=b.invert(); }
88 
90  operator FXfloat*(){return &x;}
91  operator const FXfloat*() const {return &x;}
92 
94  FXbool operator!() const {return x==0.0f && y==0.0f && z==0.0f && w==0.0f; }
95 
97  FXQuatf operator+() const { return *this; }
98  FXQuatf operator-() const { return FXQuatf(-x,-y,-z,-w); }
99 
101  FXVec3f operator*(const FXVec3f& v) const;
102 
104  FXfloat length2() const { return x*x+y*y+z*z+w*w; }
105  FXfloat length() const { return Math::sqrt(length2()); }
106 
108  FXQuatf& adjust();
109 
111  void setAxisAngle(const FXVec3f& axis,FXfloat phi=0.0f);
112 
114  void getAxisAngle(FXVec3f& axis,FXfloat& phi) const;
115 
117  void setRollPitchYaw(FXfloat roll,FXfloat pitch,FXfloat yaw);
118  void getRollPitchYaw(FXfloat& roll,FXfloat& pitch,FXfloat& yaw) const;
119 
121  void setYawPitchRoll(FXfloat yaw,FXfloat pitch,FXfloat roll);
122  void getYawPitchRoll(FXfloat& yaw,FXfloat& pitch,FXfloat& roll) const;
123 
125  void setRollYawPitch(FXfloat roll,FXfloat yaw,FXfloat pitch);
126  void getRollYawPitch(FXfloat& roll,FXfloat& yaw,FXfloat& pitch) const;
127 
129  void setPitchRollYaw(FXfloat pitch,FXfloat roll,FXfloat yaw);
130  void getPitchRollYaw(FXfloat& pitch,FXfloat& roll,FXfloat& yaw) const;
131 
133  void setPitchYawRoll(FXfloat pitch,FXfloat yaw,FXfloat roll);
134  void getPitchYawRoll(FXfloat& pitch,FXfloat& yaw,FXfloat& roll) const;
135 
137  void setYawRollPitch(FXfloat yaw,FXfloat roll,FXfloat pitch);
138  void getYawRollPitch(FXfloat& yaw,FXfloat& roll,FXfloat& pitch) const;
139 
141  void setAxes(const FXVec3f& ex,const FXVec3f& ey,const FXVec3f& ez);
142 
144  void getAxes(FXVec3f& ex,FXVec3f& ey,FXVec3f& ez) const;
145 
147  FXVec3f getXAxis() const;
148 
150  FXVec3f getYAxis() const;
151 
153  FXVec3f getZAxis() const;
154 
156  FXQuatf exp() const;
157 
159  FXQuatf log() const;
160 
162  FXQuatf pow(FXfloat t) const;
163 
165  FXQuatf invert() const;
166 
168  FXQuatf unitinvert() const;
169 
171  FXQuatf conj() const;
172 
175  };
176 
178 inline FXQuatf operator*(const FXQuatf& a,FXfloat n){return FXQuatf(a.x*n,a.y*n,a.z*n,a.w*n);}
179 inline FXQuatf operator*(FXfloat n,const FXQuatf& a){return FXQuatf(n*a.x,n*a.y,n*a.z,n*a.w);}
180 inline FXQuatf operator/(const FXQuatf& a,FXfloat n){return FXQuatf(a.x/n,a.y/n,a.z/n,a.w/n);}
181 inline FXQuatf operator/(FXfloat n,const FXQuatf& a){return FXQuatf(n/a.x,n/a.y,n/a.z,n/a.w);}
182 
184 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); }
185 inline FXQuatf operator/(const FXQuatf& a,const FXQuatf& b){ return a*b.invert(); }
186 
188 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); }
189 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); }
190 
192 inline FXbool operator==(const FXQuatf& a,FXfloat n){return a.x==n && a.y==n && a.z==n && a.w==n;}
193 inline FXbool operator!=(const FXQuatf& a,FXfloat n){return a.x!=n || a.y!=n || a.z!=n || a.w!=n;}
194 inline FXbool operator==(FXfloat n,const FXQuatf& a){return n==a.x && n==a.y && n==a.z && n==a.w;}
195 inline FXbool operator!=(FXfloat n,const FXQuatf& a){return n!=a.x || n!=a.y || n!=a.z || n!=a.w;}
196 
198 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; }
199 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; }
200 
201 
203 extern FXAPI FXQuatf arc(const FXVec3f& a,const FXVec3f& b);
204 
206 extern FXAPI FXQuatf lerp(const FXQuatf& u,const FXQuatf& v,FXfloat f);
207 
209 extern FXAPI FXQuatf lerpdot(const FXQuatf& u,const FXQuatf& v,FXfloat f);
210 
212 extern FXAPI FXStream& operator<<(FXStream& store,const FXQuatf& v);
213 
215 extern FXAPI FXStream& operator>>(FXStream& store,FXQuatf& v);
216 
217 }
218 
219 #endif

Copyright © 1997-2016 Jeroen van der Zijp