Changeset 1807 for trunk/src/math/vector.cpp
 Timestamp:
 Aug 24, 2012, 12:51:48 PM (11 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/src/math/vector.cpp
r1804 r1807 487 487 } 488 488 489 template<> quat quat::slerp(quat QuatA, quat QuatB, float const &Scalar) 490 { 491 float magnitude = lol::sqrt(sqlength(QuatA) * sqlength(QuatB)); 492 //btAssert(magnitude > btScalar(0)); 493 494 float product = lol::dot(QuatA,QuatB) / magnitude; 495 if (product > 1.0f && product < 1.0f) 496 { 497 // Take care of long angle case see http://en.wikipedia.org/wiki/Slerp 498 const float sign = (product < 0.0f) ? 1.0f : 1.0f; 499 500 const float theta = lol::acos(sign * product); 501 const float s1 = lol::sin(sign * Scalar * theta); 502 const float d = 1.0f / lol::sin(theta); 503 const float s0 = lol::sin((1.0f  Scalar) * theta); 504 505 return quat( 506 (QuatA.w * s0 + QuatB.w * s1) * d, 507 (QuatA.x * s0 + QuatB.x * s1) * d, 508 (QuatA.y * s0 + QuatB.y * s1) * d, 509 (QuatA.z * s0 + QuatB.z * s1) * d); 510 } 511 else 512 { 513 return QuatA; 514 } 489 template<> quat slerp(quat const &qa, quat const &qb, float f) 490 { 491 float const magnitude = lol::sqrt(sqlength(qa) * sqlength(qb)); 492 float const product = lol::dot(qa, qb) / magnitude; 493 494 /* If quaternions are equal or opposite, there is no need 495 * to slerp anything, just return qa. */ 496 if (std::abs(product) >= 1.0f) 497 return qa; 498 499 float const sign = (product < 0.0f) ? 1.0f : 1.0f; 500 float const theta = lol::acos(sign * product); 501 float const s1 = lol::sin(sign * f * theta); 502 float const s0 = lol::sin((1.0f  f) * theta); 503 504 /* This is the same as 1/sin(theta) */ 505 float const d = 1.0f / lol::sqrt(1.f  product * product); 506 507 return qa * (s0 * d) + qb * (s1 * d); 515 508 } 516 509
Note: See TracChangeset
for help on using the changeset viewer.