SPARK  0.1.0
A general purpose game engine written in C++.
Loading...
Searching...
No Matches
Circle.h
1#pragma once
2
3#include "spark/core/Application.h"
4#include "spark/core/components/Transform.h"
5
6#include "spark/math/Vector2.h"
7#include "spark/rtti/HasRtti.h"
8
9namespace spark::core::components
10{
14 class Circle final : public Component
15 {
16 DECLARE_SPARK_RTTI(Circle, Component)
17
18 public:
19 float radius = 25;
20
21 public:
26 explicit Circle(GameObject* parent)
27 : Component(parent) {}
28
34 explicit Circle(GameObject* parent, const float radius)
35 : Component(parent), radius(radius) {}
36
37 void render() const override
38 {
40
41 // Get the transform matrix for the circle
42 auto transform_matrix = gameObject()->transform()->matrix();
43 transform_matrix = glm::translate(transform_matrix, {radius, radius, 0.0f});
44 transform_matrix = glm::scale(transform_matrix, {radius * 2, radius * 2, 1.0f});
45
46 // Draw the circle
47 core::Application::Instance()->window().renderer().drawCircle(transform_matrix, radius);
48 }
49 };
50}
51
52IMPLEMENT_SPARK_RTTI(spark::core::components::Circle)
static Application * Instance()
Gets the instance of the application.
Definition Application.cpp:53
Window & window()
Gets the window for the application.
Definition Application.cpp:120
A component that can be attached to a GameObject to provide additional functionality.
Definition Component.h:20
GameObject * gameObject()
Gets the GameObject that the component is attached to.
Definition Component.cpp:19
virtual void render() const
Renders the component.
Definition Component.h:59
A GameObject is any object in the game. It contains a list of components that provides functionality ...
Definition GameObject.h:26
components::Transform * transform() const
Gets the transform component of the GameObject.
Definition GameObject.cpp:63
Renderer2D< render::vk::VulkanBackend > & renderer() const
Gets the renderer of the window.
Definition Window.cpp:469
A simple component to render a circle.
Definition Circle.h:15
Circle(GameObject *parent)
Creates a new circle component . Defaults to a radius of 25.
Definition Circle.h:26
Circle(GameObject *parent, const float radius)
Creates a new circle component .
Definition Circle.h:34
void render() const override
Renders the component.
Definition Circle.h:37
glm::mat4 matrix() const
Gets the transformation matrix of the transform.
Definition Transform.h:40