Scalar type interpolation (for doubles, floats, etc...) | |
| template<class T, typename U> void | lerp (T &result, const U &lerp, const T &a, const T &b) |
| Linear Interpolation between number [a] and [b]. More... | |
Quaternion Interpolation | |
| template<typename DATA_TYPE> Quat< DATA_TYPE > & | slerp (Quat< DATA_TYPE > &result, const DATA_TYPE t, const Quat< DATA_TYPE > &from, const Quat< DATA_TYPE > &to, bool adjustSign=true) |
| spherical linear interpolation between two rotation quaternions. More... | |
| template<typename DATA_TYPE> Quat< DATA_TYPE > & | lerp (Quat< DATA_TYPE > &result, const DATA_TYPE t, const Quat< DATA_TYPE > &from, const Quat< DATA_TYPE > &to) |
| linear interpolation between two quaternions. More... | |
Vector Interpolation | |
| template<typename DATA_TYPE, unsigned SIZE> VecBase< DATA_TYPE, SIZE > & | lerp (VecBase< DATA_TYPE, SIZE > &result, const DATA_TYPE &lerpVal, const VecBase< DATA_TYPE, SIZE > &from, const VecBase< DATA_TYPE, SIZE > &to) |
| Linearly interpolates between to vectors. More... | |
|
||||||||||||||||||||||||
|
linear interpolation between two quaternions. t is a value between 0 and 1 that interpolates between from and to.
Definition at line 583 of file QuatOps.h.
00584 {
00585 // just an alias to match q
00586 const Quat<DATA_TYPE>& p = from;
00587
00588 // calc cosine theta
00589 DATA_TYPE cosom = dot( from, to );
00590
00591 // adjust signs (if necessary)
00592 Quat<DATA_TYPE> q;
00593 if (cosom < (DATA_TYPE)0.0)
00594 {
00595 q[0] = -to[0]; // Reverse all signs
00596 q[1] = -to[1];
00597 q[2] = -to[2];
00598 q[3] = -to[3];
00599 }
00600 else
00601 {
00602 q = to;
00603 }
00604
00605 // do linear interp
00606 DATA_TYPE sclp, sclq;
00607 sclp = (DATA_TYPE)1.0 - t;
00608 sclq = t;
00609
00610 result[Xelt] = sclp * p[Xelt] + sclq * q[Xelt];
00611 result[Yelt] = sclp * p[Yelt] + sclq * q[Yelt];
00612 result[Zelt] = sclp * p[Zelt] + sclq * q[Zelt];
00613 result[Welt] = sclp * p[Welt] + sclq * q[Welt];
00614 return result;
00615 }
|
|
||||||||||||||||||||||||
|
Linearly interpolates between to vectors.
Definition at line 437 of file VecOps.h.
00441 {
00443 for (unsigned int x = 0; x < SIZE; ++x)
00444 {
00445 Math::lerp( result[x], lerpVal, from[x], to[x] );
00446 }
00447 return result;
00448 }
|
|
||||||||||||||||||||||||
|
Linear Interpolation between number [a] and [b].
Definition at line 523 of file Math.h.
00524 {
00525 T size = b - a;
00526 result = ((U)a) + (((U)size) * lerp);
00527 }
|
|
||||||||||||||||||||||||||||
|
spherical linear interpolation between two rotation quaternions. t is a value between 0 and 1 that interpolates between from and to.
Definition at line 526 of file QuatOps.h.
00527 {
00528 const Quat<DATA_TYPE>& p = from; // just an alias to match q
00529
00530 // calc cosine theta
00531 DATA_TYPE cosom = dot( from, to );
00532
00533 // adjust signs (if necessary)
00534 Quat<DATA_TYPE> q;
00535 if (adjustSign && (cosom < (DATA_TYPE)0.0))
00536 {
00537 cosom = -cosom;
00538 q[0] = -to[0]; // Reverse all signs
00539 q[1] = -to[1];
00540 q[2] = -to[2];
00541 q[3] = -to[3];
00542 }
00543 else
00544 {
00545 q = to;
00546 }
00547
00548 // Calculate coefficients
00549 DATA_TYPE sclp, sclq;
00550 if (((DATA_TYPE)1.0 - cosom) > (DATA_TYPE)0.0001) // 0.0001 -> some epsillon
00551 {
00552 // Standard case (slerp)
00553 DATA_TYPE omega, sinom;
00554 omega = gmtl::Math::aCos( cosom ); // extract theta from dot product's cos theta
00555 sinom = gmtl::Math::sin( omega );
00556 sclp = gmtl::Math::sin( ((DATA_TYPE)1.0 - t) * omega ) / sinom;
00557 sclq = gmtl::Math::sin( t * omega ) / sinom;
00558 }
00559 else
00560 {
00561 // Very close, do linear interp (because it's faster)
00562 sclp = (DATA_TYPE)1.0 - t;
00563 sclq = t;
00564 }
00565
00566 result[Xelt] = sclp * p[Xelt] + sclq * q[Xelt];
00567 result[Yelt] = sclp * p[Yelt] + sclq * q[Yelt];
00568 result[Zelt] = sclp * p[Zelt] + sclq * q[Zelt];
00569 result[Welt] = sclp * p[Welt] + sclq * q[Welt];
00570 return result;
00571 }
|
1.2.14 written by Dimitri van Heesch,
© 1997-2002