-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathterrain.h
237 lines (169 loc) · 4.42 KB
/
terrain.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
//basic includes
//#define STRICT
#define NOMINMAX //this somehow connected to PhysX
#include <windows.h>
#include <commdlg.h>
#include <tchar.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <commctrl.h>
#include <basetsd.h>
#include <dxerr9.h>
#include <dshow.h>
#include <dxfile.h>
//physics
#include "NxPhysics.h"
#include "UserAllocator.h"
#include "MyCharacterController.h"
#include "Stream.h"
#include "cooking.h"
#include "ErrorStream.h"
//#include "PerfRenderer.h"
//#include "Utilities.h"
//#include "SamplesVRDSettings.h"
//DX includes
#include "d3dx9.h"
#include "d3dx9effect.h"
#include "D3DFile.h"
#include "DXUtil.h"
#include "D3DEnumeration.h"
#include "D3DSettings.h"
#include "D3DApp.h"
#include "D3DFont.h"
#include "D3DUtil.h"
#include "DMUtil.h"
//mine
#include "mmath.h"
#include "mstring.h"
#include "log.h"
//STL
#include <vector>
#include <list>
#include <iostream>
using namespace std; //for STL to get it work
#define U16 unsigned short
typedef struct{
D3DXVECTOR2 size, elements;
char* TexturePath;
char* HeightmapPath;
D3DXVECTOR3 coordinate;
char type;
int Q;
}TERRAININFO;
class CUSTOMVERTEX
{
public:
FLOAT x, y, z;
FLOAT nx, ny, nz;
FLOAT tu, tv;
CUSTOMVERTEX();
CUSTOMVERTEX(float, float, float, float, float, float, float, float);
CUSTOMVERTEX(D3DXVECTOR3, D3DXVECTOR3, D3DXVECTOR2);
};
#define D3DFVF_CUSTOMVERTEX ( D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1 )
#define OUTOFTERRAIN -99999.0f
// terrain type
//up - floor
//down - roof
//none - smth else
#define UP 1
#define DOWN 2
#define NONE 3
//orientations
#define OR_NONE -1
#define OR_N 0
#define OR_NE 1
#define OR_E 2
#define OR_SE 3
#define OR_S 4
#define OR_SW 5
#define OR_W 6
#define OR_NW 7
//-------------------------------------------------------------
// Name:
// Desc:
//-------------------------------------------------------------
class CTextureTable
{
public:
LPDIRECT3DDEVICE9 m_pd3dDevice;
LPDIRECT3DTEXTURE9* ppTex;
LPDIRECT3DTEXTURE9* ppBumpTex;
UINT elementCount;
public:
HRESULT Release();
HRESULT CreateFromFile(LPDIRECT3DDEVICE9, char*);
};
/* example of texture table file:
-----------------------------------------
[Table] 3
0 snow01.jpg
25 snow02.jpg
50 ice01.jpg
-----------------------------------------
*/
//-------------------------------------------------------------
// Name:
// Desc:
//-------------------------------------------------------------
class CTerrain
{
public:
//message
char msg;
char type;
protected:
LPDIRECT3DDEVICE9 pDirect3DDevice;
//------------------
//shader stuff
LPD3DXEFFECT m_pEffect;
//------------------
D3DXVECTOR3 coordinate;
D3DXVECTOR3 angle;
LPDIRECT3DVERTEXBUFFER9 pBufferVertex;
LPDIRECT3DINDEXBUFFER9 pBufferIndex;
LPDIRECT3DINDEXBUFFER9 pBufferIndexLOD2;
LPDIRECT3DINDEXBUFFER9 pBufferIndexLOD4;
LPDIRECT3DINDEXBUFFER9 pBufferIndexLOD8;
LPDIRECT3DINDEXBUFFER9 pBufferIndexLOD16;
//colormap - weights of textures
LPDIRECT3DTEXTURE9 pTextureMap;
CTextureTable* texTable;
UINT m_numFaces;
UINT m_numIndices;
UINT m_numVert;
int seg_x, seg_y;
int terWidth, terHeight;
int HeightQ;
//render
int area;
public:
//----- physX
NxPhysicsSDK* mPhysicsSDK;
NxScene* mScene;
NxActor* object;
//get functions
vector<float> GetVertices();
vector<U16> GetIndices();
LPDIRECT3DVERTEXBUFFER9 GetVertexBuffer() { return pBufferVertex; }
LPDIRECT3DINDEXBUFFER9 GetIndexBuffer() { return pBufferIndex; }
//-----
HRESULT Init(char*, LPDIRECT3DDEVICE9, CTextureTable*, LPD3DXEFFECT g_pEffect); //string "width height nx ny q TYPE transBmp mapBMP"
HRESULT Create(int width, int height, int nx, int ny, int Q, char t_type);
HRESULT TransformFromBMP(LPCWSTR filePath);
HRESULT InitPhysX( NxPhysicsSDK* gPhysicsSDK, NxScene* gScene );
HRESULT CalculateNormals();
FLOAT GetYByXZ(float x, float z);
FLOAT GetYByQuadAndXZ(float x, float z, CUSTOMVERTEX* Vert);
D3DXVECTOR2 GetNByXZ(float x, float z);
CUSTOMVERTEX* GetQuadByN(D3DXVECTOR2 n);
D3DXVECTOR3 GetNormalByXZ(float x, float z);
HRESULT SetCoordinate( D3DXVECTOR3 coordinate );
HRESULT SetArea(int);
HRESULT Render(D3DXMATRIX, D3DXMATRIX, D3DXVECTOR2, D3DXVECTOR2 campos);
HRESULT RenderLOD(int LOD, D3DXVECTOR2 A,D3DXVECTOR2 B,D3DXVECTOR2 C,D3DXVECTOR2 D);
HRESULT Release();
~CTerrain() { };
CTerrain();
};