#include "Morault_Rendering.h"
#include <rlgl.h>

void Morault::Rendering::DrawWall(Vector2 a, Vector2 b, int heightFloor, int heightCeiling, Texture2D texture, float renderScale)
{
	rlSetTexture(texture.id);
	rlBegin(RL_QUADS);
	rlColor4ub(255, 255, 255, 255);
	rlNormal3f(-(b.y - a.y), 0, (b.x - a.x));

	rlTexCoord2f(1.0f, 0.0f); rlVertex3f(a.x * renderScale,
										 heightCeiling * renderScale,
										 a.y * renderScale);
	rlTexCoord2f(0.0f, 0.0f); rlVertex3f(b.x * renderScale,
										 heightCeiling * renderScale,
										 b.y * renderScale);
	rlTexCoord2f(0.0f, 1.0f); rlVertex3f(b.x * renderScale,
										 heightFloor * renderScale,
										 b.y * renderScale);
	rlTexCoord2f(1.0f, 1.0f); rlVertex3f(a.x * renderScale,
										 heightFloor * renderScale,
										 a.y * renderScale);
	rlEnd();
	rlSetTexture(0);
}

void Morault::Rendering::DrawFloor(Vector2 a, Vector2 b, Vector2 c, int heightFloor, Texture2D texture, float renderScale)
{
	rlSetTexture(texture.id);
	
	rlBegin(RL_QUADS); // workaround because triangles were stubborn with textures

	rlColor4ub(255, 255, 255, 255);
	rlNormal3f(0, 1, 0);


	rlTexCoord2f(a.x / 128, a.y / 128);
	rlVertex3f(a.x * renderScale, heightFloor * renderScale, a.y * renderScale);

	rlTexCoord2f(b.x / 128, b.y / 128);
	rlVertex3f(b.x * renderScale, heightFloor * renderScale, b.y * renderScale);

	rlTexCoord2f(c.x / 128, c.y / 128);
	rlVertex3f(c.x * renderScale, heightFloor * renderScale, c.y * renderScale);

	rlTexCoord2f(c.x / 128, c.y / 128);
	rlVertex3f(c.x * renderScale, heightFloor * renderScale, c.y * renderScale);

	rlEnd();

	rlSetTexture(0);
}

void Morault::Rendering::DrawCeiling(Vector2 a, Vector2 b, Vector2 c, int heightCeiling, Texture2D texture, float renderScale)
{
	rlSetTexture(texture.id);

	rlBegin(RL_QUADS); // workaround because triangles were stubborn with textures

	rlColor4ub(255, 255, 255, 255);
	rlNormal3f(0, 1, 0);


	rlTexCoord2f(a.x / 128, a.y / 128);
	rlVertex3f(a.x * renderScale, heightCeiling * renderScale, a.y * renderScale);

	rlTexCoord2f(c.x / 128, c.y / 128);
	rlVertex3f(c.x * renderScale, heightCeiling * renderScale, c.y * renderScale);

	rlTexCoord2f(b.x / 128, b.y / 128);
	rlVertex3f(b.x * renderScale, heightCeiling * renderScale, b.y * renderScale);

	rlTexCoord2f(b.x / 128, b.y / 128);
	rlVertex3f(b.x * renderScale, heightCeiling * renderScale, b.y * renderScale);

	rlEnd();

	rlSetTexture(0);
}
