[1378] | 1 | #pragma once
|
---|
| 2 | #include <vector> // Standard-Vektor einschließen
|
---|
| 3 | #include <string>
|
---|
| 4 | #include <fstream>
|
---|
| 5 | #include "./GameManager.h"
|
---|
| 6 | #include "./Object3d.h"
|
---|
| 7 | #include <boost/shared_ptr.hpp>
|
---|
| 8 | #include <new>
|
---|
| 9 | #include <exception>
|
---|
| 10 | #include "Node.h"
|
---|
| 11 | #include "Vector.h"
|
---|
| 12 |
|
---|
| 13 | using namespace std;
|
---|
| 14 |
|
---|
| 15 | #define SPTR boost::shared_ptr
|
---|
| 16 |
|
---|
| 17 | class Terrain : public Node
|
---|
| 18 | {
|
---|
| 19 | public:
|
---|
| 20 | Terrain(void);
|
---|
| 21 | ~Terrain(void);
|
---|
| 22 | void generateTerrain(std::string filename, int _numVertsPerRow, int _numVertsPerCol);
|
---|
| 23 | float getHeight(float x, float y);
|
---|
| 24 | float getOriginalHeight(float x, float y);
|
---|
| 25 | float getSizeX();
|
---|
| 26 | float getSizeZ();
|
---|
| 27 | float getSlopeX(float x, float z);
|
---|
| 28 | float getSlopeZ(float x, float z);
|
---|
| 29 | void impact(float x, float z, int power);
|
---|
| 30 | void setTextures(std::string texture0, std::string texture1, std::string texture2);
|
---|
| 31 |
|
---|
| 32 | private:
|
---|
| 33 | struct Vertex
|
---|
| 34 | {
|
---|
| 35 | Vertex(float _x, float _y, float _z, float _nx, float _ny, float _nz, DWORD _color, float _u, float _v)
|
---|
| 36 | {
|
---|
| 37 | x = _x;
|
---|
| 38 | y = _y;
|
---|
| 39 | z = _z;
|
---|
| 40 | nx = _nx;
|
---|
| 41 | ny = _ny;
|
---|
| 42 | nz = _nz;
|
---|
| 43 | color = _color;
|
---|
| 44 | u = _u;
|
---|
| 45 | v = _v;
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | float x, y, z;
|
---|
| 49 | float nx, ny, nz;
|
---|
| 50 | DWORD color;
|
---|
| 51 | float u, v;
|
---|
| 52 |
|
---|
| 53 | enum FVF
|
---|
| 54 | {
|
---|
| 55 | FVF_Flags = D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE | D3DFVF_TEX1
|
---|
| 56 | };
|
---|
| 57 | };
|
---|
| 58 |
|
---|
| 59 | std::vector<float> readRawFile(std::string fileName);
|
---|
| 60 | void createTerrainPatches();
|
---|
| 61 | void updatePatch(int patchNumber, int x_top, int z_top, int x_bottom, int z_bottom, int powerRadius, float impactheight, int globalImpCenterX, int globalImpCenterZ, int patch_x, int patch_z);
|
---|
| 62 | Vector *getNormals();
|
---|
| 63 | void loadEffect();
|
---|
| 64 |
|
---|
| 65 | std::vector<float> heightmap;
|
---|
| 66 | std::vector<float> originalHeightmap;
|
---|
| 67 | int numVertsPerRow;
|
---|
| 68 | int numVertsPerCol;
|
---|
| 69 | float cellSpacing;
|
---|
| 70 | float heightScale;
|
---|
| 71 | int numVertices;
|
---|
| 72 | int patchSize;
|
---|
| 73 | int numberOfPatches;
|
---|
| 74 |
|
---|
| 75 | std::string texture0;
|
---|
| 76 | std::string texture1;
|
---|
| 77 | std::string texture2;
|
---|
| 78 | std::string texture3;
|
---|
| 79 |
|
---|
| 80 | std::vector<Object3d*> terrainPatches;
|
---|
| 81 |
|
---|
| 82 | Vector *normals;
|
---|
| 83 |
|
---|
| 84 | D3DMATERIAL9 *standardMats;
|
---|
| 85 | std::vector<IDirect3DTexture9*> Textures;
|
---|
| 86 |
|
---|
| 87 | //effect stuff:
|
---|
| 88 | ID3DXEffect* TerrainEffect;
|
---|
| 89 |
|
---|
| 90 | //shader technique:
|
---|
| 91 | D3DXHANDLE TexHandleTop;
|
---|
| 92 | D3DXHANDLE TexHandleSlope;
|
---|
| 93 | D3DXHANDLE TexHandleBottom;
|
---|
| 94 | D3DXHANDLE AmbientHandle;
|
---|
| 95 | D3DXHANDLE SunDirectionHandle;
|
---|
| 96 | D3DXHANDLE ShaderTechHandle;
|
---|
| 97 | };
|
---|