Oxygen Engine
Modern C++ 3D Engine using OpenGL
Loading...
Searching...
No Matches
vertex.h
1#ifndef OE_SCENE_VERTEX_H
2#define OE_SCENE_VERTEX_H
3
4#include "../common.h"
5
6#include <vector>
7#include <map>
8#include <glm/vec2.hpp>
9#include <glm/vec3.hpp>
10#include <glm/vec4.hpp>
11
12namespace oe::scene
13{
17 typedef uint32_t index_t;
18
22 template<typename T>
23 concept SimpleVertex = requires(T t)
24 {
25 {t.position} -> std::same_as<glm::vec3&>;
26 };
27
31 template<typename T>
32 concept ComplexVertex = requires(T t)
33 {
34 {t.position} -> std::same_as<glm::vec3&>;
35 {t.tex_coords} -> std::same_as<glm::vec2&>;
36 {t.normal} -> std::same_as<glm::vec3&>;
37 };
38
42 struct Vertex
43 {
45 glm::vec3 position = glm::vec3(0.0);
46
48 glm::vec2 tex_coords = glm::vec2(0.0);
49
51 glm::vec2 lm_coords = glm::vec2(0.0);
52
54 glm::vec3 normal = glm::vec3(0.0);
55
57 glm::vec3 tangent = glm::vec3(0.0);
58
63 glm::vec3 bitangent = glm::vec3(0.0);
64
65 bool operator==(const Vertex& other) const
66 {
67 return this->position == other.position;
68 }
69
70 friend Vertex operator*(const Vertex& lhs, const float ratio)
71 {
72 return Vertex({
73 .position = lhs.position * ratio,
74 .tex_coords = lhs.tex_coords * ratio,
75 .lm_coords = lhs.lm_coords * ratio,
76 .normal = lhs.normal * ratio,
77 .tangent = lhs.tangent * ratio,
78 .bitangent = lhs.bitangent * ratio
79 });
80 }
81
82 friend Vertex operator*(const float ratio, const Vertex& rhs)
83 {
84 // Same as above (Vertex multiplication by a ratio is commutative)
85 return rhs * ratio;
86 }
87
88 friend Vertex operator+(const Vertex& lhs, const Vertex& rhs)
89 {
90 return Vertex({
91 .position = lhs.position + rhs.position,
92 .tex_coords = lhs.tex_coords + rhs.tex_coords,
93 .lm_coords = lhs.lm_coords + rhs.lm_coords,
94 .normal = lhs.normal + rhs.normal,
95 .tangent = lhs.tangent + rhs.tangent,
96 .bitangent = lhs.bitangent + rhs.bitangent
97 });
98 }
99 };
100
105 {
107 glm::vec3 position = glm::vec3(0.0);
108
110 glm::vec2 tex_coords = glm::vec2(0.0);
111
113 glm::vec2 lm_coords = glm::vec2(0.0);
114
116 glm::vec3 normal = glm::vec3(0.0);
117
119 glm::vec3 tangent = glm::vec3(0.0);
120
125 glm::vec3 bitangent = glm::vec3(0.0);
126
128 glm::ivec4 bones = glm::ivec4(0);
129
131 glm::vec4 weights = glm::vec4(0.0);
132
133 bool operator==(const Vertex& other) const
134 {
135 return this->position == other.position;
136 }
137
138 friend SkinnedVertex operator*(const SkinnedVertex& lhs, const float ratio)
139 {
140 return SkinnedVertex({
141 .position = lhs.position * ratio,
142 .tex_coords = lhs.tex_coords * ratio,
143 .lm_coords = lhs.lm_coords * ratio,
144 .normal = lhs.normal * ratio,
145 .tangent = lhs.tangent * ratio,
146 .bitangent = lhs.bitangent * ratio
147 });
148 }
149
150 friend SkinnedVertex operator*(const float ratio, const SkinnedVertex& rhs)
151 {
152 // Same as above (Vertex multiplication by a ratio is commutative)
153 return rhs * ratio;
154 }
155
156 friend SkinnedVertex operator+(const SkinnedVertex& lhs, const SkinnedVertex& rhs)
157 {
158 return SkinnedVertex({
159 .position = lhs.position + rhs.position,
160 .tex_coords = lhs.tex_coords + rhs.tex_coords,
161 .lm_coords = lhs.lm_coords + rhs.lm_coords,
162 .normal = lhs.normal + rhs.normal,
163 .tangent = lhs.tangent + rhs.tangent,
164 .bitangent = lhs.bitangent + rhs.bitangent
165 });
166 }
167 };
168}
169
170#endif
Definition vertex.h:32
Definition vertex.h:23
Scene related management (Render-agnostic Geometry, Manger, etc...)
Definition debug.h:19
uint32_t index_t
Definition vertex.h:17
Definition vertex.h:105
glm::vec4 weights
Definition vertex.h:131
glm::vec3 bitangent
Definition vertex.h:125
glm::ivec4 bones
Definition vertex.h:128
glm::vec2 lm_coords
Definition vertex.h:113
glm::vec3 position
Definition vertex.h:107
glm::vec2 tex_coords
Definition vertex.h:110
glm::vec3 tangent
Definition vertex.h:119
glm::vec3 normal
Definition vertex.h:116
Definition vertex.h:43
glm::vec2 lm_coords
Definition vertex.h:51
glm::vec3 tangent
Definition vertex.h:57
glm::vec3 bitangent
Definition vertex.h:63
glm::vec3 normal
Definition vertex.h:54
glm::vec3 position
Definition vertex.h:45
glm::vec2 tex_coords
Definition vertex.h:48