Muto 0.0.1
Cross-Platform Application Template
GitHub Repo | Muto Updates | Muto's Author
Loading...
Searching...
No Matches
Sandbox2D Class Reference

#include <Sandbox2D.h>

Inheritance diagram for Sandbox2D:
Muto::Layer

Public Member Functions

virtual void OnAttach () override
 Called when the layer is attached to the application.
 
virtual void OnDetach () override
 Called when the layer is detached from the application.
 
virtual void OnEvent (Muto::Event &e) override
 Called when an event is dispatched to the layer.
 
virtual void OnImGuiRender () override
 Called when the layer should render its ImGui components.
 
virtual void OnUpdate (Muto::Timestep ts) override
 Called every frame to update the layer with the given timestep.
 
 Sandbox2D ()
 
virtual ~Sandbox2D ()
 
- Public Member Functions inherited from Muto::Layer
const std::string & GetName () const
 Retrieves the name of the layer for debugging purposes.
 
 Layer (const std::string &name="Layer")
 Constructs a Layer with an optional name for debugging purposes.
 
virtual void OnRender ()
 Called when the layer should render its contents.
 
virtual ~Layer ()
 

Private Attributes

glm::vec4 m_BackgroundColor = { 0.1f, 0.1f, 0.1f, 1.0f }
 
Muto::OrthographicCameraController m_CameraController
 
glm::vec4 m_ClearColor = { 0.1f, 0.3f, 0.3f, 1.0f }
 
Muto::ParticleProps m_ParticleProps
 
Muto::ParticleSystem m_ParticleSystem
 
int ParticleEmitCount = 100
 

Additional Inherited Members

- Protected Attributes inherited from Muto::Layer
std::string m_DebugName
 The name of the layer assigned at creation, used for debugging.
 

Constructor & Destructor Documentation

◆ Sandbox2D()

Sandbox2D::Sandbox2D ( )
9 : Layer("Sandbox2D"), m_CameraController(1280.0f / 720.0f, true)
10{
12}
#define MU_PROFILE_FUNCTION()
Definition Instrumentor.h:240
Layer(const std::string &name="Layer")
Constructs a Layer with an optional name for debugging purposes.
Definition Layer.cpp:6
Muto::OrthographicCameraController m_CameraController
Definition Sandbox2D.h:21

References Sandbox2D().

Referenced by Sandbox2D().

◆ ~Sandbox2D()

Sandbox2D::~Sandbox2D ( )
virtual
15{
16}

Member Function Documentation

◆ OnAttach()

void Sandbox2D::OnAttach ( )
overridevirtual

Called when the layer is attached to the application.

Reimplemented from Muto::Layer.

19{
21
22 m_ParticleProps.Position = { 0.0f, 0.0f, 0.0f };
23 m_ParticleProps.Velocity = { 0.0f, 0.0f, 0.0f };
24 m_ParticleProps.VelocityVariation = { 1.0f, 1.0f, 0.0f };
25 m_ParticleProps.ColorBegin = { 1.0f, 0.5f, 0.2f, 1.0f };
26 m_ParticleProps.ColorEnd = { 0.2f, 0.3f, 0.8f, 1.0f };
32
38}
void SetZoomLevel(float level)
Definition OrthographicCameraController.h:60
A simple particle system for stress testing the renderer. This is a temporary starter particle system...
Definition ParticleSystem.h:45
void SetParticleProps(const ParticleProps &particleProps)
Definition ParticleSystem.h:53
static void SetClearColor(const glm::vec4 &color)
Sets the clear color for the renderer.
Definition RenderCommand.h:29
static void Clear()
Clears the rendering buffers.
Definition RenderCommand.h:35
glm::vec4 m_ClearColor
Definition Sandbox2D.h:23
Muto::ParticleProps m_ParticleProps
Definition Sandbox2D.h:26
Muto::ParticleSystem m_ParticleSystem
Definition Sandbox2D.h:25
float SizeBegin
Definition ParticleSystem.h:19
glm::vec3 Position
Definition ParticleSystem.h:13
float RotationVariation
Definition ParticleSystem.h:23
float Lifetime
Definition ParticleSystem.h:24
glm::vec4 ColorEnd
Definition ParticleSystem.h:18
glm::vec3 VelocityVariation
Definition ParticleSystem.h:16
glm::vec4 ColorBegin
Definition ParticleSystem.h:17
float Rotation
Definition ParticleSystem.h:22
glm::vec3 Velocity
Definition ParticleSystem.h:15
float SizeEnd
Definition ParticleSystem.h:20

References Muto::RenderCommand::Clear().

◆ OnDetach()

void Sandbox2D::OnDetach ( )
overridevirtual

Called when the layer is detached from the application.

Reimplemented from Muto::Layer.

41{
43}

◆ OnEvent()

void Sandbox2D::OnEvent ( Muto::Event &  event)
overridevirtual

Called when an event is dispatched to the layer.

Parameters
eventThe event being dispatched.

Reimplemented from Muto::Layer.

131{
133}
void OnEvent(Event &e)
Definition OrthographicCameraController.cpp:47

◆ OnImGuiRender()

void Sandbox2D::OnImGuiRender ( )
overridevirtual

Called when the layer should render its ImGui components.

Reimplemented from Muto::Layer.

92{
94
95 {
96 ImGui::Begin("Settings");
97 ImGui::Text("Renderer2D Stats:");
98 auto stats = Muto::Renderer2D::GetStats();
99 ImGui::Text("\tDraw Calls: %d", stats.DrawCalls);
100 ImGui::Text("\tQuad Count: %d", stats.QuadCount);
101 ImGui::Text("\tVertex Count: %d", stats.GetTotalVertexCount());
102 ImGui::Text("\tIndex Count: %d", stats.GetTotalIndexCount());
103 ImGui::Text("Frame Time: %.3f ms", 1000.0f / ImGui::GetIO().Framerate);
104 ImGui::Separator();
105
106 ImGui::Text("Particle System Settings:");
107 ImGui::DragInt("Particle Emit Count", &ParticleEmitCount, 1, 0, 1000);
108 ImGui::DragFloat("Particle Lifetime", &m_ParticleProps.Lifetime, 0.1f, 0.0f, 15.0f);
109 ImGui::DragFloat("Particle Lifetime Variation", &m_ParticleProps.LifetimeVariation, 0.1f, 0.0f, 10.0f);
110 ImGui::DragFloat3("Particle Velocity Variation", glm::value_ptr(m_ParticleProps.VelocityVariation), 0.05f, -10.0f, 10.0f);
111 ImGui::SliderFloat("Particle Size", &m_ParticleProps.SizeBegin, 0.05f, 5.0f);
112 ImGui::ColorEdit4("Particle Color Begin", glm::value_ptr(m_ParticleProps.ColorBegin));
113 ImGui::ColorEdit4("Particle Color End", glm::value_ptr(m_ParticleProps.ColorEnd));
114
115 if (ImGui::ColorEdit4("Background Color", glm::value_ptr(m_ClearColor)))
116 {
118 }
119 if (ImGui::Button("Clear Screen"))
120 {
123 }
124 ImGui::End();
125 }
126
127}
static Statistics GetStats()
Retrieves the current rendering statistics.
Definition Renderer2D.cpp:521
int ParticleEmitCount
Definition Sandbox2D.h:24
float LifetimeVariation
Definition ParticleSystem.h:25

References Muto::RenderCommand::Clear(), and Muto::Renderer2D::GetStats().

◆ OnUpdate()

void Sandbox2D::OnUpdate ( Muto::Timestep  ts)
overridevirtual

Called every frame to update the layer with the given timestep.

Parameters
tsThe timestep representing the time elapsed since the last update.

Reimplemented from Muto::Layer.

46{
48
49 // Update
51
52 // Render
54 {
55 MU_PROFILE_SCOPE("Renderer Prep");
57 }
58
59 {
60 MU_PROFILE_SCOPE("Particle Scene");
62
64 {
66
67 glm::vec2 mousePos = Muto::Input::GetMousePosition();
68 auto width = Muto::Application::Get().GetWindow().GetWidth();
69 auto height = Muto::Application::Get().GetWindow().GetHeight();
70
71 auto bounds = m_CameraController.GetBounds();
72 m_ParticleProps.Position.x = (mousePos.x / width) * bounds.GetWidth() - bounds.GetWidth() * 0.5f + m_CameraController.GetPosition().x;
73 m_ParticleProps.Position.y = bounds.GetHeight() * 0.5f - (mousePos.y / height) * bounds.GetHeight() + m_CameraController.GetPosition().y;
75 for (int i = 0; i < ParticleEmitCount; i++) {
77 }
79 }
80 }
81 else {
83 }
84
88 }
89}
#define MU_PROFILE_SCOPE(name)
Definition Instrumentor.h:239
Window & GetWindow()
Retrieves the application window.
Definition Application.h:110
static Application & Get()
Retrieves the singleton instance of the Application.
Definition Application.h:107
static glm::vec2 GetMousePosition()
Gets the current position of the mouse cursor as a 2D vector.
Definition WindowsInput.cpp:23
static bool IsMouseButtonPressed(int button)
Checks if the specified mouse button is currently pressed.
Definition WindowsInput.cpp:16
void OnUpdate(Timestep ts)
Definition OrthographicCameraController.cpp:21
OrthographicCameraBounds GetBounds() const
Definition OrthographicCameraController.h:40
OrthographicCamera & GetCamera()
Definition OrthographicCameraController.h:38
glm::vec3 GetPosition() const
Definition OrthographicCameraController.h:42
void OnRender()
Definition ParticleSystem.cpp:76
bool m_IsEmitting
Definition ParticleSystem.h:63
void OnUpdate(Timestep ts)
Definition ParticleSystem.cpp:24
float m_TimeSinceLastEmit
Definition ParticleSystem.h:62
void Emit(const ParticleProps &particleProps)
Definition ParticleSystem.cpp:96
static void EndScene()
Ends the current scene.
Definition Renderer2D.cpp:165
static void ResetStats()
Resets the rendering statistics.
Definition Renderer2D.cpp:516
static void BeginScene(const Camera &camera, const glm::mat4 &transform)
Begins a new scene with the given camera and transform.
Definition Renderer2D.cpp:137
virtual uint32_t GetHeight() const =0
Retrieves the height of the window.
virtual uint32_t GetWidth() const =0
Retrieves the width of the window.
@ MBC_ButtonLeft
Definition MouseButtonCodes.h:29

References Muto::RenderCommand::Clear(), Muto::Renderer2D::EndScene(), Muto::Application::Get(), Muto::Window::GetHeight(), Muto::Window::GetWidth(), Muto::Application::GetWindow(), Muto::Input::IsMouseButtonPressed(), Muto::Mouse::MBC_ButtonLeft, ParticleEmitCount, and Muto::Renderer2D::ResetStats().

Member Data Documentation

◆ m_BackgroundColor

glm::vec4 Sandbox2D::m_BackgroundColor = { 0.1f, 0.1f, 0.1f, 1.0f }
private
22{ 0.1f, 0.1f, 0.1f, 1.0f };

◆ m_CameraController

Muto::OrthographicCameraController Sandbox2D::m_CameraController
private

◆ m_ClearColor

glm::vec4 Sandbox2D::m_ClearColor = { 0.1f, 0.3f, 0.3f, 1.0f }
private
23{ 0.1f, 0.3f, 0.3f, 1.0f };

◆ m_ParticleProps

Muto::ParticleProps Sandbox2D::m_ParticleProps
private

◆ m_ParticleSystem

Muto::ParticleSystem Sandbox2D::m_ParticleSystem
private

◆ ParticleEmitCount

int Sandbox2D::ParticleEmitCount = 100
private

Referenced by OnUpdate().


The documentation for this class was generated from the following files: