src/geometry.h

Mon, 02 Mar 2020 11:08:13 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Mon, 02 Mar 2020 11:08:13 +0200
changeset 66
77c819262b7a
parent 64
f99d52b1646b
child 71
198d25fe4e21
permissions
-rw-r--r--

added a method to find out if the view is perpendicular to grid

#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, const float epsilon = 1e-6f);
	glm::vec3 scalingVector(const glm::mat4 matrix);
	struct ScalingExtract
	{
		glm::vec3 scaling;
		glm::mat4 unscaled;
	};
	ScalingExtract extractScaling(const glm::mat4& matrix);
}

mercurial