-
Notifications
You must be signed in to change notification settings - Fork 1
/
D3D.h
112 lines (83 loc) · 2.78 KB
/
D3D.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
#ifndef D3D_H
#define D3D_H
#include <d3dx9.h>
#include <windows.h>
extern IDirect3DDevice9 *Device;
extern HWND hwnd;
static D3DPRESENT_PARAMETERS d3dpp;
#define screenWidth 800
#define screenHeight 600
namespace D3D {
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
bool InitWindow(HINSTANCE hInstance);
bool InitD3D();
const D3DXCOLOR WHITE(D3DCOLOR_XRGB(255, 255, 255));
const D3DXCOLOR BLACK(D3DCOLOR_XRGB(0, 0, 0));
const D3DXCOLOR RED(D3DCOLOR_XRGB(255, 0, 0));
const D3DXCOLOR GREEN(D3DCOLOR_XRGB(0, 255, 0));
const D3DXCOLOR BLUE(D3DCOLOR_XRGB(0, 0, 255));
const D3DXCOLOR YELLOW(D3DCOLOR_XRGB(255, 255, 0));
const D3DXCOLOR CYAN(D3DCOLOR_XRGB(0, 255, 255));
const D3DXCOLOR MAGENTA(D3DCOLOR_XRGB(255, 0, 255));
D3DMATERIAL9 InitMtrl(D3DXCOLOR a, D3DXCOLOR d, D3DXCOLOR s, D3DXCOLOR e, float p);
D3DLIGHT9 InitDirectionalLight(D3DXVECTOR3 * direction, D3DXCOLOR * color);
D3DLIGHT9 InitSpotLight(D3DXVECTOR3 * position, D3DXVECTOR3 * direction, D3DXCOLOR * color);
D3DLIGHT9 InitPointLight(D3DXVECTOR3 * position, D3DXCOLOR * color);
IDirect3DTexture9* LoadTexture(char* fileName);
float Lerp(float a, float b, float t);
float GetRandomFloat(float lowBound, float highBound);
void GetRandomVector(D3DXVECTOR3 *out, D3DXVECTOR3 *min, D3DXVECTOR3* max);
DWORD FtoDw(float f);
// structures for animated mesh container
struct D3DXMESHCONTAINER_EXTENDED : public D3DXMESHCONTAINER {
IDirect3DTexture9** exTextures;
D3DMATERIAL9* exMaterials;
ID3DXMesh* exSkinMesh;
D3DXMATRIX* exBoneOffsets;
D3DXMATRIX** exFrameCombinedMatrixPointer;
};
// structure for extended frame for animated meshes
struct D3DXFRAME_EXTENDED : public D3DXFRAME {
D3DXMATRIX exCombinedTransformationMatrix;
};
// vertex struct for environment objects
struct EVertex {
EVertex() {}
EVertex(float X, float Y, float Z, float U, float V) : x(X), y(Y), z(Z), u(U), v(V) {}
float x, y, z, u, v;
static const DWORD FVF = D3DFVF_XYZ | D3DFVF_TEX1;
};
// bounding box structure for collision detection and particle systems
struct BoundingBox {
BoundingBox();
// compares point to bounding vectors
bool isPointInside(D3DXVECTOR3 &point);
// collision between bounding boxes
bool isCollision(BoundingBox &box);
D3DXVECTOR3 _min, _max;
};
// overloaded operators for comparing vectors
bool operator<=(const D3DXVECTOR3 &a, const D3DXVECTOR3 &b);
bool operator>=(const D3DXVECTOR3 &a, const D3DXVECTOR3 &b);
// distance checking function for 3D vectors
float getDistance(D3DXVECTOR3 &a, D3DXVECTOR3 &b);
// release method
template<class T> void Release(T t)
{
if (t)
{
t->Release();
t = 0;
}
}
// delete method
template<class T> void Delete(T t)
{
if (t)
{
delete t;
t = 0;
}
}
}
#endif