summaryrefslogtreecommitdiff
path: root/app/legion/heightfield.h
blob: 5267109deeb95d1afcbe77ef16d9bbef1787b71c (plain) (blame)
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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Heightfield class
//
// $Revision: $
// $NoKeywords: $
//===========================================================================//

#ifndef HEIGHTFIELD_H
#define HEIGHTFIELD_H

#ifdef _WIN32
#pragma once
#endif

#include "materialsystem/MaterialSystemUtil.h"


//-----------------------------------------------------------------------------
// Forward declarations
//-----------------------------------------------------------------------------
class CMeshBuilder;


//-----------------------------------------------------------------------------
// Definition of a heightfield
//-----------------------------------------------------------------------------
class CHeightField
{
public:
	CHeightField( int nPowX, int nPowY, int nPowScale );
	~CHeightField();

	// Loads the heights from a file
	bool LoadHeightFromFile( const char *pFileName );

	// Returns the max range of x, y
	int GetWidth();
	int GetHeight();

	// Returns the height of the field at a paticular (x,y)
	float GetHeight( float x, float y );
	float GetHeightAndSlope( float x, float y, float *dx, float *dy );

	// Draws the heightfield
	void Draw( );

private:
	int m_nPowX;
	int m_nPowY;
	int m_nWidth;
	int m_nHeight;
	int m_nScale;
	int m_nPowScale;
	float m_flOOScale;
	float *m_pHeightField;

	CMaterialReference m_Material;
	CTextureReference m_Texture;
};


//-----------------------------------------------------------------------------
// Returns the max range of x, y (for use in GetHeight)
//-----------------------------------------------------------------------------
inline int CHeightField::GetWidth()
{
	return m_nWidth << m_nPowScale;
}

inline int CHeightField::GetHeight()
{
	return m_nHeight << m_nPowScale;
}


#endif // HEIGHTFIELD_H