-
Notifications
You must be signed in to change notification settings - Fork 0
/
GameObject.h
269 lines (221 loc) · 6.26 KB
/
GameObject.h
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
//// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
//// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
//// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//// PARTICULAR PURPOSE.
////
//// Copyright (c) Microsoft Corporation. All rights reserved
#pragma once
// GameObject:
// This is the class representing a generic object in the 3D world of the game. There are
// specific sub-classes that have specific geometric shapes. This class contains all the
// properties of objects that are common.
//
// During the game physics calculations the IsTouching method will be called to determine
// the object's proximity to a point. It is expected the sub-classes will replace this method.
// The Render method will be called during rendering to include the object in the generation of
// the scene.
//#include "MeshObject.h"
#include "SoundEffect.h"
#include "Animate.h"
//#include "Material.h"
ref class GameObject
{
internal:
GameObject();
// Expect the IsTouching method to be overloaded by subclasses.
virtual bool IsTouching(
DirectX::XMFLOAT3 /* point */,
float /* radius */,
_Out_ DirectX::XMFLOAT3 *contact,
_Out_ DirectX::XMFLOAT3 *normal
)
{
*contact = DirectX::XMFLOAT3(0.0f, 0.0f, 0.0f);
*normal = DirectX::XMFLOAT3(0.0f, 0.0f, 1.0f);
return false;
};
void Render(
_In_ ID3D11DeviceContext *context,
_In_ ID3D11Buffer *primitiveConstantBuffer
);
void Active(bool active);
bool Active();
void Target(bool target);
bool Target();
void Hit(bool hit);
bool Hit();
void OnGround(bool ground);
bool OnGround();
void TargetId(int targetId);
int TargetId();
void HitTime(float t);
float HitTime();
void AnimatePosition(_In_opt_ Animate^ animate);
Animate^ AnimatePosition();
void HitSound(_In_ SoundEffect^ hitSound);
SoundEffect^ HitSound();
void PlaySound(float impactSpeed, DirectX::XMFLOAT3 eyePoint);
//void Mesh(_In_ MeshObject^ mesh);
//void NormalMaterial(_In_ Material^ material);
//Material^ NormalMaterial();
//void HitMaterial(_In_ Material^ material);
//Material^ HitMaterial();
void Position(DirectX::XMFLOAT3 position);
void Position(DirectX::XMVECTOR position);
void Velocity(DirectX::XMFLOAT3 velocity);
void Velocity(DirectX::XMVECTOR velocity);
DirectX::XMMATRIX ModelMatrix();
DirectX::XMFLOAT3 Position();
DirectX::XMVECTOR VectorPosition();
DirectX::XMVECTOR VectorVelocity();
DirectX::XMFLOAT3 Velocity();
protected private:
virtual void UpdatePosition() {};
// Object Data
bool m_active;
bool m_target;
int m_targetId;
bool m_hit;
bool m_ground;
DirectX::XMFLOAT3 m_position;
DirectX::XMFLOAT3 m_velocity;
DirectX::XMFLOAT4X4 m_modelMatrix;
//Material^ m_normalMaterial;
//Material^ m_hitMaterial;
DirectX::XMFLOAT3 m_defaultXAxis;
DirectX::XMFLOAT3 m_defaultYAxis;
DirectX::XMFLOAT3 m_defaultZAxis;
float m_hitTime;
Animate^ m_animatePosition;
//MeshObject^ m_mesh;
SoundEffect^ m_hitSound;
};
__forceinline void GameObject::Active(bool active)
{
m_active = active;
}
__forceinline bool GameObject::Active()
{
return m_active;
}
__forceinline void GameObject::Target(bool target)
{
m_target = target;
}
__forceinline bool GameObject::Target()
{
return m_target;
}
__forceinline void GameObject::Hit(bool hit)
{
m_hit = hit;
}
__forceinline bool GameObject::Hit()
{
return m_hit;
}
__forceinline void GameObject::OnGround(bool ground)
{
m_ground = ground;
}
__forceinline bool GameObject::OnGround()
{
return m_ground;
}
__forceinline void GameObject::TargetId(int targetId)
{
m_targetId = targetId;
}
__forceinline int GameObject::TargetId()
{
return m_targetId;
}
__forceinline void GameObject::HitTime(float t)
{
m_hitTime = t;
}
__forceinline float GameObject::HitTime()
{
return m_hitTime;
}
__forceinline void GameObject::Position(DirectX::XMFLOAT3 position)
{
m_position = position;
// Update any internal states that are dependent on the position.
// UpdatePosition is a virtual function that is specific to the derived class.
UpdatePosition();
}
__forceinline void GameObject::Position(DirectX::XMVECTOR position)
{
XMStoreFloat3(&m_position, position);
// Update any internal states that are dependent on the position.
// UpdatePosition is a virtual function that is specific to the derived class.
UpdatePosition();
}
__forceinline DirectX::XMFLOAT3 GameObject::Position()
{
return m_position;
}
__forceinline DirectX::XMVECTOR GameObject::VectorPosition()
{
return DirectX::XMLoadFloat3(&m_position);
}
__forceinline void GameObject::Velocity(DirectX::XMFLOAT3 velocity)
{
m_velocity = velocity;
}
__forceinline void GameObject::Velocity(DirectX::XMVECTOR velocity)
{
XMStoreFloat3(&m_velocity, velocity);
}
__forceinline DirectX::XMFLOAT3 GameObject::Velocity()
{
return m_velocity;
}
__forceinline DirectX::XMVECTOR GameObject::VectorVelocity()
{
return DirectX::XMLoadFloat3(&m_velocity);
}
__forceinline void GameObject::AnimatePosition(_In_opt_ Animate^ animate)
{
m_animatePosition = animate;
}
__forceinline Animate^ GameObject::AnimatePosition()
{
return m_animatePosition;
}
//__forceinline void GameObject::NormalMaterial(_In_ Material^ material)
//{
// m_normalMaterial = material;
//}
//__forceinline Material^ GameObject::NormalMaterial()
//{
// return m_normalMaterial;
//}
//
//__forceinline void GameObject::HitMaterial(_In_ Material^ material)
//{
// m_hitMaterial = material;
//}
//
//__forceinline Material^ GameObject::HitMaterial()
//{
// return m_hitMaterial;
//}
//
//__forceinline void GameObject::Mesh(_In_ MeshObject^ mesh)
//{
// m_mesh = mesh;
//}
__forceinline void GameObject::HitSound(_In_ SoundEffect^ hitSound)
{
m_hitSound = hitSound;
}
__forceinline SoundEffect^ GameObject::HitSound()
{
return m_hitSound;
}
__forceinline DirectX::XMMATRIX GameObject::ModelMatrix()
{
return DirectX::XMLoadFloat4x4(&m_modelMatrix);
}