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;
23class Mesh;
24class Shader;
25class Texture;
26
33class Sprite : public Component
34{
35public:
36 Sprite();
43 Sprite(const std::string& shaderName, const std::string& textureName = "",
44 const std::string& meshName = "1x1_mesh");
45 Sprite(const Sprite&) = default;
46 ~Sprite() override = default;
47
48 auto clone() const -> std::unique_ptr<GameObject> override;
49 auto componentShowMenu() -> void override; // for debug ImGUI
50 auto onUpdate(float dt) -> void override;
51
52 auto endWindow() -> void override
53 {
54 }; // for debug ImGUI
55 auto onRender() -> void override;
56 auto load(Stream& stream) -> void override;
57 auto save(Stream& stream) const -> void override;
58
59 auto show() -> void;
60
61 auto hide() -> void;
62
63 [[nodiscard]] auto shown() const -> bool;
64
65 auto showWireframe() -> void;
66
67 auto hideWireframe() -> void;
68
69 [[nodiscard]] auto isWireframe() const -> bool;
70
71 auto showFaces() -> void;
72
73 auto hideFaces() -> void;
74
75 [[nodiscard]] auto isFaces() const -> bool;
76
77 auto setFrameIndex(unsigned int index) -> void;
78
79 auto color() -> Vector4D&;
80
81 [[nodiscard]] auto color() const -> const Vector4D&;
82
83 [[nodiscard]] auto getText() const -> std::string;
84
85 auto setText(std::string text) -> void;
86
87 auto setMesh(Mesh* newMesh) -> void;
88
89 auto setShader(Shader* newShader) -> void;
90
91 auto setTexture(Texture* newTexture) -> void;
92
93 auto getMesh() const -> const Mesh*;
94
95 auto getShader() const -> const Shader*;
96
97 auto getTexture() const -> const Texture*;
98
99 friend auto to_json(json& j, const Sprite& p) -> void;
100 friend auto from_json(const json& j, Sprite& p) -> void;
101
102private:
103 // whether to render the sprite
104 bool visible{true};
105
106 // render the wireframe
107 bool renderLines{false};
108
109 // render the faces
110 bool renderFaces{true};
111
112 // the frame currently being displayed (for sprite sheets)
113 unsigned int frameIndex{0};
114
115 // The color of the mesh to multiply by
116 Vector4D multColor{1.f, 1.f, 1.f, 1.f};
117
118 Mesh* mesh = nullptr;
119 Shader* shader = nullptr;
120 Texture* texture = nullptr;
121
122 std::string text;
123 unsigned maxLineCharLength = 30;
124
129 auto drawDebugLines(AffineMatrix transform) -> void;
130
134 auto drawMeshStandard(const AffineMatrix& transform) -> void;
135
140 auto drawMeshText(Transform& transform) const -> void;
141};
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
Definition Mesh.h:49
Definition Shader.h:23
A component that renders an image on an entity, or text.
Definition Sprite.h:34
std::string text
Definition Sprite.h:122
auto endWindow() -> void override
currently unused, but intended to but was assumed to be necessary for a proper ImGui editor
Definition Sprite.h:52
auto getShader() const -> const Shader *
Definition Sprite.cpp:311
auto color() -> Vector4D &
Definition Sprite.cpp:271
Sprite()
Definition Sprite.cpp:41
Sprite(const Sprite &)=default
unsigned maxLineCharLength
Definition Sprite.h:123
Shader * shader
Definition Sprite.h:119
auto componentShowMenu() -> void override
Definition Sprite.cpp:532
auto onUpdate(float dt) -> void override
called once every frame.
Definition Sprite.cpp:67
Texture * texture
Definition Sprite.h:120
auto getTexture() const -> const Texture *
Definition Sprite.cpp:316
Vector4D multColor
Definition Sprite.h:116
auto isFaces() const -> bool
Definition Sprite.cpp:261
auto drawMeshStandard(const AffineMatrix &transform) -> void
helper function to render mesh normaly
Definition Sprite.cpp:89
auto onRender() -> void override
called every frame after update has been called for every object.
Definition Sprite.cpp:166
auto shown() const -> bool
Definition Sprite.cpp:231
bool renderLines
Definition Sprite.h:107
auto show() -> void
Definition Sprite.cpp:221
auto setMesh(Mesh *newMesh) -> void
Definition Sprite.cpp:291
auto setText(std::string text) -> void
Definition Sprite.cpp:286
auto getText() const -> std::string
Definition Sprite.cpp:281
auto setShader(Shader *newShader) -> void
Definition Sprite.cpp:296
unsigned int frameIndex
Definition Sprite.h:113
auto setTexture(Texture *newTexture) -> void
Definition Sprite.cpp:301
auto isWireframe() const -> bool
Definition Sprite.cpp:246
bool visible
Definition Sprite.h:104
Mesh * mesh
Definition Sprite.h:118
auto load(Stream &stream) -> void override
Implementations will load the state of a GameObject from a th::Json Object.
Definition Sprite.cpp:211
auto getMesh() const -> const Mesh *
Definition Sprite.cpp:306
auto drawMeshText(Transform &transform) const -> void
helper functions to draw the sprite in text mode.
Definition Sprite.cpp:102
auto hide() -> void
Definition Sprite.cpp:226
auto clone() const -> std::unique_ptr< GameObject > override
makes a copy a GameObject even if it's held polymorphically
Definition Sprite.cpp:62
auto save(Stream &stream) const -> void override
Implementations will load the state of a GameObject to a th::Json object.
Definition Sprite.cpp:216
auto showFaces() -> void
Definition Sprite.cpp:251
auto showWireframe() -> void
Definition Sprite.cpp:236
auto hideFaces() -> void
Definition Sprite.cpp:256
auto setFrameIndex(unsigned int index) -> void
Definition Sprite.cpp:266
auto hideWireframe() -> void
Definition Sprite.cpp:241
auto drawDebugLines(AffineMatrix transform) -> void
helper functions to draw bounding boxes for sprites
Definition Sprite.cpp:72
bool renderFaces
Definition Sprite.h:110
~Sprite() override=default
holds and manages textures for use with meshes in sprites
Definition Texture.h:31
Definition Transform.h:27
Definition AffineMatrix.h:30
Definition Vector4D.h:23