cangine
Loading...
Searching...
No Matches
triangle.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <array>
4#include "../util/color.hpp"
5#include "../types/vector3.hpp"
6#include "vertex.hpp"
7#include "rectangle.hpp"
8
9namespace cangine {
10
14struct Triangle {
15 std::array<Vertex, 3> vertices;
16
23 constexpr Triangle(const Vertex& v1, const Vertex& v2, const Vertex& v3) noexcept
24 : vertices({v1, v2, v3}) {}
25};
26
35inline Triangle makeTriangle(const Vector3& a, const Vector3& b, const Vector3& c, const Color& color) noexcept {
36 return Triangle(
37 Vertex(a, color),
38 Vertex(b, color),
39 Vertex(c, color)
40 );
41}
42
48inline std::array<Triangle, 2> rectToTriangle(const Rectangle& r) noexcept {
49 Vector3 A = r.pos;
50 Vector3 B(r.pos.x + r.width, r.pos.y, r.pos.z);
51 Vector3 C(B.x, r.pos.y + r.height, r.pos.z);
52 Vector3 D(r.pos.x, C.y, r.pos.z);
53
54 return {
55 makeTriangle(A, B, C, r.color),
56 makeTriangle(A, C, D, r.color)
57 };
58}
59
60}
Definition audiomanager.cpp:4
std::array< Triangle, 2 > rectToTriangle(const Rectangle &r) noexcept
Splits a rectangle into the two triangles that cover it.
Definition triangle.hpp:48
Triangle makeTriangle(const Vector3 &a, const Vector3 &b, const Vector3 &c, const Color &color) noexcept
Builds a triangle from three positions sharing a single color.
Definition triangle.hpp:35
RGBA color stored as normalized floating-point components.
Definition color.hpp:12
An axis-aligned rectangle with a position, size and color.
Definition rectangle.hpp:21
A triangle defined by three vertices.
Definition triangle.hpp:14
constexpr Triangle(const Vertex &v1, const Vertex &v2, const Vertex &v3) noexcept
Constructs a triangle from three vertices.
Definition triangle.hpp:23
std::array< Vertex, 3 > vertices
The triangle's three corner vertices.
Definition triangle.hpp:15
Three-component floating-point vector.
Definition vector3.hpp:13
A single renderable vertex: position, color and texture coordinate.
Definition vertex.hpp:14