#include "SharedMethods.h"

XMMATRIX SharedMethods::RotateFromPoint(const float x, const float y, const float z, const 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(const int value)
{
	return (float)value / 255.0f;
}

// Method to generate a random intensity rating between 2 floats
float SharedMethods::GenerateRandomIntensity(const float min, const 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;
}

// Method for genering random UV's, maybe get rid of this in future
float SharedMethods::GenerateRandomUV(const float min, const float max)
{		
	return SharedMethods::Clamp<float>((float)(rand() % (int)(max * 100.0f)) * 0.01f, (float)min, (float)max);
}