#include <ExQuaternion.h>
Membres publics | |
ExQuaternion () | |
ExQuaternion (float w, float x, float y, float z) | |
~ExQuaternion () | |
void | LoadIdentity (void) |
void | SetQuaternion (float w, float x, float y, float z) |
void | Normalize (void) |
void | Conjugate (void) |
float | GetMagnitude (void) |
void | SetEuler (float yaw, float pitch, float roll) |
void | CreateFromAxisAngle (float X, float Y, float Z, float degree) |
void | CreateMatrix (float *pMatrix) |
ExQuaternion | operator- (const ExQuaternion &Q) |
ExQuaternion | operator+ (const ExQuaternion &Q) |
ExQuaternion | operator * (const float scalar) |
ExQuaternion | operator * (const ExQuaternion &Q) |
Attributs Publics | |
float | qw |
float | qx |
float | qy |
float | qz |
Amis (friends) | |
std::ostream & | operator<< (std::ostream &s, const ExQuaternion &q) |
|
Définition à la ligne 26 du fichier ExQuaternion.cpp. Références SetQuaternion(). Référencé par operator+().
00027 { 00028 SetQuaternion(1,0,0,0); 00029 } |
|
Définition à la ligne 31 du fichier ExQuaternion.cpp. Références SetQuaternion().
00032 { 00033 SetQuaternion(w,x,y,z); 00034 } |
|
Définition à la ligne 36 du fichier ExQuaternion.cpp.
00037 { 00038 00039 } |
|
Définition à la ligne 52 du fichier ExQuaternion.cpp.
00053 { 00054 00055 } |
|
Définition à la ligne 93 du fichier ExQuaternion.cpp. Références PI, qw, qx, qy, et qz. Référencé par ExCModel::Draw(), ExCGroupEntity::Draw(), et ExCEntity::Draw().
00094 { 00095 // This function takes an angle and an axis of rotation, then converts 00096 // it to a quaternion. An example of an axis and angle is what we pass into 00097 // glRotatef(). That is an axis angle rotation. It is assumed an angle in 00098 // degrees is being passed in. Instead of using glRotatef(), we can now handle 00099 // the rotations our self. 00100 00101 // The equations for axis angle to quaternions are such: 00102 00103 // w = cos( theta / 2 ) 00104 // x = X * sin( theta / 2 ) 00105 // y = Y * sin( theta / 2 ) 00106 // z = Z * sin( theta / 2 ) 00107 00108 // First we want to convert the degrees to radians 00109 // since the angle is assumed to be in radians 00110 float angle = float((degree / 180.0f) * PI); 00111 00112 // Here we calculate the sin( theta / 2) once for optimization 00113 float result = (float)sin( angle / 2.0f ); 00114 00115 // Calcualte the w value by cos( theta / 2 ) 00116 qw = (float)cos( angle / 2.0f ); 00117 00118 // Calculate the x, y and z of the quaternion 00119 qx = float(X * result); 00120 qy = float(Y * result); 00121 qz = float(Z * result); 00122 } |
|
Définition à la ligne 124 du fichier ExQuaternion.cpp. Référencé par ExCModel::Draw(), ExCGroupEntity::Draw(), et ExCEntity::Draw().
00125 { 00126 // Make sure the matrix has allocated memory to store the rotation data 00127 if(!pMatrix) return; 00128 00129 // This function is a necessity when it comes to doing almost anything 00130 // with quaternions. Since we are working with OpenGL, which uses a 4x4 00131 // homogeneous matrix, we need to have a way to take our quaternion and 00132 // convert it to a rotation matrix to modify the current model view matrix. 00133 // We pass in a 4x4 matrix, which is a 1D array of 16 floats. This is how OpenGL 00134 // allows us to pass in a matrix to glMultMatrixf(), so we use a single dimensioned array. 00135 // After about 300 trees murdered and 20 packs of chalk depleted, the 00136 // mathematicians came up with these equations for a quaternion to matrix converion: 00137 // 00138 // ¦ 2 2 ¦ 00139 // ¦ 1 - (2y + 2z ) 2xy + 2zw 2xz - 2yw 0 ¦ 00140 // ¦ ¦ 00141 // ¦ 2 2 ¦ 00142 // M = ¦ 2xy - 2zw 1 - (2x + 2z ) 2zy + 2xw 0 ¦ 00143 // ¦ ¦ 00144 // ¦ 2 2 ¦ 00145 // ¦ 2xz + 2yw 2yz - 2xw 1 - (2x + 2y ) 0 ¦ 00146 // ¦ ¦ 00147 // ¦ ¦ 00148 // ¦ 0 0 0 1 | ¦ 00149 // ¦ ¦ 00150 // 00151 // This is of course a 4x4 matrix. Notice that a rotational matrix can just 00152 // be a 3x3 matrix, but since OpenGL uses a 4x4 matrix, we need to conform to the man. 00153 // Remember that the identity matrix of a 4x4 matrix has a diagonal of 1's, where 00154 // the rest of the indices are 0. That is where we get the 0's lining the sides, and 00155 // the 1 at the bottom-right corner. Since OpenGL matrices are row by column, we fill 00156 // in our matrix accordingly below. 00157 00158 // First row 00159 pMatrix[ 0] = 1.0f - 2.0f * ( qy * qy + qz * qz ); 00160 pMatrix[ 1] = 2.0f * ( qx * qy - qw * qz ); 00161 pMatrix[ 2] = 2.0f * ( qx * qz + qw * qy ); 00162 pMatrix[ 3] = 0.0f; 00163 00164 // Second row 00165 pMatrix[ 4] = 2.0f * ( qx * qy + qw * qz ); 00166 pMatrix[ 5] = 1.0f - 2.0f * ( qx * qx + qz * qz ); 00167 pMatrix[ 6] = 2.0f * ( qy * qz - qw * qx ); 00168 pMatrix[ 7] = 0.0f; 00169 00170 // Third row 00171 pMatrix[ 8] = 2.0f * ( qx * qz - qw * qy ); 00172 pMatrix[ 9] = 2.0f * ( qy * qz + qw * qx ); 00173 pMatrix[10] = 1.0f - 2.0f * ( qx * qx + qy * qy ); 00174 pMatrix[11] = 0.0f; 00175 00176 // Fourth row 00177 pMatrix[12] = 0; 00178 pMatrix[13] = 0; 00179 pMatrix[14] = 0; 00180 pMatrix[15] = 1.0f; 00181 00182 // Now pMatrix[] is a 4x4 homogeneous matrix that can be applied to an OpenGL Matrix 00183 } |
|
Définition à la ligne 63 du fichier ExQuaternion.cpp. Référencé par Normalize().
00064 {
00065 return(sqrt(qw*qw+qx*qx+qy*qy+qz*qz));
00066
00067 }
|
|
Définition à la ligne 57 du fichier ExQuaternion.cpp.
|
|
Définition à la ligne 68 du fichier ExQuaternion.cpp. Références GetMagnitude(), qw, qx, qy, et qz.
|
|
Définition à la ligne 188 du fichier ExQuaternion.cpp.
|
|
|
|
Définition à la ligne 197 du fichier ExQuaternion.cpp. Références ExQuaternion(), qw, qx, qy, et qz.
00198 { 00199 return ExQuaternion(qw+Q.qw,qx+Q.qx,qy+Q.qy,qz+Q.qz); 00200 } |
|
|
|
Définition à la ligne 78 du fichier ExQuaternion.cpp.
00079 { 00080 float cosY = cosf(yaw/2.0f); 00081 float sinY = sinf(yaw/2.0f); 00082 float cosP = cosf(pitch/2.0f); 00083 float sinP = sinf(pitch/2.0f); 00084 float cosR = cosf(roll/2.0f); 00085 float sinR = sinf(roll/2.0f); 00086 00087 qw=cosR*sinP*cosY+sinR*cosP*sinY; 00088 qx=cosR*cosP*sinY-sinR*sinP*cosY; 00089 qy=sinR*cosP*cosY-cosR*sinP*sinY; 00090 qz=cosR*cosP*cosY+sinR*sinP*sinY; 00091 00092 } |
|
Définition à la ligne 44 du fichier ExQuaternion.cpp. Référencé par ExQuaternion().
|
|
Définition à la ligne 205 du fichier ExQuaternion.cpp.
|
|
Définition à la ligne 55 du fichier ExQuaternion.h. Référencé par CreateFromAxisAngle(), CreateMatrix(), GetMagnitude(), GetMatrixFromQuaternion(), GetQuaternionFromEuler(), Normalize(), operator *(), operator+(), operator<<(), SetEuler(), et SetQuaternion(). |
|
Définition à la ligne 55 du fichier ExQuaternion.h. Référencé par CreateFromAxisAngle(), CreateMatrix(), GetAxisFromQuaternion(), GetMagnitude(), GetMatrixFromQuaternion(), GetQuaternionFromEuler(), LoadIdentity(), Normalize(), operator *(), operator+(), operator<<(), SetEuler(), et SetQuaternion(). |
|
Définition à la ligne 55 du fichier ExQuaternion.h. Référencé par CreateFromAxisAngle(), CreateMatrix(), GetAxisFromQuaternion(), GetMagnitude(), GetMatrixFromQuaternion(), GetQuaternionFromEuler(), LoadIdentity(), Normalize(), operator *(), operator+(), operator<<(), SetEuler(), et SetQuaternion(). |
|
Définition à la ligne 55 du fichier ExQuaternion.h. Référencé par CreateFromAxisAngle(), CreateMatrix(), GetAxisFromQuaternion(), GetMagnitude(), GetMatrixFromQuaternion(), GetQuaternionFromEuler(), LoadIdentity(), Normalize(), operator *(), operator+(), operator<<(), SetEuler(), et SetQuaternion(). |