Changeset 8560 in orxonox.OLD for branches/bsp_model
- Timestamp:
- Jun 17, 2006, 12:22:53 PM (18 years ago)
- Location:
- branches/bsp_model/src/lib
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/bsp_model/src/lib/graphics/importer/md3/md3_model.cc
r8558 r8560 25 25 26 26 #include "material.h" 27 #include "quaternion.h" 27 28 28 29 namespace md3 … … 266 267 */ 267 268 float* MD3Model::interpolateTransformation(MD3Tag* currFrameTag, MD3Tag* nextFrameTag, float frac) 268 {} 269 { 270 // interpolate position 271 Vector interpolatedPosition = currFrameTag->position * (1.0f - frac) + nextFrameTag->position * frac; 272 273 274 // interpolate rotation matrix 275 float currRot[4][4]; 276 float nextRot[4][4]; 277 float interpolatedMatrix[4][4]; 278 279 Quaternion currQuat(currFrameTag->matrix); currQuat.matrix(currRot); 280 Quaternion nextQuat(nextFrameTag->matrix); nextQuat.matrix(nextRot); 281 282 Quaternion interpolatedQuat = Quaternion::quatSlerp(currQuat, nextQuat, frac); interpolatedQuat.matrix(interpolatedMatrix); 283 284 // quaternion code is column based, so use transposed matrix when spitting out to gl 285 this->tmpMatrix[0] = interpolatedMatrix[0][0]; 286 this->tmpMatrix[4] = interpolatedMatrix[1][0]; 287 this->tmpMatrix[8] = interpolatedMatrix[2][0]; 288 this->tmpMatrix[12] = interpolatedPosition.x; 289 this->tmpMatrix[1] = interpolatedMatrix[0][1]; 290 this->tmpMatrix[5] = interpolatedMatrix[1][1]; 291 this->tmpMatrix[9] = interpolatedMatrix[2][1]; 292 this->tmpMatrix[13] = interpolatedPosition.y; 293 this->tmpMatrix[2] = interpolatedMatrix[0][2]; 294 this->tmpMatrix[6] = interpolatedMatrix[1][2]; 295 this->tmpMatrix[10]= interpolatedMatrix[2][2]; 296 this->tmpMatrix[14] = interpolatedPosition.z; 297 this->tmpMatrix[3] = 0.0f; 298 this->tmpMatrix[7] = 0.0f; 299 this->tmpMatrix[11]= 0.0f; 300 this->tmpMatrix[15] = 1.0f; 301 302 return this->tmpMatrix; 303 304 } 269 305 270 306 -
branches/bsp_model/src/lib/graphics/importer/md3/md3_model.h
r8558 r8560 62 62 sVec3D* tmpMesh; //!< a temporary mesh frame 63 63 MD3Normal* tmpNormal; //!< a temporary normals frame 64 float tmpMatrix[16]; //!< a temporary matrix 64 65 }; 65 66 -
branches/bsp_model/src/lib/math/quaternion.cc
r7348 r8560 133 133 134 134 135 135 136 /** 136 137 * @brief Slerps this QUaternion performs a smooth move. … … 298 299 } 299 300 301 302 /** 303 * Creates a quaternion from a 3x3 rotation matrix. 304 * @param mat The 3x3 source rotation matrix. 305 * @return The equivalent 4 float quaternion. 306 */ 307 Quaternion::Quaternion(float mat[3][3]) 308 { 309 int NXT[] = {1, 2, 0}; 310 float q[4]; 311 312 // check the diagonal 313 float tr = mat[0][0] + mat[1][1] + mat[2][2]; 314 if( tr > 0.0f) { 315 float s = (float)sqrtf(tr + 1.0f); 316 this->w = s * 0.5f; 317 s = 0.5f / s; 318 this->v.x = (mat[1][2] - mat[2][1]) * s; 319 this->v.y = (mat[2][0] - mat[0][2]) * s; 320 this->v.z = (mat[0][1] - mat[1][0]) * s; 321 } 322 else 323 { 324 // diagonal is negative 325 // get biggest diagonal element 326 int i = 0; 327 if (mat[1][1] > mat[0][0]) i = 1; 328 if (mat[2][2] > mat[i][i]) i = 2; 329 //setup index sequence 330 int j = NXT[i]; 331 int k = NXT[j]; 332 333 float s = (float)sqrtf((mat[i][i] - (mat[j][j] + mat[k][k])) + 1.0f); 334 335 q[i] = s * 0.5f; 336 337 if (s != 0.0f) s = 0.5f / s; 338 339 q[j] = (mat[i][j] + mat[j][i]) * s; 340 q[k] = (mat[i][k] + mat[k][i]) * s; 341 q[3] = (mat[j][k] - mat[k][j]) * s; 342 343 this->v.x = q[0]; 344 this->v.y = q[1]; 345 this->v.z = q[2]; 346 this->w = q[3]; 347 } 348 } 349 300 350 /** 301 351 * @brief outputs some nice formated debug information about this quaternion … … 314 364 PRINT(0)("angle = %f, axis: ax=%f, ay=%f, az=%f\n", this->getSpacialAxisAngle(), axis.x, axis.y, axis.z ); 315 365 } 366 367 368 369 370 371 -
branches/bsp_model/src/lib/math/quaternion.h
r7348 r8560 42 42 inline Quaternion (const Vector& v, float f) { this->w = f; this->v = v; } 43 43 Quaternion (float m[4][4]); 44 Quaternion (float m[3][3]); 44 45 /** turns a rotation along an axis into a Quaternion @param angle: the amount of radians to rotate @param axis: the axis to rotate around */ 45 46 inline Quaternion (float angle, const Vector& axis) { w = cos(angle/2.0); v = axis * sin(angle/2.0); } … … 118 119 119 120 121 // some helper functions 122 float* quaternionFromMatrix(float* mat); 123 124 120 125 #endif /* __QUATERNION_H_ */ 121 126
Note: See TracChangeset
for help on using the changeset viewer.