Al's Programming Resource Homepage  Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

QUAT Class Reference

#include <quat.h>

List of all members.

Public Methods

 QUAT (float sx=0, float sy=0, float sz=0, float sw=1)
 ~QUAT ()
void Reset ()
void CopyQuat (QUAT q)
void Set (float sx, float sy, float sz, float sw)
void AxisAngleToQuat (VECTOR axis, float theta)
void EulerToQuat (float pitch, float yaw, float roll)
void NormaliseQuat ()
float MagnitudeQuat ()
void MultQuat (QUAT q)
void MatrixToQuat (float m[4][4])

Public Attributes

float x
float y
float z
float w


Constructor & Destructor Documentation

QUAT::QUAT float    sx = 0,
float    sy = 0,
float    sz = 0,
float    sw = 1
 

Definition at line 6 of file quat.cpp.

00007 :
00008     x(sx),
00009     y(sy),
00010     z(sz),
00011         w(sw)
00012 {
00013 }

QUAT::~QUAT  
 

Definition at line 15 of file quat.cpp.

00016 {
00017 }


Member Function Documentation

void QUAT::AxisAngleToQuat VECTOR    axis,
float    theta
 

Definition at line 35 of file quat.cpp.

References w, VECTOR::x, x, VECTOR::y, y, VECTOR::z, and z.

00036 {
00037         float halfTheta = theta * 0.5;
00038         float cosHalfTheta = cos(halfTheta);
00039         float sinHalfTheta = sin(halfTheta);
00040         x = axis.x * sinHalfTheta;
00041         y = axis.y * sinHalfTheta;
00042         z = axis.z * sinHalfTheta;
00043         w = cosHalfTheta;
00044 }

void QUAT::CopyQuat QUAT    q
 

Definition at line 27 of file quat.cpp.

References w, x, y, and z.

Referenced by MultQuat().

00028 {
00029     x = q.x;
00030     y = q.y;
00031     z = q.z;
00032     w = q.w;
00033 }

void QUAT::EulerToQuat float    pitch,
float    yaw,
float    roll
 

Definition at line 46 of file quat.cpp.

References w, x, y, and z.

Referenced by OBJECT::GetXUnit(), OBJECT::GetYUnit(), OBJECT::MoveX(), OBJECT::MoveY(), and OBJECT::Rotate().

00047 {
00048         float cr, cp, cy, sr, sp, sy, cpcy, spsy;  // calculate trig identities
00049         cr = cos(roll/2);
00050         cp = cos(pitch/2);
00051         cy = cos(yaw/2);
00052         sr = sin(roll/2);
00053         sp = sin(pitch/2);
00054         sy = sin(yaw/2);
00055         cpcy = cp * cy;
00056         spsy = sp * sy;
00057         w = cr * cpcy + sr * spsy;
00058         x = sr * cpcy - cr * spsy;
00059         y = cr * sp * cy + sr * cp * sy;
00060         z = cr * cp * sy - sr * sp * cy;
00061 }

float QUAT::MagnitudeQuat  
 

Definition at line 63 of file quat.cpp.

References w, x, y, and z.

Referenced by NormaliseQuat().

00064 {
00065       return( sqrt(w*w+x*x+y*y+z*z));
00066 }

void QUAT::MatrixToQuat float    m[4][4]
 

Definition at line 108 of file quat.cpp.

References w, x, y, and z.

00109 {
00110   float  tr, s, q[4];
00111   int    i, j, k;
00112 
00113   int nxt[3] = {1, 2, 0};
00114 
00115   tr = m[0][0] + m[1][1] + m[2][2];
00116 
00117   // check the diagonal
00118   if (tr > 0.0) {
00119     s = sqrt (tr + 1.0);
00120     w = s / 2.0;
00121     s = 0.5 / s;
00122     x = (m[1][2] - m[2][1]) * s;
00123     y = (m[2][0] - m[0][2]) * s;
00124     z = (m[0][1] - m[1][0]) * s;
00125 } 
00126 else 
00127 {        
00128      // diagonal is negative
00129           i = 0;
00130           if (m[1][1] > m[0][0]) i = 1;
00131          if (m[2][2] > m[i][i]) i = 2;
00132             j = nxt[i];
00133             k = nxt[j];
00134 
00135             s = sqrt ((m[i][i] - (m[j][j] + m[k][k])) + 1.0);
00136       
00137          q[i] = s * 0.5;
00138             
00139             if (s != 0.0) s = 0.5 / s;
00140 
00141         q[3] = (m[j][k] - m[k][j]) * s;
00142             q[j] = (m[i][j] + m[j][i]) * s;
00143             q[k] = (m[i][k] + m[k][i]) * s;
00144 
00145       x = q[0];
00146       y = q[1];
00147       z = q[2];
00148       w = q[3];
00149   }
00150 }

void QUAT::MultQuat QUAT    q
 

Definition at line 78 of file quat.cpp.

References CopyQuat(), VECTOR::CrossVector(), VECTOR::DotProduct(), w, x, VECTOR::x, y, VECTOR::y, z, and VECTOR::z.

Referenced by OBJECT::GetXUnit(), OBJECT::GetYUnit(), OBJECT::MoveX(), OBJECT::MoveY(), and OBJECT::Rotate().

00079 {
00080       QUAT q3;
00081       VECTOR vectorq1;
00082       VECTOR vectorq2;
00083       vectorq1.x = x;
00084       vectorq1.y = y;
00085       vectorq1.z = z;
00086       vectorq2.x = q.x;
00087       vectorq2.y = q.y;
00088       vectorq2.z = q.z;
00089 
00090       VECTOR tempvec1;
00091       VECTOR tempvec2;
00092       VECTOR tempvec3;
00093       tempvec1 = vectorq1;
00094       q3.w = (w*q.w) - tempvec1.DotProduct(vectorq2);
00095       tempvec1.CrossVector(vectorq2);
00096       tempvec2.x = w * q.x;
00097       tempvec2.y = w * q.y;
00098       tempvec2.z = w * q.z;
00099       tempvec3.x = q.w * x;
00100       tempvec3.y = q.w * y;
00101       tempvec3.z = q.w * z;
00102       q3.x = tempvec1.x + tempvec2.x + tempvec3.x;
00103       q3.y = tempvec1.y + tempvec2.y + tempvec3.y;
00104       q3.z = tempvec1.z + tempvec2.z + tempvec3.z;
00105       CopyQuat(q3);
00106 }

void QUAT::NormaliseQuat  
 

Definition at line 68 of file quat.cpp.

References MagnitudeQuat(), w, x, y, and z.

00069 {
00070       float Mag;
00071       Mag = MagnitudeQuat();
00072       w = w/Mag;
00073       x = x/Mag;
00074       y = y/Mag;
00075       z = z/Mag;
00076 }

void QUAT::Reset  
 

Definition at line 19 of file quat.cpp.

References w, x, y, and z.

Referenced by OBJECT::Reset(), LIGHT::Reset(), and CAMERA::Reset().

00020 {
00021     x = 0.0;
00022     y = 0.0;
00023     z = 0.0;
00024     w = 1.0;
00025 }

void QUAT::Set float    sx,
float    sy,
float    sz,
float    sw
[inline]
 

Definition at line 16 of file quat.h.

References w, x, y, and z.

00016 {x = sx, y = sy, z = sz, w = sw;}


Member Data Documentation

float QUAT::w
 

Definition at line 27 of file quat.h.

Referenced by AxisAngleToMatrix(), AxisAngleToQuat(), CopyQuat(), EulerToQuat(), EulerToQuat(), OBJECT::GetXUnit(), OBJECT::GetYUnit(), OBJECT::GetZUnit(), MagnitudeQuat(), MagnitudeQuat(), MATRIX::MatrixFromAxisAngle(), MatrixToQuat(), OBJECT::MoveX(), OBJECT::MoveY(), OBJECT::MoveZ(), MultQuat(), MultQuat(), NormaliseQuat(), NormaliseQuat(), MATRIX::QuatToMatrix(), QuatToMatrix(), Reset(), and Set().

float QUAT::x
 

Definition at line 24 of file quat.h.

Referenced by AxisAngleToMatrix(), AxisAngleToQuat(), CopyQuat(), EulerToQuat(), EulerToQuat(), OBJECT::GetXUnit(), OBJECT::GetYUnit(), OBJECT::GetZUnit(), MagnitudeQuat(), MagnitudeQuat(), MATRIX::MatrixFromAxisAngle(), MatrixToQuat(), OBJECT::MoveX(), OBJECT::MoveY(), OBJECT::MoveZ(), MultQuat(), MultQuat(), NormaliseQuat(), NormaliseQuat(), MATRIX::QuatToMatrix(), QuatToMatrix(), Reset(), and Set().

float QUAT::y
 

Definition at line 25 of file quat.h.

Referenced by AxisAngleToMatrix(), AxisAngleToQuat(), CopyQuat(), EulerToQuat(), EulerToQuat(), OBJECT::GetXUnit(), OBJECT::GetYUnit(), OBJECT::GetZUnit(), MagnitudeQuat(), MagnitudeQuat(), MATRIX::MatrixFromAxisAngle(), MatrixToQuat(), OBJECT::MoveX(), OBJECT::MoveY(), OBJECT::MoveZ(), MultQuat(), MultQuat(), NormaliseQuat(), NormaliseQuat(), MATRIX::QuatToMatrix(), QuatToMatrix(), Reset(), and Set().

float QUAT::z
 

Definition at line 26 of file quat.h.

Referenced by AxisAngleToMatrix(), AxisAngleToQuat(), CopyQuat(), EulerToQuat(), EulerToQuat(), OBJECT::GetXUnit(), OBJECT::GetYUnit(), OBJECT::GetZUnit(), MagnitudeQuat(), MagnitudeQuat(), MATRIX::MatrixFromAxisAngle(), MatrixToQuat(), OBJECT::MoveX(), OBJECT::MoveY(), OBJECT::MoveZ(), MultQuat(), MultQuat(), NormaliseQuat(), NormaliseQuat(), MATRIX::QuatToMatrix(), QuatToMatrix(), Reset(), and Set().


The documentation for this class was generated from the following files:
Generated on Fri Dec 23 05:20:42 2005 for Potentially Visible Sets by doxygen1.2.15