Files
directx-plane-game/Graphics2/SharedMethods.h
iDunnoDev 616f68bf8b Added Comments
Added ability to hold shift and skip the terrain generation when loading
Added ability for the perlin terrain to save a raw image of the terrain to use as a cache
2022-06-13 16:41:25 +01:00

80 lines
2.2 KiB
C++

#pragma once
#include "DirectXCore.h"
#include <string>
// The generic CBuffer used in most of the nodes
struct CBUFFER
{
XMMATRIX completeTransformation;
XMMATRIX worldTransformation;
XMFLOAT4 cameraPosition;
XMVECTOR lightVector;
XMFLOAT4 lightColor;
XMFLOAT4 ambientColor;
XMFLOAT4 diffuseCoefficient;
XMFLOAT4 specularCoefficient;
float shininess;
float opacity;
float validTexture;
float padding[1];
};
// Struct to hold the terrain populate methods variables
struct TerrainPopNode
{
std::wstring nodeBaseName;
std::wstring modelName;
float scaleFactor;
};
// The Shared methods namespace should be used for functions that are used in many places to stop duplicate code and keep things consolidated
namespace SharedMethods
{
// Function for creating a rotation matrix that should be around a specific point
XMMATRIX RotateFromPoint(const float x, const float y, const float z, const XMMATRIX rotationMatrix);
// Function for converting a 255 style RGB value to its normalised intensity value
float RGBValueToIntensity(const int value);
// Template function for clamping a number between 2 values, the template allows this to be used for any numeric type
template <typename T = float> T Clamp(const T value, const T min, const T max)
{
if (value < min)
{
return min;
}
else if (value > max)
{
return max;
}
else
{
return value;
}
}
// Template function for lerping values
template <typename T = float> float Lerp(const T a, const T b, const float p)
{
return (float)a + p * ((float)b - (float)a);
}
// Template function for doing a cubic interpolate, i think this is unused currently but i did play around with the idea
template <typename T = float> float CubicInterpolate(const T n0, const T n1, const T n2, const T n3, const float a)
{
float p = ((float)n3 - (float)n2) - ((float)n0 - (float)n1);
float q = ((float)n0 - (float)n1) - p;
float r = (float)n2 - (float)n0;
float s = (float)n1;
return p * a * a * a + q * a * a + r * a + s;
}
// Function for generating a random float value
float GenerateRandomIntensity(const float min, const float max);
// Function for generating random UV values
float GenerateRandomUV(const float min, const float max);
};