Files
directx-plane-game/Graphics2/SharedMethods.h
iDunnoDev b856b43209 Added better perlin terrain generation
Added function to scatter models onto the terrain
2022-05-11 21:03:19 +01:00

69 lines
1.5 KiB
C++

#pragma once
#include "DirectXCore.h"
#include <string>
struct CBUFFER
{
XMMATRIX completeTransformation;
XMMATRIX worldTransformation;
XMFLOAT4 cameraPosition;
XMVECTOR lightVector;
XMFLOAT4 lightColor;
XMFLOAT4 ambientColor;
XMFLOAT4 diffuseCoefficient;
XMFLOAT4 specularCoefficient;
float shininess;
float opacity;
float padding[2];
};
struct TerrainPopNode
{
std::wstring nodeBaseName;
std::wstring modelName;
float scaleFactor;
};
namespace SharedMethods
{
XMMATRIX RotateFromPoint(const float x, const float y, const float z, const XMMATRIX rotationMatrix);
float RGBValueToIntensity(const int value);
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;
}
}
// Methods 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 <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;
}
float GenerateRandomIntensity(const float min, const float max);
float GenerateRandomUV(const float min, const float max);
};