src/geometry.h

Thu, 27 Feb 2020 11:56:41 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Thu, 27 Feb 2020 11:56:41 +0200
changeset 57
5c0005f63319
parent 55
cb81ecb5fb23
child 58
b7841cd31fb7
permissions
-rw-r--r--

use glm::unProject to implement screenToModelCoordinates

#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