00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #pragma once
00014
00015 #include "GeomExport.h"
00016 #include "maxheap.h"
00017 #include "matrix3.h"
00018 #include "assert1.h"
00019
00020 #include <iosfwd>
00021
00022 class Quat;
00023 class AngAxis;
00024
00040 class AngAxis: public MaxHeapOperators {
00041 public:
00042 Point3 axis;
00043 float angle;
00044
00046 AngAxis() { }
00057 AngAxis(float x, float y, float z, float ang)
00058 { axis.x = x; axis.y = y; axis.z = z; angle = ang; }
00061 AngAxis(const Point3& axis,float angle) { this->axis=axis; this->angle=angle; }
00064 GEOMEXPORT AngAxis(const Quat &q);
00070 GEOMEXPORT AngAxis(const Matrix3& m);
00071
00083 AngAxis& Set(float x, float y, float z, float ang)
00084 {axis.x = x; axis.y = y; axis.z = z; angle = ang; return *this; }
00092 AngAxis& Set(const Point3& ax, float ang)
00093 {axis = ax; angle = ang; return *this; }
00100 GEOMEXPORT AngAxis& Set(const Quat& q);
00106 GEOMEXPORT AngAxis& Set(const Matrix3& m);
00107
00110 GEOMEXPORT int GetNumRevs();
00113 GEOMEXPORT void SetNumRevs(int num);
00114 };
00115
00144 class Quat: public MaxHeapOperators {
00145 public:
00146 float x,y,z,w;
00147
00148
00150 Quat(): x(0.0f),y(0.0f),z(0.0f),w(1.0f) {}
00153 Quat(float X, float Y, float Z, float W) { x = X; y = Y; z = Z; w = W; }
00156 Quat(double X, double Y, double Z, double W) {
00157 x = (float)X; y = (float)Y; z = (float)Z; w = (float)W;
00158 }
00161 Quat(const Quat& a) { x = a.x; y = a.y; z = a.z; w = a.w; }
00165 Quat(float af[4]) { x = af[0]; y = af[1]; z = af[2]; w = af[3]; }
00168 GEOMEXPORT Quat(const Matrix3& mat);
00170 GEOMEXPORT Quat(const AngAxis& aa);
00174 GEOMEXPORT Quat(const Point3& V, float W);
00175
00176
00179 float& operator[](int i) { return (&x)[i]; }
00182 const float& operator[](int i) const { return (&x)[i]; }
00183
00184 float Scalar() { return w; }
00185 Point3 Vector() { return Point3(x, y, z); }
00186
00187
00190 operator float*() { return(&x); }
00191
00192
00194 Quat operator-() const { return(Quat(-x,-y,-z,-w)); }
00197 Quat operator+() const { return *this; }
00198
00199
00201 GEOMEXPORT Quat Inverse() const;
00203 GEOMEXPORT Quat Conjugate() const;
00205 GEOMEXPORT Quat LogN() const;
00209 GEOMEXPORT Quat Exp() const;
00210
00211
00213 GEOMEXPORT Quat& operator-=(const Quat&);
00215 GEOMEXPORT Quat& operator+=(const Quat&);
00217 GEOMEXPORT Quat& operator*=(const Quat&);
00219 GEOMEXPORT Quat& operator*=(float);
00221 GEOMEXPORT Quat& operator/=(float);
00222
00223 Quat& Set(float X, float Y, float Z, float W)
00224 { x = X; y = Y; z = Z; w = W; return *this; }
00225 Quat& Set(double X, double Y, double Z, double W)
00226 { x = (float)X; y = (float)Y; z = (float)Z; w = (float)W;
00227 return *this; }
00228 GEOMEXPORT Quat& Set(const Matrix3& mat);
00229 GEOMEXPORT Quat& Set(const AngAxis& aa);
00230 Quat& Set(const Point3& V, float W)
00231 { x = V.x; y = V.y; z = V.z; w = W; return *this; }
00232 GEOMEXPORT Quat& SetEuler(float X, float Y, float Z);
00233 GEOMEXPORT Quat& Invert();
00234
00237 GEOMEXPORT Quat& MakeClosest(const Quat& qto);
00238
00239
00241 GEOMEXPORT int operator==(const Quat& a) const;
00242 GEOMEXPORT int Equals(const Quat& a, float epsilon = 1E-6f) const;
00243
00246 void Identity() { x = y = z = 0.0f; w = 1.0f; }
00249 GEOMEXPORT int IsIdentity() const;
00253 GEOMEXPORT void Normalize();
00266 GEOMEXPORT void MakeMatrix(Matrix3 &mat, bool flag=false) const;
00267 GEOMEXPORT void GetEuler(float *X, float *Y, float *Z) const;
00268
00269
00271 GEOMEXPORT Quat operator-(const Quat&) const;
00273 GEOMEXPORT Quat operator+(const Quat&) const;
00275 GEOMEXPORT Quat operator*(const Quat&) const;
00279 GEOMEXPORT Quat operator/(const Quat&) const;
00280 GEOMEXPORT float operator%(const Quat&) const;
00281 GEOMEXPORT Quat Plus(const Quat&) const;
00282 GEOMEXPORT Quat Minus(const Quat&) const;
00283 };
00284
00286 GEOMEXPORT Quat operator*(float, const Quat&);
00288 GEOMEXPORT Quat operator*(const Quat&, float);
00290 GEOMEXPORT Quat operator/(const Quat&, float);
00292 GEOMEXPORT Quat Inverse(const Quat& q);
00294 GEOMEXPORT Quat Conjugate(const Quat& q);
00296 GEOMEXPORT Quat LogN(const Quat& q);
00298 GEOMEXPORT Quat Exp(const Quat& q);
00302 GEOMEXPORT Quat Slerp(const Quat& p, const Quat& q, float t);
00305 GEOMEXPORT Quat LnDif(const Quat& p, const Quat& q);
00309 GEOMEXPORT Quat QCompA(const Quat& qprev,const Quat& q, const Quat& qnext);
00312 GEOMEXPORT Quat Squad(const Quat& p, const Quat& a, const Quat &b, const Quat& q, float t);
00315 GEOMEXPORT Quat qorthog(const Quat& p, const Point3& axis);
00316
00333 GEOMEXPORT Quat squadrev(
00334 float angle,
00335 const Point3& axis,
00336 const Quat& p,
00337 const Quat& a,
00338 const Quat& b,
00339 const Quat& q,
00340 float t
00341 );
00342
00345 GEOMEXPORT void RotateMatrix(Matrix3& mat, const Quat& q);
00348 GEOMEXPORT void PreRotateMatrix(Matrix3& mat, const Quat& q);
00351 GEOMEXPORT Quat QFromAngAxis(float ang, const Point3& axis);
00354 GEOMEXPORT void AngAxisFromQ(const Quat& q, float *ang, Point3& axis);
00357 GEOMEXPORT float QangAxis(const Quat& p, const Quat& q, Point3& axis);
00363 GEOMEXPORT void DecomposeMatrix(const Matrix3& mat, Point3& p, Quat& q, Point3& s);
00366 GEOMEXPORT Quat TransformQuat(const Matrix3 &m, const Quat&q );
00369 inline Quat IdentQuat() { return(Quat(0.0,0.0,0.0,1.0)); }
00370
00371
00372
00373
00374
00375
00380 GEOMEXPORT void QuatToEuler(Quat &q, float *ang);
00397 GEOMEXPORT void EulerToQuat(float *ang, Quat &q);
00398
00399 GEOMEXPORT std::ostream &operator<<(std::ostream&, const Quat&);
00400