-
Notifications
You must be signed in to change notification settings - Fork 1
/
Skele.cpp
125 lines (105 loc) · 2.82 KB
/
Skele.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include "Skele.h"
Skele::Skele( ): m_modelId( 0 ), m_file_path( "models/bones_all.x" )
{
}
Skele::~Skele( )
{
}
// We are not using this, but have to override it from base class
bool Skele::Initialize(Terrain *terrain)
{
return false;
}
bool Skele::Initialize(std::shared_ptr<IXAnimator> xAnimator)
{
// set speed variables
speed = 50.0f;
strafeSpeed = 50.0f;
turnSpeed = 2.0f;
// set start position
Reset();
// Use the animation librayr to initialize the physical mesh object
m_animator = xAnimator;
if( !m_animator->LoadXFile( m_file_path.c_str( ), &m_modelId) )
{
printf("IXAnimator library could not load %s", m_file_path.c_str() );
return false;
}
m_numberOfAnimationSets = m_animator->GetNumberOfAnimationSets(m_modelId);
// set the scale
D3DXMatrixScaling( &S, 7.0f, 7.0f, 7.0f );
return true;
}
void Skele::Render( )
{
// the position and rotation translation matrix is the inverse of the characters's view matrix
getViewMatrix( &T );
D3DXMatrixInverse( &T, NULL, &T );
P = S*T;
// The render function expects the time to be in milliseconds
// timer.DeltaTime() returns units in seconds
m_animator->Render(m_modelId, P, timer.DeltaTime()*1000.0f );
// update the bounding box coordinates to match the mesh
D3DXVec3TransformCoord( &box.MIN, &characterMesh.min, &P );
D3DXVec3TransformCoord( &box.MAX, &characterMesh.max, &P );
}
void Skele::Update( )
{
// update third person camera position (rear view)
thirdPersonCamera._pos = ((-_look * 20.0) + (_up * 10.0f)) + _pos;
}
void Skele::GetMessages( UINT msg, WPARAM wParam, LPARAM lParam, void * Data )
{
if( isAuto )
{
switch (msg)
{
case WM_CHAR:
switch( wParam )
{
case 'z':
m_animator->ChangeAnimationSet(m_modelId, Skele::shaking_head);
break;
case 'x':
m_animator->ChangeAnimationSet(m_modelId, Skele::walking);
break;
case 'c':
m_animator->ChangeAnimationSet(m_modelId, Skele::taking_damage);
break;
case 'v':
m_animator->ChangeAnimationSet(m_modelId, Skele::dancing);
break;
case 'b':
m_animator->ChangeAnimationSet(m_modelId, Skele::dying);
break;
default:
break;
}
break;
default:
break;
}
}
else
{
printf("Skeleton error: Skeleton should be AI driven\n");
}
}
void Skele::Reset( )
{
// set start position
_pos = { 900.0f, 0.0f, -850.0f };
}
D3DXMATRIX Skele::getRearView( )
{
D3DXMATRIX V;
D3DXMatrixLookAtLH( &V, &thirdPersonCamera._pos, &D3DXVECTOR3( _pos.x, box.MAX.y, _pos.z ), &D3DXVECTOR3( 0, 1, 0 ) );
return V;
}
D3DXMATRIX Skele::getSideView( )
{
D3DXMATRIX V;
thirdPersonCamera._pos = ((_right * 500.0f) + (_up * 50.0f)) + _pos;
D3DXMatrixLookAtLH( &V, &thirdPersonCamera._pos, &D3DXVECTOR3( _pos.x, box.MAX.y, _pos.z ), &D3DXVECTOR3( 1, 0, 0 ) );
return V;
}