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
Circle.cpp
Go to the documentation of this file.
1
7
8#include <glad/glad.h>
9#include <glm/gtc/constants.hpp>
10#include <glm/trigonometric.hpp>
11
12#include "galaxy/meta/Memory.hpp"
13
14#include "Circle.hpp"
15
16namespace galaxy
17{
18 namespace graphics
19 {
21 : m_fragments {20.0f}
22 , m_radius {10.0f}
23
24 {
25 m_mode = GL_LINE_LOOP;
26 }
27
29 : Shape {std::move(c)}
30 {
31 this->m_radius = c.m_radius;
32 this->m_fragments = c.m_fragments;
33 }
34
36 {
37 if (this != &c)
38 {
39 Shape::operator=(std::move(c));
40
41 this->m_radius = c.m_radius;
42 this->m_fragments = c.m_fragments;
43 }
44
45 return *this;
46 }
47
49 {
50 }
51
52 void Circle::create(const float fragments, const float radius)
53 {
56
57 // Thanks to https://stackoverflow.com/a/33859443
58 // For help with maths.
59
60 auto count = 0u;
61 const auto increment = (2.0f * glm::pi<float>()) / m_fragments;
62
63 meta::vector<unsigned int> indices;
64 meta::vector<graphics::Vertex> vertices;
65
66 for (float angle = 0.0f; angle <= (2.0f * glm::pi<float>()); angle += increment)
67 {
68 graphics::Vertex vertex;
69 vertex.m_pos.x = (m_radius * glm::cos(angle)) + m_radius;
70 vertex.m_pos.y = (m_radius * glm::sin(angle) + m_radius);
71
72 vertices.emplace_back(vertex);
73 indices.push_back(count);
74
75 count++;
76 }
77
78 m_width = m_radius * 2.0f;
79 m_height = m_radius * 2.0f;
81 }
82
83 float Circle::fragments() const
84 {
85 return m_fragments;
86 }
87
88 float Circle::radius() const
89 {
90 return m_radius;
91 }
92 } // namespace graphics
93} // namespace galaxy
thread_local const float vertices[]
Video.cpp galaxy.
Definition Video.cpp:19
thread_local const unsigned int indices[]
Definition Video.cpp:21
Circle()
Constructor.
Definition Circle.cpp:20
float m_radius
Radius.
Definition Circle.hpp:76
Circle & operator=(Circle &&)
Move assignment operator.
Definition Circle.cpp:35
virtual ~Circle()
Destructor.
Definition Circle.cpp:48
float m_fragments
Points making up circumference.
Definition Circle.hpp:71
float radius() const
Get radius.
Definition Circle.cpp:88
float fragments() const
Get fragments.
Definition Circle.cpp:83
void create(const float fragments, const float radius)
Create the circle.
Definition Circle.cpp:52
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