Brunot
Loading...
Searching...
No Matches
Physics.h
Go to the documentation of this file.
1// File: Physics.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)
4// 2025 / 09 / 22
5// (C) Digipen 2025
6// ____ __ __ __
7// /\__ _\/\ \ /\ \/\ \
8// \/_/\ \/\ \ \___ __ \ \ \_\ \ ___ __ __ ____ __
9// \ \ \ \ \ _ `\ /'__`\ \ \ _ \ / __`\/\ \/\ \ /',__\ /'__`\
10// \ \ \ \ \ \ \ \/\ __/ \ \ \ \ \/\ \L\ \ \ \_\ \/\__, `\/\ __/
11// \ \_\ \ \_\ \_\ \____\ \ \_\ \_\ \____/\ \____/\/\____/\ \____\
12// \/_/ \/_/\/_/\/____/ \/_/\/_/\/___/ \/___/ \/___/ \/____/
13#pragma once
14
15#include "Framework/Component.h"
17
18
19// This class is partly inspired by the physics component Doug Schilling's 230 Engine
20class Physics : public Component
21{
22public:
23 Physics();
24 Physics(const Physics& p) = default;
25 auto operator=(const Physics& p) -> Physics& = default;
26
27 auto clone() const -> std::unique_ptr<GameObject> override;
28
29 auto componentShowMenu() -> void override;; // for debug ImGUI
30 // This function is the most inspired by Doug Schilling's engine
31 auto onUpdate(float dt) -> void override;
32
33 auto endWindow() -> void override
34 {
35 }; // for debug ImGUI
36
37 auto onRender() -> void override;
38 auto load(Stream& stream) -> void override;
39 auto save(Stream& stream) const -> void override;
40
41 auto acceleration(const Vector4D& acceleration) -> void;
42 auto acceleration(void) const -> const Vector4D&;
43
44 auto prevTranslation(const Vector4D& oldTranslation) -> void;
45 auto prevTranslation(void) const -> const Vector4D&;
46
47 auto velocity(const Vector4D& velocity) -> void;
48 auto velocity(void) const -> const Vector4D&;
49
50 auto rotationalVelocity(float rotationalVelocity) -> void;
51 auto rotationalVelocity(void) const -> float;
52
56 friend auto to_json(json& j, const Physics& p) -> void;
60 friend auto from_json(const json& j, Physics& p) -> void;
61 friend struct nlohmann::adl_serializer<Physics>;
62
63private:
64 // These variables are heavily influenced by Doug Schilling's 230 Engine
65
66 // Acceleration = inverseMass * (sum of forces)
68 // Previous position
71 // How fast the object is rotating, stored in degrees
73};
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 Physics.h:21
auto velocity(void) const -> const Vector4D &
Definition Physics.cpp:113
auto endWindow() -> void override
currently unused, but intended to but was assumed to be necessary for a proper ImGui editor
Definition Physics.h:33
auto componentShowMenu() -> void override
Definition Physics.cpp:36
auto onUpdate(float dt) -> void override
called once every frame.
Definition Physics.cpp:51
auto load(Stream &stream) -> void override
Implementations will load the state of a GameObject from a th::Json Object.
Definition Physics.cpp:78
Physics(const Physics &p)=default
Physics()
Definition Physics.cpp:22
friend auto to_json(json &j, const Physics &p) -> void
Definition Physics.cpp:128
auto operator=(const Physics &p) -> Physics &=default
auto save(Stream &stream) const -> void override
Implementations will load the state of a GameObject to a th::Json object.
Definition Physics.cpp:83
auto clone() const -> std::unique_ptr< GameObject > override
makes a copy a GameObject even if it's held polymorphically
Definition Physics.cpp:31
auto rotationalVelocity(void) const -> float
Definition Physics.cpp:123
Vector4D _velocity
Definition Physics.h:70
float _rotationalVelocity
Definition Physics.h:72
auto onRender() -> void override
called every frame after update has been called for every object.
Definition Physics.cpp:74
auto prevTranslation(void) const -> const Vector4D &
Definition Physics.cpp:103
auto acceleration(void) const -> const Vector4D &
Definition Physics.cpp:93
Vector4D _prevTranslation
Definition Physics.h:69
Vector4D _acceleration
Definition Physics.h:67
friend auto from_json(const json &j, Physics &p) -> void
Definition Physics.cpp:144
Definition Vector4D.h:23