10
10
#include < iostream>
11
11
12
12
#include < Core/Animation/KeyFramedValue.hpp>
13
+ #include < Core/Animation/KeyFramedValueInterpolators.hpp>
13
14
#include < Core/Math/Interpolation.hpp>
14
15
#include < Core/Utils/Color.hpp>
15
16
#include < Core/Utils/Log.hpp>
20
21
21
22
static constexpr int CTRL_PT_RAD = 5 ;
22
23
24
+ using namespace Ra ::Core::Animation;
23
25
using namespace Ra ::Core::Utils;
24
26
25
- template <typename T>
26
- using KeyFramedValue = Ra::Core::Animation::KeyFramedValue<T>;
27
-
28
27
namespace Ra ::GuiBase {
29
28
30
29
KeyFrameEditorFrame::KeyFrameEditorFrame ( QWidget* parent ) : QFrame( parent ) {
@@ -297,32 +296,32 @@ void KeyFrameEditorFrame::onSetCursorToNextKeyFrame() {
297
296
} \
298
297
}
299
298
300
- #define drawSampled ( drawFunc ) \
301
- { \
302
- int p; \
303
- Scalar t0 = *times.begin (); \
304
- for ( auto t1 : times ) \
305
- { \
306
- fromTimeToPixel ( t1, p ); \
307
- if ( p < sliderH ) \
308
- { \
309
- std::exchange ( t0, t1 ); \
310
- continue ; \
311
- } \
312
- fromTimeToPixel ( t0, p ); \
313
- if ( p > sliderH + areaWidth ) \
314
- { \
315
- std::exchange ( t0, t1 ); \
316
- continue ; \
317
- } \
318
- const int N = int ( ( t1 - t0 ) / stepT ); \
319
- for ( Scalar t = t0; t <= t1; t += 1_ra / N ) \
320
- { \
321
- fromTimeToPixel ( t, p ); \
322
- drawFunc ( p, kf->at ( t ) ); \
323
- } \
324
- std::exchange ( t0, t1 ); \
325
- } \
299
+ #define drawSampled ( drawFunc, type ) \
300
+ { \
301
+ int p; \
302
+ Scalar t0 = *times.begin (); \
303
+ for ( auto t1 : times ) \
304
+ { \
305
+ fromTimeToPixel ( t1, p ); \
306
+ if ( p < sliderH ) \
307
+ { \
308
+ std::exchange ( t0, t1 ); \
309
+ continue ; \
310
+ } \
311
+ fromTimeToPixel ( t0, p ); \
312
+ if ( p > sliderH + areaWidth ) \
313
+ { \
314
+ std::exchange ( t0, t1 ); \
315
+ continue ; \
316
+ } \
317
+ const int N = int ( ( t1 - t0 ) / stepT ); \
318
+ for ( Scalar t = t0; t <= t1; t += 1_ra / N ) \
319
+ { \
320
+ fromTimeToPixel ( t, p ); \
321
+ drawFunc ( p, kf->at ( t, linearInterpolate<type> ) ); \
322
+ } \
323
+ std::exchange ( t0, t1 ); \
324
+ } \
326
325
}
327
326
328
327
void KeyFrameEditorFrame::paintEvent ( QPaintEvent* ) {
@@ -483,33 +482,33 @@ void KeyFrameEditorFrame::paintEvent( QPaintEvent* ) {
483
482
fromValueToPixel ( v, y );
484
483
path[0 ].lineTo ( QPoint ( x, y ) );
485
484
};
486
- drawSampled ( drawScalar );
485
+ drawSampled ( drawScalar, Scalar );
487
486
}
488
487
}
489
488
else if ( auto kf = dynamic_cast <KeyFramedValue<Ra::Core::Vector2>*>( m_value ) )
490
489
{
491
490
if ( m_displayCurve[0 ] || m_displayCurve[1 ] )
492
- { drawSampled ( drawVector ( Ra::Core::Vector2, 2 ) ); }
491
+ { drawSampled ( drawVector ( Ra::Core::Vector2, 2 ), Ra::Core::Vector2 ); }
493
492
}
494
493
else if ( auto kf = dynamic_cast <KeyFramedValue<Ra::Core::Vector3>*>( m_value ) )
495
494
{
496
495
if ( m_displayCurve[0 ] || m_displayCurve[1 ] || m_displayCurve[2 ] )
497
- { drawSampled ( drawVector ( Ra::Core::Vector3, 3 ) ); }
496
+ { drawSampled ( drawVector ( Ra::Core::Vector3, 3 ), Ra::Core::Vector3 ); }
498
497
}
499
498
else if ( auto kf = dynamic_cast <KeyFramedValue<Ra::Core::Vector4>*>( m_value ) )
500
499
{
501
500
if ( m_displayCurve[0 ] || m_displayCurve[1 ] || m_displayCurve[2 ] || m_displayCurve[3 ] )
502
- { drawSampled ( drawVector ( Ra::Core::Vector4, 4 ) ); }
501
+ { drawSampled ( drawVector ( Ra::Core::Vector4, 4 ), Ra::Core::Vector4 ); }
503
502
}
504
503
else if ( auto kf = dynamic_cast <KeyFramedValue<Ra::Core::Utils::Color>*>( m_value ) )
505
504
{
506
505
if ( m_displayCurve[0 ] || m_displayCurve[1 ] || m_displayCurve[2 ] || m_displayCurve[3 ] )
507
- { drawSampled ( drawVector ( Ra::Core::Utils::Color, 4 ) ); }
506
+ { drawSampled ( drawVector ( Ra::Core::Utils::Color, 4 ), Ra::Core::Utils::Color ); }
508
507
}
509
508
else if ( auto kf = dynamic_cast <KeyFramedValue<Ra::Core::Quaternion>*>( m_value ) )
510
509
{
511
510
if ( m_displayCurve[0 ] || m_displayCurve[1 ] || m_displayCurve[2 ] || m_displayCurve[3 ] )
512
- { drawSampled ( drawQuaternion ); }
511
+ { drawSampled ( drawQuaternion, Ra::Core::Quaternion ); }
513
512
}
514
513
else if ( auto kf = dynamic_cast <KeyFramedValue<Ra::Core::Transform>*>( m_value ) )
515
514
{
@@ -541,7 +540,7 @@ void KeyFrameEditorFrame::paintEvent( QPaintEvent* ) {
541
540
path[9 ].lineTo ( QPoint ( x, y ) );
542
541
}
543
542
};
544
- drawSampled ( drawTransform );
543
+ drawSampled ( drawTransform, Ra::Core::Transform );
545
544
}
546
545
}
547
546
@@ -729,17 +728,20 @@ void KeyFrameEditorFrame::mouseMoveEvent( QMouseEvent* event ) {
729
728
if ( auto kf = dynamic_cast <KeyFramedValue<bool >*>( m_value ) )
730
729
{
731
730
kf->insertKeyFrame ( time , int ( std::max ( value, 0_ra ) ) );
732
- m_curveControlPoints[uint ( i )][uint ( j )].y () = kf->at ( time );
731
+ m_curveControlPoints[uint ( i )][uint ( j )].y () =
732
+ kf->at ( time , linearInterpolate<bool > );
733
733
}
734
734
if ( auto kf = dynamic_cast <KeyFramedValue<int >*>( m_value ) )
735
735
{
736
736
kf->insertKeyFrame ( time , int ( value ) );
737
- m_curveControlPoints[uint ( i )][uint ( j )].y () = kf->at ( time );
737
+ m_curveControlPoints[uint ( i )][uint ( j )].y () =
738
+ kf->at ( time , linearInterpolate<int > );
738
739
}
739
740
if ( auto kf = dynamic_cast <KeyFramedValue<Scalar>*>( m_value ) )
740
741
{
741
742
kf->insertKeyFrame ( time , value );
742
- m_curveControlPoints[uint ( i )][uint ( j )].y () = kf->at ( time );
743
+ m_curveControlPoints[uint ( i )][uint ( j )].y () =
744
+ kf->at ( time , linearInterpolate<Scalar> );
743
745
}
744
746
if ( auto kf = dynamic_cast <KeyFramedValue<Ra::Core::Vector2>*>( m_value ) )
745
747
{
@@ -855,21 +857,21 @@ Scalar KeyFrameEditorFrame::nearestStep( Scalar time ) const {
855
857
return newCursor;
856
858
}
857
859
858
- #define registerValue () \
859
- m_curveControlPoints[0 ].reserve( times.size() ); \
860
- for ( auto t : times ) \
861
- { \
862
- m_curveControlPoints[0 ].push_back ( {t, kf->at ( t )} ); \
860
+ #define registerValue ( type ) \
861
+ m_curveControlPoints[0 ].reserve( times.size() ); \
862
+ for ( auto t : times ) \
863
+ { \
864
+ m_curveControlPoints[0 ].push_back ( {t, kf->at ( t, linearInterpolate<type> )} ); \
863
865
}
864
866
865
- #define registerVector ( N ) \
867
+ #define registerVector ( N, type ) \
866
868
for ( size_t i = 0 ; i < N; ++i ) \
867
869
{ \
868
870
m_curveControlPoints[i].reserve ( times.size () ); \
869
871
} \
870
872
for ( auto t : times ) \
871
873
{ \
872
- const auto f = kf->at ( t ); \
874
+ const auto f = kf->at ( t, linearInterpolate<type> ); \
873
875
for ( uint i = 0 ; i < N; ++i ) \
874
876
m_curveControlPoints[i].push_back ( {t, f ( i )} ); \
875
877
}
@@ -910,7 +912,8 @@ void KeyFrameEditorFrame::registerKeyFrames( bool newValue ) {
910
912
m_curveControlPoints[0 ].reserve ( times.size () );
911
913
for ( auto t : times )
912
914
{
913
- m_curveControlPoints[0 ].push_back ( {t, ( kf->at ( t ) ? 1 : 0 )} );
915
+ m_curveControlPoints[0 ].push_back (
916
+ {t, ( kf->at ( t, linearInterpolate<bool > ) ? 1 : 0 )} );
914
917
}
915
918
916
919
if ( m_ui != nullptr )
@@ -921,7 +924,7 @@ void KeyFrameEditorFrame::registerKeyFrames( bool newValue ) {
921
924
}
922
925
else if ( auto kf = dynamic_cast <KeyFramedValue<int >*>( m_value ) )
923
926
{
924
- registerValue ();
927
+ registerValue ( int );
925
928
926
929
if ( m_ui != nullptr )
927
930
{
@@ -931,7 +934,7 @@ void KeyFrameEditorFrame::registerKeyFrames( bool newValue ) {
931
934
}
932
935
else if ( auto kf = dynamic_cast <KeyFramedValue<Scalar>*>( m_value ) )
933
936
{
934
- registerValue ();
937
+ registerValue ( Scalar );
935
938
936
939
if ( m_ui != nullptr )
937
940
{
@@ -941,7 +944,7 @@ void KeyFrameEditorFrame::registerKeyFrames( bool newValue ) {
941
944
}
942
945
else if ( auto kf = dynamic_cast <KeyFramedValue<Ra::Core::Vector2>*>( m_value ) )
943
946
{
944
- registerVector ( 2 );
947
+ registerVector ( 2 , Ra::Core::Vector2 );
945
948
946
949
if ( m_ui != nullptr )
947
950
{
@@ -953,7 +956,7 @@ void KeyFrameEditorFrame::registerKeyFrames( bool newValue ) {
953
956
}
954
957
else if ( auto kf = dynamic_cast <KeyFramedValue<Ra::Core::Vector3>*>( m_value ) )
955
958
{
956
- registerVector ( 3 );
959
+ registerVector ( 3 , Ra::Core::Vector3 );
957
960
958
961
if ( m_ui != nullptr )
959
962
{
@@ -967,7 +970,7 @@ void KeyFrameEditorFrame::registerKeyFrames( bool newValue ) {
967
970
}
968
971
else if ( auto kf = dynamic_cast <KeyFramedValue<Ra::Core::Vector4>*>( m_value ) )
969
972
{
970
- registerVector ( 4 );
973
+ registerVector ( 4 , Ra::Core::Vector4 );
971
974
972
975
if ( m_ui != nullptr )
973
976
{
@@ -983,7 +986,7 @@ void KeyFrameEditorFrame::registerKeyFrames( bool newValue ) {
983
986
}
984
987
else if ( auto kf = dynamic_cast <KeyFramedValue<Ra::Core::Utils::Color>*>( m_value ) )
985
988
{
986
- registerVector ( 4 );
989
+ registerVector ( 4 , Ra::Core::Utils::Color );
987
990
988
991
if ( m_ui != nullptr )
989
992
{
@@ -1004,7 +1007,9 @@ void KeyFrameEditorFrame::registerKeyFrames( bool newValue ) {
1004
1007
m_curveControlPoints[6 ].reserve ( times.size () );
1005
1008
for ( auto t : times )
1006
1009
{
1007
- const auto f = kf->at ( t ).matrix ().eulerAngles ( 0 , 1 , 2 );
1010
+ const auto f = kf->at ( t, linearInterpolate<Ra::Core::Quaternion> )
1011
+ .matrix ()
1012
+ .eulerAngles ( 0 , 1 , 2 );
1008
1013
m_curveControlPoints[4 ].push_back ( {t, f.x ()} );
1009
1014
m_curveControlPoints[5 ].push_back ( {t, f.y ()} );
1010
1015
m_curveControlPoints[6 ].push_back ( {t, f.z ()} );
@@ -1025,7 +1030,7 @@ void KeyFrameEditorFrame::registerKeyFrames( bool newValue ) {
1025
1030
}
1026
1031
for ( auto t : times )
1027
1032
{
1028
- const auto f = kf->at ( t );
1033
+ const auto f = kf->at ( t, linearInterpolate<Ra::Core::Transform> );
1029
1034
const auto T = f.translation ();
1030
1035
Ra::Core::Matrix3 R, S;
1031
1036
f.computeRotationScaling ( &R, &S );
0 commit comments