SimpleFastOpenAtomicVisualiser
Loading...
Searching...
No Matches
triangle.h
Go to the documentation of this file.
1#ifndef TRIANGLE__H
2#define TRIANGLE__H
3
4#include <cstdint>
5#include <vector>
6#include <array>
7#include <cmath>
8
9#include <glm/glm.hpp>
10
15template <class T> using vec3 = glm::vec<3,T,glm::packed_highp>;
16
22template <class T>
24{
25public:
26
32 {
33 x = vec3<T> (0);
34 y = vec3<T> (0);
35 z = vec3<T> (0);
36 };
37
48
54 std::array<vec3<T>, 3> getVertices() const
55 {
56 std::array<vec3<T>, 3> v = {};
57 for (uint32_t j = 0; j < 3; j++)
58 {
59 v[0][j] = x[j];
60 v[1][j] = y[j];
61 v[2][j] = z[j];
62 }
63 return v;
64 }
65
71 void setVertices(std::array<vec3<T>, 3> v)
72 {
73 for (uint32_t j = 0; j < 3; j++)
74 {
75 x[j] = v[0][j];
76 y[j] = v[1][j];
77 z[j] = v[2][j];
78 }
79 }
80
87 {
88 vec3<T> u = y-x;
89 vec3<T> v = z-x;
90 return glm::normalize(glm::cross(u, v));
91 }
92
96};
97
98#endif /* TRIANGLE__H */
A 3D triangle.
Definition triangle.h:24
vec3< T > z
Definition triangle.h:95
std::array< vec3< T >, 3 > getVertices() const
Get the Vertices of the Triangle.
Definition triangle.h:54
Triangle(vec3< T > v1, vec3< T > v2, vec3< T > v3)
Construct a new Triangle with the given vertices.
Definition triangle.h:45
vec3< T > normal() const
Calculate the Triangle's normal vector.
Definition triangle.h:86
Triangle()
Construct a new empty Triangle.
Definition triangle.h:31
void setVertices(std::array< vec3< T >, 3 > v)
Set the Vertices of the Triangle.
Definition triangle.h:71
vec3< T > y
Definition triangle.h:94
vec3< T > x
Definition triangle.h:93
glm::vec< L, float, glm::qualifier::highp > vec
Definition commandLine.h:214
glm::vec< 3, T, glm::packed_highp > vec3
Definition triangle.h:15