-
Notifications
You must be signed in to change notification settings - Fork 0
/
Terrain.h
171 lines (141 loc) · 4.19 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
/*--------------------------------------------------------------------------------
Terrain.h
Provides all definitions for Terrain generation/manipulation
History:
Created by Scott Wakeling
--------------------------------------------------------------------------------*/
#ifndef _TERRAIN_H
#define _TERRAIN_H
//-------------
// Includes
//-------------
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
#include "resource.h"
//-----------------
// Definitions
//-----------------
#define COLOUR(r,g,b) ((COLORREF)((((0)&0xff)<<24)|(((b)&0xff)<<16)|(((g)&0xff)<<8)|((r)&0xff)))
#define GRID_X 256
#define GRID_Y 256
//----------------------------------
// A simple mathematical vector
//----------------------------------
class CVector
{
public:
FLOAT x, y, z;
//----------------------------------
// Construction and Destruction
//----------------------------------
CVector() : x(0.0),
y(0.0),
z(0,0)
{
};
CVector( FLOAT fInx, FLOAT fIny, FLOAT fInz ) : x(fInx),
y(fIny),
z(fInz)
{
};
//-----------------------
// CVector Interface
//-----------------------
//...
//------------------------------------------------------------------------------
// Operators
//------------------------------------------------------------------------------
// Cross
CVector operator^( const CVector& vec ) const
{
return CVector( (y * vec.z - z * vec.y), (z * vec.x - x * vec.z), (x * vec.y - y * vec.x) );
}
// Subtraction
CVector operator-( const CVector vec ) const
{
return CVector( x - vec.x, y - vec.y, z - vec.z );
}
};
//--------------------------------------------------------------------
// A fault line class for use in the fault line generation fractal
//--------------------------------------------------------------------
class CFaultLine
{
public:
//----------------------------------
// Construction and Destruction
//----------------------------------
CFaultLine();
CFaultLine( CVector v1, CVector v2 );
virtual ~CFaultLine();
//--------------------------
// CFaultLine Interface
//--------------------------
FLOAT TestPoint( CVector vTest );
private:
CVector vFaultBase;
CVector vFaultEnd;
};
//----------------------------------------------------------------------
// A wrapper class for deriving iterates from the logistic function
//----------------------------------------------------------------------
class CLogFunc
{
public:
//----------------------------------
// Construction and Destruction
//----------------------------------
CLogFunc();
CLogFunc( float fM, float fSeed );
virtual ~CLogFunc();
//------------------------
// CLogFunc Interface
//------------------------
float& Seed();
float& M();
float Iterate();
void Reset();
private:
float m_fM;
float m_fSeed;
float m_fLastIterate;
};
//--------------------------------------------------------------------------------------
// A terrain tile, used for generating the heightmaps and interrogating the results
//--------------------------------------------------------------------------------------
class CTerrain
{
public:
//----------------------------------
// Construction and Destruction
//----------------------------------
CTerrain();
virtual ~CTerrain();
//------------------------
// CTerrain Interface
//------------------------
BYTE& Grid( int iXPos, int iYPos );
int& MaxHeight();
int& MinHeight();
void ClearGrid( int iValue );
void Draw( HWND hWnd, HDC hdc, int iClientX, int iClientY );
FLOAT PickPoint( CLogFunc* pLogFunc );
void GenerateFaultLines( int iIterations, int iDepthInit, int iDepthEnd, int iFixedFaultDepth, bool bUseLogisticFunc, bool bRetainAllValues, HWND hWnd );
FLOAT CalcFractalDimension();
INT PatchMaxHeight( int iStartX, int iWidth, int iStartY, int iHeight );
FLOAT GetAvgHeight();
void SetFilename( LPSTR szNewFilename );
LPSTR GetFilename();
void Save();
void Blur( int iBlurFactor );
private:
int m_iMaxHeight;
int m_iMinHeight;
int m_iTileSq;
BYTE m_abGrid[256][256];
TCHAR m_lpstrFilename[MAX_PATH];
};
#endif