Files
directx-plane-game/Graphics2/SharedMethods.cpp
iDunnoDev bc906064e5 Added color gradient for the terrain blend maps
Added terrainBuffer struct
Added shared methods to genereate random UV's and intensities
Added water to the terrain
Added random UV's to the shader
Removed the vector3d class since DX can deal with that stuff...
2022-05-04 14:09:59 +01:00

49 lines
1.2 KiB
C++

#include "SharedMethods.h"
XMMATRIX SharedMethods::RotateFromPoint(float x, float y, float z, XMMATRIX rotationMatrix)
{
// Translates a matrix to a point, rotates and then returns back to where it was
return XMMatrixTranslation(x, y, z) * rotationMatrix * XMMatrixTranslation(-x, -y, -z);
}
// Method so i can use normal RGB values and hopefully hex values too since im use to those
float SharedMethods::RGBValueToIntensity(int value)
{
return (float)value / 255.0f;
}
float SharedMethods::Lerp(int a, int b, int p)
{
return Lerp((float)a, (float)b, (float)p);
}
float SharedMethods::Lerp(float a, float b, float p)
{
return a + p * (b - a);
}
float SharedMethods::GenerateRandomIntensity(float min, float max)
{
float randNo = (float)rand() / (float)RAND_MAX;
float rangeDiff = max - min;
float actualNo = randNo * rangeDiff;
int roundedNo = (int)(actualNo * 100 + 0.5f);
return (float)roundedNo * 0.01f;
}
float SharedMethods::GenerateRandomUV(int min, int max)
{
int randNo = rand() % ((max - min) + 1) + min;
float finalNo;
if (randNo < max)
{
int randMan = rand() % 90;
finalNo = (float)(randNo * 0.1f) + (randMan * 0.01f);
}
else
{
finalNo = (float)randNo * 0.1f;
}
return finalNo;
}