Changeset 1799
 Timestamp:
 Aug 23, 2012, 5:51:20 PM (7 years ago)
 Location:
 trunk/src
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

trunk/src/lol/math/vector.h
r1796 r1799 935 935 static Quat<T> rotate(T angle, T x, T y, T z); 936 936 static Quat<T> rotate(T angle, Vec3<T> const &v); 937 static Quat<T> slerp(Quat<T> QuatA,Quat<T> QuatB, float const &Scalar); 937 938 938 939 /* Convert from Euler angles. The axes in fromeuler_xyx are 
trunk/src/math/vector.cpp
r1513 r1799 485 485 { 486 486 return quat::rotate(angle, vec3(x, y, z)); 487 } 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) 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 } 487 515 } 488 516
Note: See TracChangeset
for help on using the changeset viewer.