Radium Engine  1.5.0
Interpolation.hpp
1 #pragma once
2 
3 #include <Core/Types.hpp>
4 
5 namespace Ra {
6 namespace Core {
7 namespace Math {
8 
11 
17 template <typename T>
18 inline T linearInterpolate( const T& v0, const T& v1, const Scalar t ) {
19  return ( ( 1_ra - t ) * v0 ) + ( t * v1 );
20 }
21 
26 template <>
27 inline Core::Quaternion linearInterpolate<Core::Quaternion>( const Core::Quaternion& q0,
28  const Core::Quaternion& q1,
29  const Scalar t ) {
30  return q0.slerp( t, q1 );
31 }
32 
39 template <>
40 inline Core::Transform linearInterpolate<Core::Transform>( const Core::Transform& T0,
41  const Core::Transform& T1,
42  const Scalar t ) {
43  Ra::Core::Matrix3 T0R, T1R;
44  Ra::Core::Matrix3 T0S, T1S;
45  T0.computeRotationScaling( &T0R, &T0S );
46  T1.computeRotationScaling( &T1R, &T1S );
47 
48  Ra::Core::Quaternion T0Rot = Ra::Core::Quaternion( T0R );
49  Ra::Core::Quaternion T1Rot = Ra::Core::Quaternion( T1R );
50  Ra::Core::Quaternion iR = T0Rot.slerp( t, T1Rot );
51  Ra::Core::Matrix3 iS = ( 1 - t ) * T0S + t * T1S;
52  Ra::Core::Vector3 iT = ( 1 - t ) * T0.translation() + t * T1.translation();
53 
54  Core::Transform result;
55  result.fromPositionOrientationScale( iT, iR, iS.diagonal() );
56  return result;
57 }
59 
60 } // namespace Math
61 } // namespace Core
62 } // namespace Ra
T linearInterpolate(const T &v0, const T &v1, const Scalar t)
Definition: Cage.cpp:3