52 lines
1.1 KiB
C++
52 lines
1.1 KiB
C++
#pragma once
|
|
|
|
#include <d3dx9.h>
|
|
|
|
extern IDirect3DDevice9* g_d3d_device;
|
|
|
|
class TerrainGrid
|
|
{
|
|
public:
|
|
typedef float (TerrainGrid::*iso_surface_function)(const D3DXVECTOR3&);
|
|
|
|
void Init( int StepsXZ, int StepsY, iso_surface_function pIsoSurface );
|
|
void Render();
|
|
|
|
float IsoSurfaceIsle(const D3DXVECTOR3& pos);
|
|
float IsoSurfaceCave(const D3DXVECTOR3& pos);
|
|
float IsoSurfaceCaveGround(const D3DXVECTOR3& pos);
|
|
|
|
private:
|
|
|
|
typedef struct
|
|
{
|
|
D3DXVECTOR3 p[3];
|
|
} TRIANGLE;
|
|
|
|
typedef struct
|
|
{
|
|
D3DXVECTOR3 p[8];
|
|
float val[8];
|
|
} GRIDCELL;
|
|
|
|
float PerlinNoise_2D(float x, float y, float scale);
|
|
D3DXVECTOR3 VertexInterp(float isolevel, D3DXVECTOR3 p1, D3DXVECTOR3 p2, float valp1, float valp2);
|
|
int Polygonise(GRIDCELL grid, float isolevel, TRIANGLE* triangles);
|
|
D3DXVECTOR3 GetNormal(D3DXVECTOR3 input, iso_surface_function pIsoSurface);
|
|
|
|
D3DLOCKED_BOX noiseLock;
|
|
int vertexCount;
|
|
int indexCount;
|
|
IDirect3DVertexDeclaration9* vertexDecl;
|
|
IDirect3DIndexBuffer9* indexBuffer;
|
|
IDirect3DVertexBuffer9* vertexBuffer;
|
|
};
|
|
|
|
struct TerrainVertex
|
|
{
|
|
D3DXVECTOR3 pos;
|
|
D3DXVECTOR3 normal;
|
|
D3DXVECTOR2 tex;
|
|
D3DCOLOR col;
|
|
};
|