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 Sprite();
47 Sprite(const std::string& shaderName, const std::string& textureName = "",
48 const std::string& meshName = "1x1_mesh");
49 Sprite(const Sprite&) = default;
50 ~Sprite() override = default;
51
52 auto clone() const -> std::unique_ptr<GameObject> override;
53 auto componentShowMenu() -> void override; // for debug ImGUI
54 auto onUpdate(float dt) -> void override;
55
56 auto endWindow() -> void override
57 {
58 }; // for debug ImGUI
59 auto onRender() -> void override;
60 auto load(const Stream& stream) -> void override;
61 auto save(Stream& stream) const -> void override;
62
63 auto show() -> void;
64
65 auto hide() -> void;
66
67 [[nodiscard]] auto shown() const -> bool;
68
69 auto showWireframe() -> void;
70
71 auto hideWireframe() -> void;
72
73 [[nodiscard]] auto isWireframe() const -> bool;
74
75 auto showFaces() -> void;
76
77 auto hideFaces() -> void;
78
79 [[nodiscard]] auto isFaces() const -> bool;
80
81 auto setFrameIndex(unsigned int index) -> void;
82
83 auto color() -> Vector4D&;
84
85 [[nodiscard]] auto color() const -> const Vector4D&;
86
87 [[nodiscard]] auto getText() const -> std::string;
88
89 auto setText(std::string newText) -> void;
90
91 auto setOpacity(float opacity) -> void;
92
93 auto setMesh(gfx::Mesh* newMesh) -> void;
94
95 auto setShader(gfx::Shader* newShader) -> void;
96
97 auto setTexture(gfx::Texture* newTexture) -> void;
98
99 auto getOpacity() const -> float;
100
101 auto getMesh() const -> const gfx::Mesh*;
102
103 auto getShader() const -> const gfx::Shader*;
104
105 auto getTexture() const -> const gfx::Texture*;
106
107 friend auto to_json(json& j, const Sprite& p) -> void;
108 friend auto from_json(const json& j, Sprite& p) -> void;
109
110private:
111 // whether to render the sprite
112 bool visible{true};
113
114 // render the wireframe
115 bool renderLines{false};
116
117 // render the faces
118 bool renderFaces{true};
119
120 // the frame currently being displayed (for sprite sheets)
121 unsigned int frameIndex{0};
122
123 // The color of the mesh to multiply by
124 Vector4D multColor{1.f, 1.f, 1.f, 1.f};
125
126 gfx::Mesh* mesh = nullptr;
127 gfx::Shader* shader = nullptr;
129
130 std::string text;
131 unsigned maxLineCharLength = 30;
132
137 auto drawDebugLines(AffineMatrix transform) -> void;
138
142 auto drawMeshStandard(const AffineMatrix& transform) -> void;
143
148 auto drawMeshText(Transform& transform) const -> void;
149};
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
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:23
A component that renders an image on an entity, or text.
Definition Sprite.h:38
std::string text
Definition Sprite.h:130
auto endWindow() -> void override
currently unused, but intended to but was assumed to be necessary for a proper ImGui editor
Definition Sprite.h:56
auto color() -> Vector4D &
Definition Sprite.cpp:283
Sprite()
Definition Sprite.cpp:42
auto getMesh() const -> const gfx::Mesh *
Definition Sprite.cpp:328
Sprite(const Sprite &)=default
unsigned maxLineCharLength
Definition Sprite.h:131
gfx::Texture * texture
Definition Sprite.h:128
auto setTexture(gfx::Texture *newTexture) -> void
Definition Sprite.cpp:318
auto componentShowMenu() -> void override
Definition Sprite.cpp:554
auto onUpdate(float dt) -> void override
called once every frame.
Definition Sprite.cpp:68
Vector4D multColor
Definition Sprite.h:124
auto isFaces() const -> bool
Definition Sprite.cpp:273
auto drawMeshStandard(const AffineMatrix &transform) -> void
helper function to render mesh normaly
Definition Sprite.cpp:90
auto getTexture() const -> const gfx::Texture *
Definition Sprite.cpp:338
auto onRender() -> void override
called every frame after update has been called for every object.
Definition Sprite.cpp:178
auto shown() const -> bool
Definition Sprite.cpp:243
gfx::Mesh * mesh
Definition Sprite.h:126
bool renderLines
Definition Sprite.h:115
auto show() -> void
Definition Sprite.cpp:233
auto setText(std::string newText) -> void
Definition Sprite.cpp:298
auto getText() const -> std::string
Definition Sprite.cpp:293
unsigned int frameIndex
Definition Sprite.h:121
auto getShader() const -> const gfx::Shader *
Definition Sprite.cpp:333
auto isWireframe() const -> bool
Definition Sprite.cpp:258
bool visible
Definition Sprite.h:112
auto setShader(gfx::Shader *newShader) -> void
Definition Sprite.cpp:313
auto drawMeshText(Transform &transform) const -> void
helper functions to draw the sprite in text mode.
Definition Sprite.cpp:103
auto hide() -> void
Definition Sprite.cpp:238
auto clone() const -> std::unique_ptr< GameObject > override
makes a copy a GameObject even if it's held polymorphically
Definition Sprite.cpp:63
auto save(Stream &stream) const -> void override
Implementations will load the state of a GameObject to a th::Json object.
Definition Sprite.cpp:228
auto showFaces() -> void
Definition Sprite.cpp:263
auto showWireframe() -> void
Definition Sprite.cpp:248
auto getOpacity() const -> float
Definition Sprite.cpp:323
auto hideFaces() -> void
Definition Sprite.cpp:268
auto setOpacity(float opacity) -> void
Definition Sprite.cpp:303
auto setFrameIndex(unsigned int index) -> void
Definition Sprite.cpp:278
gfx::Shader * shader
Definition Sprite.h:127
auto hideWireframe() -> void
Definition Sprite.cpp:253
auto drawDebugLines(AffineMatrix transform) -> void
helper functions to draw bounding boxes for sprites
Definition Sprite.cpp:73
bool renderFaces
Definition Sprite.h:118
~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:223
auto setMesh(gfx::Mesh *newMesh) -> void
Definition Sprite.cpp:308
Definition Transform.h:27
Definition Mesh.h:56
Definition Shader.h:25
holds and manages textures for use with meshes in sprites
Definition Texture.h:33
Definition Sprite.h:25
Definition AffineMatrix.h:30
Definition Vector4D.h:23