Brunot
Loading...
Searching...
No Matches
Sprite.h
Go to the documentation of this file.
1// File: Sprite.h
2// Description: Implementation of the sprite component, a component for handeling the rendering of
3// objects
4// Author(s): Ori Balashov (ori.balashov@digipen.edu) Pair Programmed with Aidan Hartman
5// Aidan Hartman (aidan.hartman@digipen.edu) Pair Programmed with Ori Balashov
6// Marcelo Escamilla(marcelo.escamilla@digipen.edu) JSON serialization, and ImGui implementation
7// 2025 / 09 / 18
8// (C) Digipen 2025
9// ____ __ __ __
10// /\__ _\/\ \ /\ \/\ \
11// \/_/\ \/\ \ \___ __ \ \ \_\ \ ___ __ __ ____ __
12// \ \ \ \ \ _ `\ /'__`\ \ \ _ \ / __`\/\ \/\ \ /',__\ /'__`\
13// \ \ \ \ \ \ \ \/\ __/ \ \ \ \ \/\ \L\ \ \ \_\ \/\__, `\/\ __/
14// \ \_\ \ \_\ \_\ \____\ \ \_\ \_\ \____/\ \____/\/\____/\ \____\
15// \/_/ \/_/\/_/\/____/ \/_/\/_/\/___/ \/___/ \/___/ \/____/
16#pragma once
17
18#include "Framework/Component.h"
20#include "System/Json.h"
21
22class Transform;
23
24namespace gfx
25{
26class Mesh;
27class Shader;
28class Texture;
29}
30
37class Sprite : public Component
38{
39public:
40
41 static auto bindLuaTypes(sol::state& lua) -> void;
42 static auto getEnum() -> ComponentTypeEnum
43 {
44 return cSprite;
45 }
46
47 Sprite();
54 Sprite(const std::string& shaderName, const std::string& textureName = "",
55 const std::string& meshName = "1x1_mesh");
56 Sprite(const Sprite&) = default;
57 ~Sprite() override = default;
58
59 auto clone() const -> std::unique_ptr<GameObject> override;
60 auto componentShowMenu() -> void override; // for debug ImGUI
61 auto onUpdate(float dt) -> void override;
62
63 auto endWindow() -> void override
64 {
65 }; // for debug ImGUI
66 auto onRender() -> void override;
67 auto load(const Stream& stream) -> void override;
68 auto save(Stream& stream) const -> void override;
69
70 auto show() -> void;
71
72 auto hide() -> void;
73
74 auto setShown( bool ) -> void;
75
76 [[nodiscard]] auto shown() const -> bool;
77
78 auto showWireframe() -> void;
79
80 auto hideWireframe() -> void;
81
82 [[nodiscard]] auto isWireframe() const -> bool;
83
84 auto showFaces() -> void;
85
86 auto hideFaces() -> void;
87
88 [[nodiscard]] auto isFaces() const -> bool;
89
90 auto setFrameIndex(unsigned int index) -> void;
91
92 auto color() -> Vector4D&;
93
94 [[nodiscard]] auto color() const -> const Vector4D&;
95
96 [[nodiscard]] auto getText() const -> std::string;
97
98 auto setText(std::string newText) -> void;
99
100 // Operates on a scale of 0-1
101 auto setOpacity(float opacity) -> void;
102
103 auto setMesh(gfx::Mesh* newMesh) -> void;
104
105 auto setShader(gfx::Shader* newShader) -> void;
106
107 auto setTexture(gfx::Texture* newTexture) -> void;
108
109 auto setTexture(const std::string& textureName) -> void;
110
111 auto getOpacity() const -> float;
112
113 auto getMesh() const -> const gfx::Mesh*;
114
115 auto getShader() const -> const gfx::Shader*;
116
117 auto getTexture() const -> const gfx::Texture*;
118
119 friend auto to_json(json& j, const Sprite& p) -> void;
120 friend auto from_json(const json& j, Sprite& p) -> void;
121
122private:
123 // whether to render the sprite
124 bool visible{true};
125
126 // render the wireframe
127 bool renderLines{false};
128
129 // render the faces
130 bool renderFaces{true};
131
132 // the frame currently being displayed (for sprite sheets)
133 unsigned int frameIndex{0};
134
135 // The color of the mesh to multiply by
136 Vector4D multColor{1.f, 1.f, 1.f, 1.f};
137
138 gfx::Mesh* mesh = nullptr;
139 gfx::Shader* shader = nullptr;
141
142 std::string text;
143 unsigned maxLineCharLength = 30;
144
149 auto drawDebugLines(AffineMatrix transform) -> void;
150
154 auto drawMeshStandard(const AffineMatrix& transform) -> void;
155
160 auto drawMeshText(Transform& transform) const -> void;
161};
auto to_json(json &j, const AudioObject &a) -> void
Definition AudioObject.cpp:376
auto from_json(const json &j, AudioObject &a) -> void
Definition AudioObject.cpp:387
sys::Json Stream
Definition AudioObject.h:20
The base class for components, holding all of their shared All components should inherit from this.
nlohmann::json json
Definition Json.cpp:19
ComponentTypeEnum
This enum lists out every type of component we have.
Definition Component.h:39
Component(ComponentTypeEnum type, const char *typeName)
Definition Component.cpp:72
GameObject(std::string typeName, gobj::Type parentType, gobj::Type type)
constructor for gameobject.
Definition GameObject.cpp:24
A component that renders an image on an entity, or text.
Definition Sprite.h:38
auto setShown(bool) -> void
Definition Sprite.cpp:281
std::string text
Definition Sprite.h:142
auto endWindow() -> void override
currently unused, but intended to but was assumed to be necessary for a proper ImGui editor
Definition Sprite.h:63
static auto getEnum() -> ComponentTypeEnum
Definition Sprite.h:42
auto color() -> Vector4D &
Definition Sprite.cpp:326
Sprite()
Definition Sprite.cpp:76
auto getMesh() const -> const gfx::Mesh *
Definition Sprite.cpp:381
Sprite(const Sprite &)=default
unsigned maxLineCharLength
Definition Sprite.h:143
gfx::Texture * texture
Definition Sprite.h:140
auto setTexture(gfx::Texture *newTexture) -> void
Definition Sprite.cpp:361
auto componentShowMenu() -> void override
Definition Sprite.cpp:481
auto onUpdate(float dt) -> void override
called once every frame.
Definition Sprite.cpp:102
Vector4D multColor
Definition Sprite.h:136
auto isFaces() const -> bool
Definition Sprite.cpp:316
auto drawMeshStandard(const AffineMatrix &transform) -> void
helper function to render mesh normally
Definition Sprite.cpp:128
auto getTexture() const -> const gfx::Texture *
Definition Sprite.cpp:391
auto onRender() -> void override
called every frame after update has been called for every object.
Definition Sprite.cpp:216
auto shown() const -> bool
Definition Sprite.cpp:286
gfx::Mesh * mesh
Definition Sprite.h:138
bool renderLines
Definition Sprite.h:127
auto show() -> void
Definition Sprite.cpp:271
auto setText(std::string newText) -> void
Definition Sprite.cpp:341
auto getText() const -> std::string
Definition Sprite.cpp:336
unsigned int frameIndex
Definition Sprite.h:133
auto getShader() const -> const gfx::Shader *
Definition Sprite.cpp:386
auto isWireframe() const -> bool
Definition Sprite.cpp:301
bool visible
Definition Sprite.h:124
auto setShader(gfx::Shader *newShader) -> void
Definition Sprite.cpp:356
auto drawMeshText(Transform &transform) const -> void
helper functions to draw the sprite in text mode.
Definition Sprite.cpp:141
auto hide() -> void
Definition Sprite.cpp:276
auto clone() const -> std::unique_ptr< GameObject > override
makes a copy a GameObject even if it's held polymorphically
Definition Sprite.cpp:97
auto save(Stream &stream) const -> void override
Implementations will load the state of a GameObject to a th::Json object.
Definition Sprite.cpp:266
auto showFaces() -> void
Definition Sprite.cpp:306
auto showWireframe() -> void
Definition Sprite.cpp:291
auto getOpacity() const -> float
Definition Sprite.cpp:376
auto hideFaces() -> void
Definition Sprite.cpp:311
auto setOpacity(float opacity) -> void
Definition Sprite.cpp:346
auto setFrameIndex(unsigned int index) -> void
Definition Sprite.cpp:321
gfx::Shader * shader
Definition Sprite.h:139
static auto bindLuaTypes(sol::state &lua) -> void
Definition Sprite.cpp:45
auto hideWireframe() -> void
Definition Sprite.cpp:296
auto drawDebugLines(AffineMatrix transform) -> void
helper functions to draw bounding boxes for sprites
Definition Sprite.cpp:107
bool renderFaces
Definition Sprite.h:130
~Sprite() override=default
auto load(const Stream &stream) -> void override
Implementations will load the state of a GameObject from a th::Json Object.
Definition Sprite.cpp:261
auto setMesh(gfx::Mesh *newMesh) -> void
Definition Sprite.cpp:351
Definition Transform.h:28
Definition Mesh.h:56
Definition Shader.h:25
holds and manages textures for use with meshes in sprites
Definition Texture.h:33
Definition FlipCardAction.h:25
Definition AffineMatrix.h:30
Definition Vector4D.h:28