-
Notifications
You must be signed in to change notification settings - Fork 0
/
Terrain.h
82 lines (64 loc) · 1.97 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
#pragma once
#include <vector>
#include "Commons.h"
#include "GameObject.h"
#include "Camera.h"
#include "ShadowMapping.h"
class Terrain
{
public:
struct InitInfo
{
std::wstring HeightMapFilename;
std::wstring LayerMapFilename0;
std::wstring LayerMapFilename1;
std::wstring LayerMapFilename2;
std::wstring LayerMapFilename3;
std::wstring LayerMapFilename4;
std::wstring BlendMapFilename;
float HeightScale;
UINT HeightMapWidth;
UINT HeightMapHeight;
float CellSpacing;
};
Terrain();
~Terrain();
float GetWidth()const;
float GetDepth()const;
float GetHeight(float x, float z)const;
XMMATRIX GetWorld()const;
void SetWorld(CXMMATRIX M);
void Init(ID3D11Device* device, ID3D11DeviceContext* deviceContext, const InitInfo& initInfo, std::vector<float> heightmapData);
void Draw(ID3D11DeviceContext* deviceContext, Light light, Camera* camera, ShadowMap* pShadowMap);
void DrawToShadowMap(ID3D11DeviceContext* deviceContext, ShadowMapConstantBuffer &cb, Camera* camera);
private:
void Smooth();
bool InBounds(int i, int j);
float Average(int i, int j);
void CalcAllPatchBoundsY();
void CalcPatchBoundsY(UINT i, UINT j);
void BuildQuadPatchVB(ID3D11Device* device);
void BuildQuadPatchIB(ID3D11Device* device);
void BuildHeightMapSRV(ID3D11Device* device, std::vector<float> heightMap);
private:
static const int CellsPerPatch = 64;
ID3D11Buffer* _quadPatchVertexBuffer;
ID3D11Buffer* _quadPatchIndexBuffer;
ID3D11Buffer* _pConstantBuffer;
InitInfo _info;
UINT _numPatchVertices;
UINT _numPatchQuadFaces;
UINT _numPatchVertRows;
UINT _numPatchVertCols;
XMFLOAT4X4 _world;
Material _material;
std::vector<XMFLOAT2> _patchBoundsY;
std::vector<float> _heightMap;
ID3D11ShaderResourceView* _blendMapSRV;
ID3D11ShaderResourceView* _heightMapSRV;
ID3D11ShaderResourceView * _layer0SRV;
ID3D11ShaderResourceView * _layer1SRV;
ID3D11ShaderResourceView * _layer2SRV;
ID3D11ShaderResourceView * _layer3SRV;
ID3D11ShaderResourceView * _layer4SRV;
};