#pragma once
#include <raymath.h>
#include <iostream>
#include <vector>

namespace MPFW {
	namespace Physics {
		struct Box {
			Vector3 min, max;
		};
		using Polygon = std::vector<Vector3>;
		struct CollisionFace {
			Polygon polygon;
			Vector3 normal;
			bool normalCalculated = false;
		};

		struct CollisionSet {
			Box size;
			std::vector<CollisionFace> collisionFaces;
		};

		struct CollisionMapGenParams {
			int voxelLateralCount = 3;
		};

		struct CachedPolygon {
			unsigned long length;
			Vector3 normal;
			std::vector<Vector3> vertices;
		};

		struct CachedCollisionSet {
			unsigned long fileOffset, size, polyCount;
			float minx, miny, minz, maxx, maxy, maxz;
		};

		struct CachedCollisionMap {
			unsigned long cachedCollisionMapVersion = 0x01;
			unsigned long collisionSetCount;
			std::vector<CachedCollisionSet> collisionSets;
		};

		// collision maps subdivide the maps for collisions
		struct CollisionMap {
			std::vector<CollisionSet> collisionSets;
		};
		Box GenerateBoundingBoxPolygon(Polygon poly);
		CollisionMap GenerateCollisionMap(std::vector<Polygon> polygons, std::vector<Vector3> totalVertices, CollisionMapGenParams cmgp, std::string cacheName);
	}
}