source: golgotha/src/max_plugin/sdk_inc/quat.h @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 11 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
  • Property svn:keywords set to Id
File size: 4.3 KB
Line 
1/**********************************************************************
2 *<
3        FILE: quat.h
4
5        DESCRIPTION: Class definitions for Quat
6
7        CREATED BY: Dan Silva
8
9        HISTORY:
10
11 *>     Copyright (c) 1994, All Rights Reserved.
12 **********************************************************************/
13#ifndef _QUAT_H
14
15#define _QUAT_H
16
17#include "matrix3.h"
18
19class ostream;
20class Quat;
21
22class AngAxis {
23public:
24        Point3 axis;
25        float angle;
26
27        AngAxis() {}
28        AngAxis(const Point3& axis,float angle) {this->axis=axis;this->angle=angle;}   
29        DllExport AngAxis(const Quat &q);
30        DllExport int GetNumRevs();
31        DllExport void SetNumRevs(int num);
32        };
33
34class Quat {
35public:
36        float x,y,z,w;
37
38        // Constructors
39        Quat(){}
40        Quat(float X, float Y, float Z, float W)  { x = X; y = Y; z = Z; w = W; }
41        Quat(double X, double Y, double Z, double W)  {
42                x = (float)X; y = (float)Y; z = (float)Z; w = (float)W;
43                }
44        Quat(const Quat& a) { x = a.x; y = a.y; z = a.z; w = a.w; }
45        Quat(float af[4]) { x = af[0]; y = af[1]; z = af[2]; w = af[3]; }
46        DllExport Quat(const Matrix3& mat);
47        DllExport Quat(const AngAxis& aa);
48
49        // Access operators
50        float& operator[](int i) { return (&x)[i]; }     
51        const float& operator[](int i) const { return (&x)[i]; } 
52
53        // Conversion function
54        operator float*() { return(&x); }
55
56        // Unary operators
57        Quat operator-() const { return(Quat(-x,-y,-z,-w)); }
58        Quat operator+() const { return *this; }
59
60        // Assignment operators
61        DllExport Quat& operator-=(const Quat&);
62        DllExport Quat& operator+=(const Quat&);
63        DllExport Quat& operator*=(const Quat&);
64        DllExport Quat& operator*=(float);
65        DllExport Quat& operator/=(float);
66
67        DllExport Quat& MakeClosest(const Quat& qto);
68
69        // Comparison
70        DllExport int operator==(const Quat& a) const;
71
72        void Identity() { x = y = z = (float)0.0; w = (float) 1.0; }
73        DllExport int IsIdentity() const;
74        DllExport void Normalize();  // normalize
75        DllExport void MakeMatrix(Matrix3 &mat) const;
76
77        // Binary operators
78        DllExport Quat operator-(const Quat&) const;  //RB: Changed these to            // difference of two quaternions
79        DllExport Quat operator+(const Quat&) const;  // duplicate * and /                      // sum of two quaternions
80        DllExport Quat operator*(const Quat&) const;  // product of two quaternions
81        DllExport Quat operator/(const Quat&) const;  // ratio of two quaternions
82        };
83
84Quat DllExport operator*(float, const Quat&);   // multiply by scalar
85Quat DllExport operator*(const Quat&, float);   // multiply by scalar
86Quat DllExport operator/(const Quat&, float);   // divide by scalar
87Quat DllExport Inverse(const Quat& q);  // Inverse of quaternion (1/q)
88Quat DllExport Conjugate(const Quat& q);
89Quat DllExport LogN(const Quat& q);
90Quat DllExport Exp(const Quat& q);
91Quat DllExport Slerp(const Quat& p, const Quat& q, float t);
92Quat DllExport LnDif(const Quat& p, const Quat& q);
93Quat DllExport QCompA(const Quat& qprev,const Quat& q, const Quat& qnext);
94Quat DllExport Squad(const Quat& p, const Quat& a, const Quat &b, const Quat& q, float t);
95Quat DllExport qorthog(const Quat& p, const Point3& axis);
96Quat DllExport squadrev(
97                float angle,    // angle of rotation
98                const Point3& axis,     // the axis of rotation
99                const Quat& p,          // start quaternion
100                const Quat& a,          // start tangent quaternion
101                const Quat& b,          // end tangent quaternion
102                const Quat& q,          // end quaternion
103                float t                 // parameter, in range [0.0,1.0]
104                );
105
106void DllExport RotateMatrix(Matrix3& mat, const Quat& q);         
107void DllExport PreRotateMatrix(Matrix3& mat, const Quat& q);
108Quat DllExport QFromAngAxis(float ang, const Point3& axis);
109void DllExport AngAxisFromQ(const Quat& q, float *ang, Point3& axis);
110float DllExport QangAxis(const Quat& p, const Quat& q, Point3& axis);
111void DllExport DecomposeMatrix(const Matrix3& mat, Point3& p, Quat& q, Point3& s);
112Quat DllExport TransformQuat(const Matrix3 &m, const Quat&q );
113inline Quat IdentQuat() { return(Quat(0.0,0.0,0.0,1.0)); }
114
115// Assumes Euler angles are of the form:
116// RotateX(ang[0])
117// RotateY(ang[1])
118// RotateZ(ang[2])
119//
120void DllExport QuatToEuler(Quat &q, float *ang);
121void DllExport EulerToQuat(float *ang, Quat &q);
122
123ostream DllExport &operator<<(ostream&, const Quat&);
124
125#endif _QUAT_H
Note: See TracBrowser for help on using the repository browser.