utility 2026.1.9
A comprehensive C++ utilities library tailored for the development of modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
vertex.hpp
1/*
2** ETIB PROJECT, 2025
3** evan
4** File description:
5** Vertex
6*/
7
8#pragma once
9
10#include <cmath>
11#include <ostream>
12#include <type_traits>
13
15#include "utility/graphic/position.hpp"
16
17#include "utility/math/vector.hpp"
18
19namespace utility::graphic
20{
21
26 template<typename Type>
29
37 template<CanBeVectorComponent VectorComponent> class Vertex
38 {
39 private:
41 _position;
44 _textureCoordinates;
45 Color32Bit _color;
46
47 public:
57 Vertex(void)
58 : _position {}
59 , _normal {}
60 , _textureCoordinates {}
61 , _color {}
62 {
63 }
64
74 const math::Vector<VectorComponent, 2> &textureCoordinates,
75 const Color32Bit &color)
76 : _position(position)
77 , _normal(normal)
78 , _textureCoordinates(textureCoordinates)
79 , _color(color)
80 {
81 }
82
88 {
89 _position = position;
90 }
91
97 {
98 return _position;
99 }
100
106 {
107 _normal = normal;
108 }
109
115 {
116 return _normal;
117 }
118
124 const math::Vector<VectorComponent, 2> &textureCoordinates)
125 {
126 _textureCoordinates = textureCoordinates;
127 }
128
134 {
135 return _textureCoordinates;
136 }
137
142 void setColor(const Color32Bit &color)
143 {
144 _color = color;
145 }
146
152 {
153 return _color;
154 }
155
165 const Position<VectorComponent> &position,
167 const math::Vector<VectorComponent, 2> &textureCoordinates,
168 const Color32Bit &color)
169 {
170 _position = position;
171 _normal = normal;
172 _textureCoordinates = textureCoordinates;
173 _color = color;
174 return *this;
175 }
176
182 bool hasUnitNormal(VectorComponent epsilon = VectorComponent {
183 1e-5 }) const
184 {
185 const VectorComponent normSquared = _normal[0] * _normal[0]
186 + _normal[1] * _normal[1] + _normal[2] * _normal[2];
187 return std::abs(normSquared - VectorComponent { 1 }) <= epsilon;
188 }
189
195 bool operator==(const Vertex &other) const
196 {
197 return _position == other._position && _normal == other._normal
198 && _textureCoordinates == other._textureCoordinates
199 && _color == other._color;
200 }
201
207 bool operator!=(const Vertex &other) const
208 {
209 return !(*this == other);
210 }
211 };
212
216 using VertexF = Vertex<float>;
217
221 using VertexD = Vertex<double>;
222
229 std::ostream &operator<<(std::ostream &stream, const VertexF &vertex);
230
237 std::ostream &operator<<(std::ostream &stream, const VertexD &vertex);
238
239} // namespace utility::graphic
Position in 3D space represented as a vector of three PositionComponentType components (x,...
Definition position.hpp:53
Vertex type containing common mesh attributes.
Definition vertex.hpp:38
bool hasUnitNormal(VectorComponent epsilon=VectorComponent { 1e-5 }) const
Check if the normal is approximately unit length.
Definition vertex.hpp:182
Color32Bit getColor(void) const
Get vertex color.
Definition vertex.hpp:151
void setPosition(const Position< VectorComponent > &position)
Set vertex position.
Definition vertex.hpp:87
Vertex & setAttributes(const Position< VectorComponent > &position, const math::Vector< VectorComponent, 3 > &normal, const math::Vector< VectorComponent, 2 > &textureCoordinates, const Color32Bit &color)
Set all vertex attributes at once.
Definition vertex.hpp:164
void setColor(const Color32Bit &color)
Set vertex color.
Definition vertex.hpp:142
bool operator!=(const Vertex &other) const
Inequality comparison.
Definition vertex.hpp:207
void setNormal(const math::Vector< VectorComponent, 3 > &normal)
Set vertex normal.
Definition vertex.hpp:105
math::Vector< VectorComponent, 2 > getTextureCoordinates(void) const
Get vertex texture coordinates.
Definition vertex.hpp:133
bool operator==(const Vertex &other) const
Equality comparison.
Definition vertex.hpp:195
Position< VectorComponent > getPosition(void) const
Get vertex position.
Definition vertex.hpp:96
math::Vector< VectorComponent, 3 > getNormal(void) const
Get vertex normal.
Definition vertex.hpp:114
Vertex(const Position< VectorComponent > &position, const math::Vector< VectorComponent, 3 > &normal, const math::Vector< VectorComponent, 2 > &textureCoordinates, const Color32Bit &color)
Construct from all vertex attributes.
Definition vertex.hpp:72
Vertex(void)
Default constructor.
Definition vertex.hpp:57
void setTextureCoordinates(const math::Vector< VectorComponent, 2 > &textureCoordinates)
Set vertex texture coordinates.
Definition vertex.hpp:123
3D vector class inheriting from glm::vec3.
Definition vector.hpp:83
RGBA color representation with blending and manipulation operations.
Concept to constrain position component type.
Definition position.hpp:43
Concept to constrain color component type.
Definition vertex.hpp:27
Concept to constrain vector component type.
Definition vector.hpp:72