Changeset 1319
- Timestamp:
- Apr 30, 2012, 3:40:57 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/math/vector.cpp
r1315 r1319 419 419 } 420 420 421 template<> quat::Quat(mat4const &m)421 static void MatrixToQuat(quat &that, mat3 const &m) 422 422 { 423 423 /* See http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/christian.htm for a version with no branches */ … … 425 425 if (t > 0) 426 426 { 427 w = 0.5f * sqrtf(1.0f + t);428 float s = 0.25f / w;429 x = s * (m[2][1] - m[1][2]);430 y = s * (m[0][2] - m[2][0]);431 z = s * (m[1][0] - m[0][1]);427 that.w = 0.5f * sqrtf(1.0f + t); 428 float s = 0.25f / that.w; 429 that.x = s * (m[1][2] - m[2][1]); 430 that.y = s * (m[2][0] - m[0][2]); 431 that.z = s * (m[0][1] - m[1][0]); 432 432 } 433 433 else if (m[0][0] > m[1][1] && m[0][0] > m[2][2]) 434 434 { 435 x = 0.5f * sqrtf(1.0f + m[0][0] - m[1][1] - m[2][2]);436 float s = 0.25f / x;437 y = s * (m[1][0] + m[0][1]);438 z = s * (m[0][2] + m[2][0]);439 w = s * (m[2][1] - m[1][2]);435 that.x = 0.5f * sqrtf(1.0f + m[0][0] - m[1][1] - m[2][2]); 436 float s = 0.25f / that.x; 437 that.y = s * (m[0][1] + m[1][0]); 438 that.z = s * (m[2][0] + m[0][2]); 439 that.w = s * (m[1][2] - m[2][1]); 440 440 } 441 441 else if (m[1][1] > m[2][2]) 442 442 { 443 y = 0.5f * sqrtf(1.0f - m[0][0] + m[1][1] - m[2][2]);444 float s = 0.25f / y;445 x = s * (m[1][0] + m[0][1]);446 z = s * (m[2][1] + m[1][2]);447 w = s * (m[0][2] - m[2][0]);443 that.y = 0.5f * sqrtf(1.0f - m[0][0] + m[1][1] - m[2][2]); 444 float s = 0.25f / that.y; 445 that.x = s * (m[0][1] + m[1][0]); 446 that.z = s * (m[1][2] + m[2][1]); 447 that.w = s * (m[2][0] - m[0][2]); 448 448 } 449 449 else 450 450 { 451 z = 0.5f * sqrtf(1.0f - m[0][0] - m[1][1] + m[2][2]);452 float s = 0.25f / z;453 x = s * (m[0][2] + m[2][0]);454 y = s * (m[2][1] + m[1][2]);455 w = s * (m[1][0] - m[0][1]);451 that.z = 0.5f * sqrtf(1.0f - m[0][0] - m[1][1] + m[2][2]); 452 float s = 0.25f / that.z; 453 that.x = s * (m[2][0] + m[0][2]); 454 that.y = s * (m[1][2] + m[2][1]); 455 that.w = s * (m[0][1] - m[1][0]); 456 456 } 457 } 458 459 template<> quat::Quat(mat3 const &m) 460 { 461 MatrixToQuat(*this, m); 462 } 463 464 template<> quat::Quat(mat4 const &m) 465 { 466 MatrixToQuat(*this, mat3(m)); 457 467 } 458 468
Note: See TracChangeset
for help on using the changeset viewer.