Added follow cam

Added "Controlled" mesh classes
Added Global Lighting Class
Added Gamepad controls
Split terrain nodes into Height and Perlin classes
Fixed Splitmesh node stuff
This commit is contained in:
iDunnoDev
2022-05-09 17:50:22 +01:00
committed by iDunnoDev
parent bc906064e5
commit f6bba67897
58 changed files with 1743 additions and 351 deletions

View File

@ -2,6 +2,7 @@
#include "DirectXFramework.h"
#include <fstream>
#include <vector>
#include <ctime>
#include "ColorGradient.h"
#include "DDSTextureLoader.h"
#include "WICTextureLoader.h"
@ -17,21 +18,44 @@ typedef struct TerrainVertex
XMFLOAT2 BlendMapTexCoord;
} TerrainVertex;
struct TCBUFFER
{
XMMATRIX completeTransformation;
XMMATRIX worldTransformation;
XMFLOAT4 cameraPosition;
XMVECTOR lightVector;
XMFLOAT4 lightColor;
XMFLOAT4 ambientColor;
XMFLOAT4 diffuseCoefficient;
XMFLOAT4 specularCoefficient;
float shininess;
float opacity;
float waterHeight;
float waterShininess;
XMFLOAT4 waterColor;
float padding[4];
};
class TerrainNode : public SceneNode
{
public:
TerrainNode(wstring name, wstring heightMap, wstring seed, float waterHeight = 150.0f, wstring waterNormalMap = L"Textures\\waterNormals.bmp", int widthX = 1023, int widthZ = 1023, int cellSizeX = 10, int cellSizeZ = 10);
TerrainNode(wstring name, wstring seed, float waterHeight = 150.0f, int widthX = 1023, int widthZ = 1023, int cellSizeX = 10, int cellSizeZ = 10);
void SetAmbientLight(XMFLOAT4 ambientLight);
void SetWaterColor(XMFLOAT4 waterColor);
void SetDirectionalLight(FXMVECTOR lightVector, XMFLOAT4 lightColor);
void SetCameraPosition(XMFLOAT4 cameraPosition);
bool Initialise(void);
bool virtual Initialise(void);
void Render(void);
void Shutdown(void);
void virtual Shutdown(void);
float GetHeightAtPoint(float x, float z, bool waterCollide = false);
bool CheckXBoundary(float x);
bool CheckZBoundary(float z);
protected:
bool _initError = false;
private:
int _widthX;
int _widthZ;
@ -41,25 +65,22 @@ private:
int _cellSizeX;
int _cellSizeZ;
bool _usedHeightMap;
float _waterHeight;
UINT _polygonsCount;
UINT _indiciesCount;
UINT _indicesCount;
UINT _vertexCount;
float _terrainStartX;
float _terrainStartZ;
float _terrainEndX;
float _terrainEndZ;
wstring _heightMap;
wstring _seedString;
unsigned int _seedHash;
vector<TerrainVertex> _terrainVerts;
vector<int> _indices;
vector<int> _indices;
vector<float> _heightValues;
XMFLOAT4 _ambientLight;
@ -86,12 +107,12 @@ private:
ComPtr<ID3D11RasterizerState> _defaultRasteriserState;
ComPtr<ID3D11RasterizerState> _wireframeRasteriserState;
ComPtr<ID3D11ShaderResourceView> _rngNoiseMap;
ComPtr<ID3D11ShaderResourceView> _snowTest;
ComPtr<ID3D11ShaderResourceView> _waterNormalMap;
wstring _waterNormalMapName;
XMFLOAT4 _waterColor;
void GenerateTerrainData();
void virtual GenerateTerrainData();
void GenerateTerrainNormals();
void GenerateBuffers();
void BuildShaders();
void BuildVertexLayout();
@ -101,8 +122,7 @@ private:
void LoadTerrainTextures();
void GenerateBlendMap();
bool LoadHeightMap(wstring heightMapFilename);
float GetHeightMapValueAt(int index);
float GetHeightValueAt(int index);
void AddNormalToVertex(int row, int col, int vertexIndex, XMVECTOR normal);
void BuildExtraMaps();