include/quat.h

Go to the documentation of this file.
00001 #ifndef QUAT_H
00002 
00003 #include <cmath>
00004 #include <GL/gl.h>
00005 #include <GL/glu.h>
00006 #include <iostream>
00007 #include <cassert>
00008 #include <fstream>
00009 #include "settings.h"
00010 #include "globals.h"
00011 
00012 using namespace std;
00013 
00014 class VERTEX
00015 {
00016 private:
00017         //buffer for float[3] conversions
00018         float float3[3];
00019         
00020 public:
00021         float x;
00022         float y;
00023         float z;
00024         VERTEX operator+ (VERTEX v);
00025         VERTEX operator- (VERTEX v);
00026         VERTEX();
00027 
00028         float len();
00029         VERTEX normalize();
00030         VERTEX cross(VERTEX b);
00031         void Scale(float scalar);
00032         VERTEX ScaleR(float scalar);
00033         float dot(VERTEX b);
00034         void Set(float nx, float ny, float nz);
00035         void Set(float * f3);
00036         VERTEX InvertR();
00037         float * v3();
00038         void zero();
00039         bool equals(VERTEX other);
00040 
00041         inline void flabs() {if (x < 0) x = -x; if (y < 0) y = -y; if (z < 0) z = -z;}
00042 
00043         inline float v(int i) {if (i == 2) return z; if (i == 1) return y; return x;}
00044 
00045         void DebugPrint() {DebugPrint(cout);}
00046         void DebugPrint(ostream & out);
00047 
00048         VERTEX interpolatewith(VERTEX other, float percent);
00049         
00050         bool nan();
00051 };
00052 
00053 class VERTEXD
00054 {
00055 private:
00056         //buffer for double[3] conversions
00057         double double3[3];
00058         
00059 public:
00060         double x;
00061         double y;
00062         double z;
00063         VERTEXD operator+ (VERTEXD v);
00064         VERTEXD operator- (VERTEXD v);
00065         VERTEXD();
00066         VERTEXD(VERTEX other);
00067         VERTEXD& operator= (const VERTEX &other);
00068 
00069         double len();
00070         VERTEXD normalize();
00071         VERTEXD cross(VERTEXD b);
00072         void Scale(double scalar);
00073         VERTEXD ScaleR(double scalar);
00074         double dot(VERTEXD b);
00075         void Set(double nx, double ny, double nz);
00076         void Set(double * f3);
00077         void Set(float * f3);
00078         VERTEXD InvertR();
00079         double * v3();
00080         void zero();
00081 
00082         void DebugPrint();
00083 
00084         VERTEXD interpolatewith(VERTEXD other, double percent);
00085         
00086         bool nan();
00087 };
00088 
00089 class MATRIX3
00090 {
00091 public:
00092         void ProjectionMatrix(VERTEX normal);
00093         VERTEX Multiply(VERTEX vert);
00094 //private:
00095         VERTEX row[3];
00096 };
00097 
00098 class QUATERNION
00099 {
00100 private:
00101         bool cachematvalid;
00102         float cachemat[16];
00103         
00104 public:
00105         //the 4 vectors we need to represent the quaternion
00106         float w;
00107         float x;
00108         float y;
00109         float z;
00110 
00111         QUATERNION();                   //the constructor calls loadmultident
00112         void LoadMultIdent();   //load the [1,(0,0,0)] quaternion
00113         float Norm();                   //return the magnitude of the quaternion
00114         void Normalize();               //normalize the quaternion
00115         void GetMat(float * destmat);   //convert to a matrix and store in (float) destmat[16]
00116         void GetMat(GLdouble * destmat);        //convert to a matrix and store in (gldouble) destmat[16]
00117         void GetAxisAngle(float * aangle);      //convert to axis angle form and store in (float) aangle[4] (a,x,y,z)
00118         void Multiply(QUATERNION quat2);        //multiply this quaternion by quat2
00119         void PostMultiply(QUATERNION quat2);    //multiply quat2 by this quaternion
00120         void SetAxisAngle(float a, float ax, float ay, float az);
00121         void Rotate(float a, float ax, float ay, float az);
00122         void SetEuler(float a, float b, float c);
00123         QUATERNION ReturnConjugate();
00124         void LookAt(float eyeX, float eyeY, float eyeZ, float centerX, float centerY, 
00125                    float centerZ, float upX, float upY, float upZ);
00126         void SetMat(float * m1);
00127         VERTEX RotateVec(VERTEX vec);
00128         float GetAngleBetween(QUATERNION quat2);
00129         VERTEX GetEuler();
00130         //spherical linear interpolation between this quat and another quat
00131         QUATERNION Slerp(QUATERNION quat2, float t);
00132         QUATERNION QuatSlerp(QUATERNION quat2, float t);
00133         QUATERNION Add(QUATERNION quat2);
00134         QUATERNION MultScalar(float scalar);
00135         void DebugPrint();
00136         VERTEX RelativeMove(VERTEX input);
00137 
00138         QUATERNION operator*(const QUATERNION &quat2 ); //multiply override
00139 };
00140 
00141 //axis-aligned bounding box
00142 class AABB
00143 {
00144 private:
00145         VERTEX pos;
00146         VERTEX center;
00147         VERTEX size;
00148 
00149         float fabs(float num) {if (num >= 0) return num; else return -num;}
00150 
00151 public:
00152         void SetFromCorners(VERTEX c1, VERTEX c2);
00153         bool IntersectRay(VERTEX orig, VERTEX d);
00154         bool IntersectSegment(VERTEX orig, VERTEX d, float seglen);
00155         bool IntersectAABB(AABB & other);
00156 
00157         VERTEX GetPos() {return pos;}
00158         VERTEX GetSize() {return size;}
00159         VERTEX GetCenter() {return center;}
00160         
00161         void DebugPrint();
00162         
00163         void GetVerts(VERTEX * eightverts);
00164 };
00165 
00166 #define QUAT_H
00167 #endif

Generated on Thu Oct 19 04:05:47 2006 by  doxygen 1.4.6