-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSkinnedMesh.h
386 lines (262 loc) · 7.79 KB
/
SkinnedMesh.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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
//-----------------------------------------------------------------------------
// File: SkinnedMesh.h
//
// Desc: Header file SkinnedMesh sample app
//-----------------------------------------------------------------------------
#pragma once
//base
#define STRICT
#define NOMINMAX //this somehow connected to PhysX
#include <windows.h>
#include <commctrl.h>
#include <commdlg.h>
#include <basetsd.h>
#include <math.h>
#include <stdio.h>
#include <d3dx9.h>
#include <dxerr9.h>
#include <dshow.h>
#include <tchar.h>
#include "DXUtil.h"
#include "D3DEnumeration.h"
#include "D3DSettings.h"
#include "D3DApp.h"
#include "D3DFont.h"
#include "D3DFile.h"
#include "D3DUtil.h"
#include "DMUtil.h"
#include "resource.h"
#include <dxfile.h>
//mine
#include "input.h"
#include "MyModel.h"
#include "ccamera.h"
#include "terrain.h"
#include "SkyBox.h"
#include "particle.h"
#include "decal.h"
#include "cpic.h"
#include "Mp3MusicManager.h"
#include "Water.h"
//physx)
#include "UserAllocator.h"
//#include "UserData.h"
#include "Stream.h"
//#include "Actors.h"
#include "cooking.h"
#include "Joints.h"
#include "NxPhysics.h"
#include "NxControllerManager.h"
#include "MyCharacterController.h"
#include "ContactReport.h"
#include "ErrorStream.h"
#include "PerfRenderer.h"
#include "Utilities.h"
#include "SamplesVRDSettings.h"
//STL
#include <vector>
#include <list>
#include <iostream>
using namespace std; //for STL to get it work
//adds logging to render function
//#define TESTMODE
//-----------------------------------------------------------------------------
// Defines, and constants
//-----------------------------------------------------------------------------
// TODO: change "DirectX AppWizard Apps" to your name or the company name
#define DXAPP_KEY TEXT("Mephisto studios' WAXIS engine")
struct DIRLIGHT
{
D3DXVECTOR3 Pos;
D3DXVECTOR3 Aim;
};
//for shadow maps
#define SHADOWMAPSIZE 3000
//for console & chat
#define CONSOLEHISTORYNUM 12
#define CHATHISTORYNUM 50
struct POLYGON
{
D3DXVECTOR3 v[3];
};
struct QUAD
{
D3DXVECTOR3 v[4];
};
#define DISTANCE(type) D3DXVec3Length(&(type[i]->coordinate - camera->util.GetEyePt()))
#define ONCEANIMATIONPERIOD (SkinMesh[i]->OnceAnimation()==TRUE && SkinMesh[i]->ASI.bAnimPeriodPassed==FALSE)
#define ONCEANIMATIONNOSTRIKEPERIOD (SkinMesh[i]->OnceAnimationNoStrikes()==TRUE && SkinMesh[i]->ASI.bAnimPeriodPassed==FALSE)
#define ONCEANIMATIONHURTPERIOD (SkinMesh[i]->OnceAnimationHurt()==TRUE && SkinMesh[i]->ASI.bAnimPeriodPassed==FALSE)
//console macros
#define AddMessageToConsole(str) consoleHistoryCur++; if( consoleHistoryCur >= CONSOLEHISTORYNUM ) consoleHistoryCur -= CONSOLEHISTORYNUM; strcpy( consoleHistory[consoleHistoryCur], str);
#define AddMessageToChat(str) chatHistoryCur++; if( chatHistoryCur >= CHATHISTORYNUM ) chatHistoryCur -= CHATHISTORYNUM; strcpy( chatHistory[chatHistoryCur], str);
//menu define
#define MAINMENU 1
#define SAVEGAMEMENU 2
#define LOADGAMEMENU 3
#define OPTIONSMENU 4
//class gopoclass{ public: int a,b,c; gopoclass(int, int, int); };
//-----------------------------------------------------------------------------
// Name: class CMyD3DApplication
// Desc: Application class. The base class (CD3DApplication) provides the
// generic functionality needed in all Direct3D samples. CMyD3DApplication
// adds functionality specific to this sample program.
//-----------------------------------------------------------------------------
class CMyD3DApplication : public CD3DApplication
{
BOOL m_bLoadingApp; // TRUE, if the app is loading
BOOL m_bOneTimeRender;
BOOL bShadowsEnable;
BOOL bBoundingBoxes;
//engine constants
int VIEWDISTANCE_OBJECT;
int VIEWDISTANCE_TERRAIN;
int SCREENWIDTH;
int SCREENHEIGHT;
//timing
float WorldTime;
float TimeQ;
//lock stuff
float lockTime;
float itemTime;
// console
BOOL bConsole;
double consoleTime;
char consoleStr[256];
char consoleSymNum;
char consoleHistory[ CONSOLEHISTORYNUM ][256];
char consoleHistoryCur;
// chat
BOOL bChat;
double chatTime;
char chatStr[256];
char chatSymNum;
char chatHistory[ CHATHISTORYNUM ][256];
char chatHistoryCur;
// very important stuff
double EnterTime;
// Font for drawing text
CD3DFont* m_pFont;
char logstr[256];
//menu
BOOL bMenu;
double menuTime;
int curmenu;
int selection;
BOOL bMenuLMB;
//sound - directmusic
FLOAT m_fSoundPlayRepeatCountdown; // Sound repeat timer
CMusicManager* m_pMusicManager; // DirectMusic manager class
//C3DMusicSegment* m_pSound;
//sound - directshow
CMp3MusicManager* m_pBackgroundMusic;
//skybox
CSkyBox* skybox;
//water
CWater* water;
//----- MODELS
// types:
// 1. Animations
// 2. Skinned Meshes
// 3. Objects
// 4. Weapons
// 5. Armor
int NumOfAnimations;
vector<CMyModel*> Animations;
int NumOfSkinMesh;
vector<CMyModel*> SkinMesh;
vector<CModel*> Heads;
int NumOfObjects;
vector<CModel*> Objects;
int NumOfWeapons;
vector<CModel*> Weapons;
int NumOfArmor;
vector<CModel*> Armor;
//-----
//terrain
int NumOfCTerrain;
CTerrain* terrain;
CTextureTable* texTable;
//camera
CCamera* camera;
//dinput
Input* input;
//particles
int NumOfParticle;
CParticleSystemParent* ParticleSystem;
//decals
int NumOfDecals;
CDecal* Decals;
//effects
LPD3DXEFFECT m_pEffect;
//lights
DIRLIGHT* dirlights;
int NumOfLights;
DWORD EnvColor;
//shadow map stuff
LPDIRECT3DTEXTURE9 g_pShadowMap;
LPDIRECT3DSURFACE9 g_pShadowSurf;
LPDIRECT3DSURFACE9 g_pShadowDepth;
LPDIRECT3DSURFACE9 g_pNewDepthRT;
LPDIRECT3DSURFACE9 g_pOldColorRT;
LPDIRECT3DSURFACE9 g_pOldDepthRT;
//menu stuff
int NumOfPics;
CPic* pic;
//engine stuff
//LPDIRECT3DVERTEXBUFFER9 pBoundingBoxVertBuffer;
LPD3DXMESH en_box;
//----- PHYSX STUFF -----
//
NxPhysicsSDK* gPhysicsSDK;
NxScene* gScene;
UserAllocator* gAllocator;
NxControllerManager* gManager;
HRESULT InitNx();
HRESULT StartNx();
HRESULT FetchNx();
HRESULT ReleaseNx();
//
//-----------------------
protected:
virtual HRESULT OneTimeSceneInit();
virtual HRESULT InitDeviceObjects();
virtual HRESULT RestoreDeviceObjects();
virtual HRESULT InvalidateDeviceObjects();
virtual HRESULT DeleteDeviceObjects();
virtual HRESULT Render();
virtual HRESULT FrameMove();
virtual HRESULT FinalCleanup();
virtual HRESULT ConfirmDevice( D3DCAPS9*, DWORD, D3DFORMAT );
HRESULT RenderText();
HRESULT RenderPhysXBox(NxActor* object);
HRESULT RenderPhysXCapsule(NxActor* object);
//HRESULT RenderCM(CollisionModel* cmIn);
//---- COLLISION DETECTION ----
D3DXVECTOR3 BoxVsBoxCollision( CollisionModel* cm1, CollisionModel* cm2 ); //returns offsets of dx, dy, dz
POLYGON* BoxVsPolygon( CollisionModel* cm, POLYGON* pl );
//---------
HRESULT AddActor(int inAnimType, char* inMeshPath, char* inHeadMeshPath, D3DXVECTOR3 inCoord);
HRESULT AddDecal( CollisionModel* cm, CTerrain* terr );
//menu stuff
HRESULT MenuCallback();
HRESULT MenuRender();
//process stuff
int GetCModelIndexByID( vector<CModel*> cm, int NumOfcm, int id );
HRESULT ProcessConsoleMsg();
HRESULT ProcessChatMsg();
//audio
HRESULT InitAudio( HWND hWnd );
//effect
HRESULT InitEffect();
HRESULT UpdateEffectVariables();
//Callbacks
HRESULT DInputCallback();
HRESULT AICallback(CModel*);
//ProcessMovement - based on animation
HRESULT ProcessMovement(CModel*);
public:
LRESULT MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam );
CMyD3DApplication();
virtual ~CMyD3DApplication();
};