src/geometry.h

Wed, 26 Feb 2020 22:26:05 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Wed, 26 Feb 2020 22:26:05 +0200
changeset 56
fad4a5dd8dee
parent 55
cb81ecb5fb23
child 58
b7841cd31fb7
permissions
-rw-r--r--

PartRenderer::modelToScreenCoordinates FINALLY WORKS

#pragma once
#include "basics.h"

namespace geom
{
	struct Plane
	{
		glm::vec3 normal;
		glm::vec3 anchor;
	};

	struct Line
	{
		glm::vec3 direction;
		glm::vec3 anchor;
	};

	template<int N>
	struct Polygon
	{
		glm::vec3 points[N];
	};

	inline const glm::vec3 origin = {0, 0, 0};
	inline const Plane XY = {{0, 0, 1}, origin};
	inline const Plane XZ = {{0, 1, 0}, origin};
	inline const Plane YZ = {{1, 0, 0}, origin};
	using Triangle = Polygon<3>;

	Line lineFromPoints(const glm::vec3& point_1, const glm::vec3 point_2);
	Plane planeFromTriangle(const Triangle& triangle);
	glm::vec3 normalVector(const Triangle& triangle);
	std::optional<glm::vec3> linePlaneIntersection(const Line& line, const Plane& plane);
}

mercurial