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

FXQuatd.h
1 /********************************************************************************
2 * *
3 * D o u b 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 FXQUATD_H
22 #define FXQUATD_H
23 
24 namespace FX {
25 
26 
28 class FXAPI FXQuatd {
29 public:
30  double x;
31  double y;
32  double z;
33  double w;
34 public:
35 
37  FXQuatd(){}
38 
40  FXQuatd(const FXQuatd& q):x(q.x),y(q.y),z(q.z),w(q.w){}
41 
43  FXQuatd(const FXdouble v[]):x(v[0]),y(v[1]),z(v[2]),w(v[3]){}
44 
46  FXQuatd(FXdouble xx,FXdouble yy,FXdouble zz,FXdouble ww):x(xx),y(yy),z(zz),w(ww){}
47 
49  FXQuatd(const FXVec3d& fr,const FXVec3d& to);
50 
52  FXQuatd(const FXVec3d& axis,FXdouble phi=0.0);
53 
55  FXQuatd(FXdouble roll,FXdouble pitch,FXdouble yaw);
56 
58  FXQuatd(const FXVec3d& ex,const FXVec3d& ey,const FXVec3d& ez);
59 
61  FXdouble& operator[](FXint i){return (&x)[i];}
62 
64  const FXdouble& operator[](FXint i) const {return (&x)[i];}
65 
67  FXQuatd& operator=(const FXQuatd& v){x=v.x;y=v.y;z=v.z;w=v.w;return *this;}
68 
70  FXQuatd& operator=(const FXdouble v[]){x=v[0];y=v[1];z=v[2];w=v[3];return *this;}
71 
73  FXQuatd& set(const FXQuatd& v){x=v.x;y=v.y;z=v.z;w=v.w;return *this;}
74 
76  FXQuatd& set(const FXdouble v[]){x=v[0];y=v[1];z=v[2];w=v[3];return *this;}
77 
79  FXQuatd& set(FXdouble xx,FXdouble yy,FXdouble zz,FXdouble ww){x=xx;y=yy;z=zz;w=ww;return *this;}
80 
82  FXQuatd& operator*=(FXdouble n){ return set(x*n,y*n,z*n,w*n); }
83  FXQuatd& operator/=(FXdouble n){ return set(x/n,y/n,z/n,w/n); }
84  FXQuatd& operator+=(const FXQuatd& v){ return set(x+v.x,y+v.y,z+v.z,w+v.w); }
85  FXQuatd& operator-=(const FXQuatd& v){ return set(x-v.x,y-v.y,z-v.z,w-v.w); }
86  FXQuatd& operator*=(const FXQuatd& 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  FXQuatd& operator/=(const FXQuatd& b){ return *this*=b.invert(); }
88 
90  operator FXdouble*(){return &x;}
91  operator const FXdouble*() const {return &x;}
92 
94  FXbool operator!() const {return x==0.0 && y==0.0 && z==0.0 && w==0.0; }
95 
97  FXQuatd operator+() const { return *this; }
98  FXQuatd operator-() const { return FXQuatd(-x,-y,-z,-w); }
99 
101  FXVec3d operator*(const FXVec3d& v) const;
102 
104  FXdouble length2() const { return x*x+y*y+z*z+w*w; }
105  FXdouble length() const { return Math::sqrt(length2()); }
106 
108  FXQuatd& adjust();
109 
111  void setAxisAngle(const FXVec3d& axis,FXdouble phi=0.0);
112 
114  void getAxisAngle(FXVec3d& axis,FXdouble& phi) const;
115 
117  void setRollPitchYaw(FXdouble roll,FXdouble pitch,FXdouble yaw);
118  void getRollPitchYaw(FXdouble& roll,FXdouble& pitch,FXdouble& yaw) const;
119 
121  void setYawPitchRoll(FXdouble yaw,FXdouble pitch,FXdouble roll);
122  void getYawPitchRoll(FXdouble& yaw,FXdouble& pitch,FXdouble& roll) const;
123 
125  void setRollYawPitch(FXdouble roll,FXdouble yaw,FXdouble pitch);
126  void getRollYawPitch(FXdouble& roll,FXdouble& yaw,FXdouble& pitch) const;
127 
129  void setPitchRollYaw(FXdouble pitch,FXdouble roll,FXdouble yaw);
130  void getPitchRollYaw(FXdouble& pitch,FXdouble& roll,FXdouble& yaw) const;
131 
133  void setPitchYawRoll(FXdouble pitch,FXdouble yaw,FXdouble roll);
134  void getPitchYawRoll(FXdouble& pitch,FXdouble& yaw,FXdouble& roll) const;
135 
137  void setYawRollPitch(FXdouble yaw,FXdouble roll,FXdouble pitch);
138  void getYawRollPitch(FXdouble& yaw,FXdouble& roll,FXdouble& pitch) const;
139 
141  void setAxes(const FXVec3d& ex,const FXVec3d& ey,const FXVec3d& ez);
142 
144  void getAxes(FXVec3d& ex,FXVec3d& ey,FXVec3d& ez) const;
145 
147  FXVec3d getXAxis() const;
148 
150  FXVec3d getYAxis() const;
151 
153  FXVec3d getZAxis() const;
154 
156  FXQuatd exp() const;
157 
159  FXQuatd log() const;
160 
162  FXQuatd pow(FXdouble t) const;
163 
165  FXQuatd invert() const;
166 
168  FXQuatd unitinvert() const;
169 
171  FXQuatd conj() const;
172 
175  };
176 
178 inline FXQuatd operator*(const FXQuatd& a,FXdouble n){return FXQuatd(a.x*n,a.y*n,a.z*n,a.w*n);}
179 inline FXQuatd operator*(FXdouble n,const FXQuatd& a){return FXQuatd(n*a.x,n*a.y,n*a.z,n*a.w);}
180 inline FXQuatd operator/(const FXQuatd& a,FXdouble n){return FXQuatd(a.x/n,a.y/n,a.z/n,a.w/n);}
181 inline FXQuatd operator/(FXdouble n,const FXQuatd& a){return FXQuatd(n/a.x,n/a.y,n/a.z,n/a.w);}
182 
184 inline FXQuatd operator*(const FXQuatd& a,const FXQuatd& b){ return FXQuatd(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 FXQuatd operator/(const FXQuatd& a,const FXQuatd& b){ return a*b.invert(); }
186 
188 inline FXQuatd operator+(const FXQuatd& a,const FXQuatd& b){ return FXQuatd(a.x+b.x,a.y+b.y,a.z+b.z,a.w+b.w); }
189 inline FXQuatd operator-(const FXQuatd& a,const FXQuatd& b){ return FXQuatd(a.x-b.x,a.y-b.y,a.z-b.z,a.w-b.w); }
190 
192 inline FXbool operator==(const FXQuatd& a,FXdouble n){return a.x==n && a.y==n && a.z==n && a.w==n;}
193 inline FXbool operator!=(const FXQuatd& a,FXdouble n){return a.x!=n || a.y!=n || a.z!=n || a.w!=n;}
194 inline FXbool operator==(FXdouble n,const FXQuatd& a){return n==a.x && n==a.y && n==a.z && n==a.w;}
195 inline FXbool operator!=(FXdouble n,const FXQuatd& a){return n!=a.x || n!=a.y || n!=a.z || n!=a.w;}
196 
198 inline FXbool operator==(const FXQuatd& a,const FXQuatd& b){ return a.x==b.x && a.y==b.y && a.z==b.z && a.w==b.w; }
199 inline FXbool operator!=(const FXQuatd& a,const FXQuatd& b){ return a.x!=b.x || a.y!=b.y || a.z!=b.z || a.w!=b.w; }
200 
201 
203 extern FXAPI FXQuatd arc(const FXVec3d& a,const FXVec3d& b);
204 
206 extern FXAPI FXQuatd lerp(const FXQuatd& u,const FXQuatd& v,FXdouble f);
207 
209 extern FXAPI FXQuatd lerpdot(const FXQuatd& u,const FXQuatd& v,FXdouble f);
210 
212 extern FXAPI FXStream& operator<<(FXStream& store,const FXQuatd& v);
213 
215 extern FXAPI FXStream& operator>>(FXStream& store,FXQuatd& v);
216 
217 }
218 
219 #endif

Copyright © 1997-2016 Jeroen van der Zijp