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 static auto bindLuaTypes(sol::state& lua) -> void;
24 static auto getEnum() -> ComponentTypeEnum
25 {
26 return cPhysics;
27 }
28 Physics();
29 Physics(const Physics& p) = default;
30 auto operator=(const Physics& p) -> Physics& = default;
31
32 auto clone() const -> std::unique_ptr<GameObject> override;
33
34 auto componentShowMenu() -> void override;; // for debug ImGUI
35 // This function is the most inspired by Doug Schilling's engine
36 auto onUpdate(float dt) -> void override;
37
38 auto endWindow() -> void override
39 {
40 }; // for debug ImGUI
41
42 auto onRender() -> void override;
43 auto load(const Stream& stream) -> void override;
44 auto save(Stream& stream) const -> void override;
45
46 auto acceleration(const Vector4D& acceleration) -> void;
47 auto acceleration(void) const -> const Vector4D&;
48
49 auto prevTranslation(const Vector4D& oldTranslation) -> void;
50 auto prevTranslation(void) const -> const Vector4D&;
51
52 auto velocity(const Vector4D& velocity) -> void;
53 auto velocity(void) const -> const Vector4D&;
54
55 auto rotationalVelocity(float rotationalVelocity) -> void;
56 auto rotationalVelocity(void) const -> float;
57
61 friend auto to_json(json& j, const Physics& p) -> void;
65 friend auto from_json(const json& j, Physics& p) -> void;
66 friend struct nlohmann::adl_serializer<Physics>;
67
68private:
69 // These variables are heavily influenced by Doug Schilling's 230 Engine
70
71 // Acceleration = inverseMass * (sum of forces)
73 // Previous position
76 // How fast the object is rotating, stored in degrees
78};
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
Definition Physics.h:21
auto velocity(void) const -> const Vector4D &
Definition Physics.cpp:140
auto endWindow() -> void override
currently unused, but intended to but was assumed to be necessary for a proper ImGui editor
Definition Physics.h:38
auto componentShowMenu() -> void override
Definition Physics.cpp:63
auto load(const Stream &stream) -> void override
Implementations will load the state of a GameObject from a th::Json Object.
Definition Physics.cpp:105
auto onUpdate(float dt) -> void override
called once every frame.
Definition Physics.cpp:78
static auto getEnum() -> ComponentTypeEnum
Definition Physics.h:24
Physics(const Physics &p)=default
Physics()
Definition Physics.cpp:49
friend auto to_json(json &j, const Physics &p) -> void
Definition Physics.cpp:155
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:110
auto clone() const -> std::unique_ptr< GameObject > override
makes a copy a GameObject even if it's held polymorphically
Definition Physics.cpp:58
auto rotationalVelocity(void) const -> float
Definition Physics.cpp:150
Vector4D _velocity
Definition Physics.h:75
float _rotationalVelocity
Definition Physics.h:77
auto onRender() -> void override
called every frame after update has been called for every object.
Definition Physics.cpp:101
auto prevTranslation(void) const -> const Vector4D &
Definition Physics.cpp:130
auto acceleration(void) const -> const Vector4D &
Definition Physics.cpp:120
Vector4D _prevTranslation
Definition Physics.h:74
Vector4D _acceleration
Definition Physics.h:72
static auto bindLuaTypes(sol::state &lua) -> void
Definition Physics.cpp:24
friend auto from_json(const json &j, Physics &p) -> void
Definition Physics.cpp:171
Definition Vector4D.h:28