Brunot
Loading...
Searching...
No Matches
Transform.h
Go to the documentation of this file.
1// File: Transform.h
2// Description: Component that handles kinematics of the object. Updates its position + rotation every frame
3// Author(s): Ori Balashov (ori.balashov@digipen.edu) Base foundation
4// Aidan Hartman (aidan.hartman@digipen.edu) Inherited parent functionality
5// Marcelo Escamilla(marcelo.escamilla@digipen.edu) JSON serialization, and ImGui implementation
6// 2025 / 09 / 17
7// (C) Digipen 2025
8// ____ __ __ __
9// /\__ _\/\ \ /\ \/\ \
10// \/_/\ \/\ \ \___ __ \ \ \_\ \ ___ __ __ ____ __
11// \ \ \ \ \ _ `\ /'__`\ \ \ _ \ / __`\/\ \/\ \ /',__\ /'__`\
12// \ \ \ \ \ \ \ \/\ __/ \ \ \ \ \/\ \L\ \ \ \_\ \/\__, `\/\ __/
13// \ \_\ \ \_\ \_\ \____\ \ \_\ \_\ \____/\ \____/\/\____/\ \____\
14// \/_/ \/_/\/_/\/____/ \/_/\/_/\/___/ \/___/ \/___/ \/____/
15#pragma once
16
17#include "Framework/Component.h"
20
22
23
24// This class' implementation is partly inspired by Doug Schilling's 230 Engine
25
26class Transform final : public Component
27{
28public:
29 Transform();
30 Transform(const Transform&);
31 Transform(Transform&&) noexcept;
32 auto operator=(const Transform& rhs) -> Transform& = default;
33 ~Transform() override = default;
34
35 auto parentTo(GameObject* newParent) -> bool override;
36
37 auto clone() const -> std::unique_ptr<GameObject> override;
38 auto componentShowMenu() -> void override;
39 auto onUpdate(float dt) -> void override;
40
41 auto endWindow() -> void override
42 {
43 }; // for debug ImGUI
44 auto onRender() -> void override;
45 auto load(Stream& stream) -> void override;
46 auto save(Stream& stream) const -> void override;
47
48 auto move(float x, float y) -> void;
49 auto move(const Vector4D& vec) -> void;
50
51 auto scale() const -> const Vector4D&;
52 auto scale(const Vector4D& scale) -> void;
53 auto worldScale() -> Vector4D;
54 auto translation() const -> const Point2D&;
55 auto translation(const Vector4D& translation) -> void;
56 auto worldTranslation() -> Point2D;
57 auto rotation() const -> float;
58 auto rotation(float rotation) -> void;
59 auto matrix() -> AffineMatrix&;
60
61 friend auto to_json(json& j, const Transform& p) -> void;
62 friend auto from_json(const json& j, Transform& p) -> void;
63
64 /*
65 * This function receives a message that contains information to make an action
66 * The action changes the "_translation" variable
67 * TLDR Receives a message to make an action to move the transform
68 */
69 auto receiveTranslateActionMessage(const Message* message) -> Message;
70
71private:
73 float _rotation;
75
76
77 // The isDirty & AffineMatrix idea is directly taken from Doug Schilling's 230 Engine
78
79 // True if the transformation matrix needs to be recalculated.
80 bool isDirty;
81
82 // The transformation matrix resulting from concatenating the matrices
83 // Formed by scale*rotation*translation matrices
90
94 auto recalculateMatrix() -> void;
99 auto internalMatrix() -> const AffineMatrix&;
106 auto calculateAbsoluteMatrix() -> bool;
107
111 auto linkMessages() -> void;
112};
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
Vector4D Point2D
Definition Transform.h:21
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 Transform.h:27
Point2D _translation
Definition Transform.h:74
bool isDirty
Definition Transform.h:80
auto scale() const -> const Vector4D &
Definition Transform.cpp:277
auto receiveTranslateActionMessage(const Message *message) -> Message
Definition Transform.cpp:437
auto endWindow() -> void override
currently unused, but intended to but was assumed to be necessary for a proper ImGui editor
Definition Transform.h:41
auto translation() const -> const Point2D &
Definition Transform.cpp:296
Vector4D _scale
Definition Transform.h:72
auto parentTo(GameObject *newParent) -> bool override
Sets the GameObject as a child of another GameObject.
Definition Transform.cpp:63
auto rotation() const -> float
Definition Transform.cpp:317
AffineMatrix _matrix
Definition Transform.h:84
auto onRender() -> void override
called every frame after update has been called for every object.
Definition Transform.cpp:230
auto operator=(const Transform &rhs) -> Transform &=default
float _rotation
Definition Transform.h:73
auto clone() const -> std::unique_ptr< GameObject > override
makes a copy a GameObject even if it's held polymorphically
Definition Transform.cpp:68
auto save(Stream &stream) const -> void override
Implementations will load the state of a GameObject to a th::Json object.
Definition Transform.cpp:260
auto componentShowMenu() -> void override
Definition Transform.cpp:187
auto load(Stream &stream) -> void override
Implementations will load the state of a GameObject from a th::Json Object.
Definition Transform.cpp:255
Transform()
Definition Transform.cpp:29
auto worldScale() -> Vector4D
Definition Transform.cpp:288
auto onUpdate(float dt) -> void override
called once every frame.
Definition Transform.cpp:225
auto calculateAbsoluteMatrix() -> bool
computes the absolute matrix, by getting parent entity's transform
Definition Transform.cpp:354
~Transform() override=default
AffineMatrix _absoluteMatrix
A matrix that holds the absolute transform of the component, after offsetting from parent Entities.
Definition Transform.h:89
auto linkMessages() -> void
Attaches all the functions that receive messages to the messaging system.
Definition Transform.cpp:425
auto move(float x, float y) -> void
Definition Transform.cpp:265
auto recalculateMatrix() -> void
helper function for recalculating internal Matrix
Definition Transform.cpp:330
auto internalMatrix() -> const AffineMatrix &
Definition Transform.cpp:345
auto matrix() -> AffineMatrix &
Definition Transform.cpp:407
auto worldTranslation() -> Point2D
Definition Transform.cpp:307
Definition AffineMatrix.h:30
Definition Message.h:34
Definition Vector4D.h:23