galaxy 1.0.0
Real-Time C++23 Game Programming Framework. Built on data-driven design principles and agile software engineering.
Loading...
Searching...
No Matches
Polygon.cpp
Go to the documentation of this file.
1
7
8#include <glad/glad.h>
9
10#include "Polygon.hpp"
11
12namespace galaxy
13{
14 namespace graphics
15 {
17 {
18 m_mode = GL_LINE_LOOP;
19 m_width = 0.0f;
20 m_height = 0.0f;
21 }
22
24 : Shape {std::move(p)}
25 {
26 this->m_points = std::move(p.m_points);
27 }
28
30 {
31 if (this != &p)
32 {
33 Shape::operator=(std::move(p));
34 this->m_points = std::move(p.m_points);
35 }
36
37 return *this;
38 }
39
41 {
42 }
43
44 void Polygon::create(const meta::vector<glm::vec2>& points)
45 {
47
48 meta::vector<unsigned int> indices;
49 meta::vector<graphics::Vertex> vertices;
50
51 auto count = 0u;
52 for (const auto& point : m_points)
53 {
54 if (point.x > m_width)
55 {
56 m_width = point.x;
57 }
58
59 if (point.y > m_height)
60 {
61 m_height = point.y;
62 }
63
64 graphics::Vertex vertex;
65 vertex.m_pos = point;
66
67 vertices.emplace_back(vertex);
68 indices.push_back(count);
69
70 count++;
71 }
72
74 }
75
76 const meta::vector<glm::vec2>& Polygon::points() const
77 {
78 return m_points;
79 }
80 } // namespace graphics
81} // namespace galaxy
thread_local const float vertices[]
Video.cpp galaxy.
Definition Video.cpp:19
thread_local const unsigned int indices[]
Definition Video.cpp:21
A closed loop line collection of points. I.e. A square, triangle, etc.
Definition Polygon.hpp:22
Polygon()
Constructor.
Definition Polygon.cpp:16
virtual ~Polygon()
Destructor.
Definition Polygon.cpp:40
void create(const meta::vector< glm::vec2 > &points)
Create shape.
Definition Polygon.cpp:44
meta::vector< glm::vec2 > m_points
List of points.
Definition Polygon.hpp:63
Polygon & operator=(Polygon &&)
Move assignment operator.
Definition Polygon.cpp:29
const meta::vector< glm::vec2 > & points() const
Get list of points.
Definition Polygon.cpp:76
A generic 2D shape.
Definition Shape.hpp:22
VertexArray m_vao
Vertex Array Object.
Definition Shape.hpp:105
Shape & operator=(Shape &&)
Move assignment operator.
Definition Shape.cpp:32
unsigned int m_mode
Type to render i.e. GL_LINES, GL_TRIANGLES, etc.
Definition Shape.hpp:90
float m_height
Cached height.
Definition Shape.hpp:100
float m_width
Cached width.
Definition Shape.hpp:95
void buffer(std::span< Vertex > vertices, std::span< unsigned int > indicies)
Create vertex array object.
Animated.cpp galaxy.
Definition Animated.cpp:16
STL namespace.
Represents a single vertex point.
Definition Vertex.hpp:25
glm::vec2 m_pos
Position..
Definition Vertex.hpp:29