/
GAnimController.cpp
94 lines (81 loc) · 2.29 KB
/
GAnimController.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include "GGameDemoHeader.h"
#include "GAnimController.h"
#include "GTimer.h"
#include "Content.h"
GAnimController::GAnimController ( void )
: mD3DController ( nullptr )
{
mSetDone = false;
mCurSet = nullptr;
mTargetSet = nullptr;
mSetFrameLast = 0;
mSetFrameCur = 0;
}
GAnimController::~GAnimController ( void )
{
dSafeRelease ( mD3DController );
}
void GAnimController::setBaseController ( ID3DXAnimationController* controller )
{
CXASSERT_RETURN ( controller != nullptr );
CXASSERT_RESULT ( controller->CloneAnimationController
(
controller->GetMaxNumAnimationOutputs()
, controller->GetMaxNumAnimationSets()
, controller->GetMaxNumTracks()
, controller->GetMaxNumEvents()
, &mD3DController
)
);
assert(controller->AddRef()==2);
assert(controller->Release()==1);
CXASSERT_RETURN ( mD3DController );
playFirstAnim();
}
void GAnimController::update()
{
mD3DController->AdvanceTime ( Content::Timer.getFrameTimeSec(), NULL );
if ( mCurSet != NULL )
{
D3DXTRACK_DESC trackDesc;
mD3DController->GetTrackDesc ( 0, &trackDesc );
double dbPassTime = mCurSet->GetPeriodicPosition ( trackDesc.Position );
mSetFrameCur = dbPassTime * 300000;
if ( mSetFrameCur < mSetFrameLast )
{
mSetDone = true;
mSetFrameLast = 0;
mSetFrameCur = 0;
if ( mTargetSet )
{
mCurSet = mTargetSet;
mTargetSet = nullptr;
}
}
else
{
mSetFrameLast = mSetFrameCur;
}
}
}
void GAnimController::play ( const char* animSetName )
{
assert ( mD3DController );
ID3DXAnimationSet* pset = nullptr;
mD3DController->GetAnimationSetByName ( animSetName , &pset );
if ( mSetDone )
mCurSet = pset;
else
mTargetSet = pset;
}
void GAnimController::playFirstAnim()
{
if ( mCurSet != nullptr )
{
mD3DController->GetAnimationSet ( 0, &mTargetSet );
}
else
{
mD3DController->GetAnimationSet ( 0, &mCurSet );
}
}