Saga
Saga Game Engine
Loading...
Searching...
No Matches
triangle.h
Go to the documentation of this file.
1#pragma once
2
3#include <glm/vec3.hpp>
4#include <glm/vec2.hpp>
5#include <optional>
6
7namespace Saga::Geometry {
13 struct Triangle {
14 glm::vec3 a,b,c;
15
16 std::optional<glm::vec3> normal_cached;
17
26 glm::vec3 toBarycentric(const glm::vec3 pos);
27
34 glm::vec2 toUV(const glm::vec3 pos);
35
40 glm::vec3 getNormal();
41 };
42
56 std::optional<float> rayTriangleIntersection(const glm::vec3& origin, const glm::vec3& rayDirection, Triangle triangle);
57
68 glm::vec3 getClosestPoint(const glm::vec3 pointPos, Triangle triangle);
69}
glm::vec3 getClosestPoint(const glm::vec3 pointPos, Triangle triangle)
Find the closest point between a point and a triangle.
Definition: triangle.cpp:55
std::optional< float > rayTriangleIntersection(const glm::vec3 &origin, const glm::vec3 &rayDirection, Triangle triangle)
Find the intersection time t where a ray and triangle intersects. Does not detect intersections to th...
Definition: triangle.cpp:37
Definition: box.cpp:6
Represents a 3D triangle, equipped with some utility functions.
Definition: triangle.h:13
glm::vec2 toUV(const glm::vec3 pos)
Convert a point from cartesian to UV coordinate.
Definition: triangle.cpp:25
glm::vec3 a
Definition: triangle.h:14
glm::vec3 getNormal()
Get the normal of this triangle.
Definition: triangle.cpp:30
std::optional< glm::vec3 > normal_cached
Definition: triangle.h:16
glm::vec3 b
Definition: triangle.h:14
glm::vec3 c
Definition: triangle.h:14
glm::vec3 toBarycentric(const glm::vec3 pos)
Convert a point from cartesian to barycentric coordinate with respect to the current triangle.
Definition: triangle.cpp:7