VoxelEngine
 
Loading...
Searching...
No Matches
Face.h
1#pragma once
2
3#include <glm/glm.hpp>
4#include <vector>
5
6#include "Vertex.h"
7
8namespace engine {
9 enum class FaceTag {
10 All = 0,
11 Side,
12
13 Front,
14 Right,
15 Back,
16 Left,
17 Top,
18 Bottom,
19
20 Tag1,
21 Tag2,
22 Tag3,
23 Tag4,
24 Tag5,
25 Tag6,
26 Tag7,
27 Tag8,
28
29 Count
30 };
31
32 struct Face {
33 FaceTag tag;
34 std::vector<Vertex> vertices{};
35 glm::ivec3 cullDir = {0, 0, 0};
36 bool cull = false;
37 bool doubleSided = false; // When true, renders both sides (disables backface culling)
38
39 void translate(glm::vec3 t);
40 void rotate(glm::vec3 axis, float angle);
41 void data(int textureID, int ao);
42
43 void setCull(glm::ivec3 dir) {
44 cull = true;
45 cullDir = dir;
46 }
47
48 void setDoubleSided(bool enabled = true) {
49 doubleSided = enabled;
50 cull = false;
51 }
52
53 static Face TriangleFace(
54 FaceTag tag,
55 glm::vec3 p1,
56 glm::vec3 p2,
57 glm::vec3 p3,
58 glm::vec2 uv1,
59 glm::vec2 uv2,
60 glm::vec2 uv3
61 );
62
63 static Face SquareFace(
64 FaceTag tag,
65 glm::vec3 start,
66 glm::vec3 end,
67 glm::vec3 n,
68 glm::vec2 uvStart,
69 glm::vec2 uvEnd
70 );
71
72 static Face CircleFace(
73 FaceTag tag,
74 glm::vec3 center,
75 float r,
76 int segments,
77 glm::vec3 n,
78 glm::vec2 uvStart,
79 glm::vec2 uvEnd
80 );
81
82 static Face CylinderFace(
83 FaceTag tag,
84 glm::vec3 center,
85 float r,
86 float h,
87 int segments,
88 glm::vec3 n,
89 glm::vec2 uvStart,
90 glm::vec2 uvEnd
91 );
92
93 static Face RectangleFace(
94 FaceTag tag,
95 glm::vec3 start,
96 glm::vec3 end,
97 float length,
98 glm::vec3 n,
99 glm::vec2 uvStart,
100 glm::vec2 uvEnd
101 );
102 };
103
104 constexpr FaceTag IterateFaces[6] = {
105 FaceTag::Front, FaceTag::Right, FaceTag::Back, FaceTag::Left, FaceTag::Top, FaceTag::Bottom
106 };
107
108 constexpr FaceTag IterateXZFaces[4] = {
109 FaceTag::Front,
110 FaceTag::Right,
111 FaceTag::Back,
112 FaceTag::Left,
113 };
114
115 constexpr FaceTag IterateYFaces[2] = {FaceTag::Top, FaceTag::Bottom};
116
117} // namespace engine
Definition Face.h:32