3#include "../../Opengl-Core/include/Core.hpp"
5#include <glm/ext/vector_float3.hpp>
9inline glm::vec3 GRAVITY = {0, -9.82f, 0};
29 virtual void solve() { std::cout <<
"solve\n"; };
59 virtual void solve()
override;
78 virtual void solve()
override;
97 virtual void solve()
override;
144 template <
typename T,
typename... Args>
146 this->m_solvers.push_back(CreateShared<T>(*
this, std::forward<Args>(args)...));
176 inline std::vector<unsigned int>
getEntities()
const {
return this->m_entities; }
186 ogl::Layer(std::move(name)) {}
192 std::vector<unsigned int> m_entities{};
194 std::vector<Shared<Solver>> m_solvers{};
197 float m_lastFrame = 0;
199 float m_currentFrame = 0;
201 float m_deltaTime = 0;
235 void updateVelocity(
const unsigned int &
id,
const glm::vec3 velocity);
242 void addVelocity(
const unsigned int &
id,
const glm::vec3 offset);
280 glm::vec3
getForce(
const unsigned int &
id);
287 void updateForce(
const unsigned int &
id,
const glm::vec3 force);
294 void addForce(
const unsigned int &
id,
const glm::vec3 offset);
302 float getMass(
const unsigned int &
id);
309 void updateMass(
const unsigned int &
id,
const float &mass);
Solves all collision between entities in the given PhysicWorld.
Definition PhysicWorld.hpp:48
CollisionSolver(PhysicWorld &world)
Instance basic CollisionSolver object.
Definition PhysicWorld.hpp:67
virtual void solve() override
It gets all collisions at the current step, and calls a different method based on the collider type o...
Definition PhysicWorld.cpp:103
Simulate gravity force towards the negative y world axis.
Definition PhysicWorld.hpp:95
virtual void solve() override
This method is executed at every physic simulation step.
Definition PhysicWorld.cpp:179
GravitySolver(PhysicWorld &world)
Instance basic GravitySolver object.
Definition PhysicWorld.hpp:105
The PhysicWorld is a Layer that simulates physic objects in the scene.
Definition PhysicWorld.hpp:123
bool removeEntity(const unsigned int &id)
Removes the given entity from the simulation.
Definition PhysicWorld.cpp:224
PhysicWorld(const std::string &name="Physic World")
Construct a simulated world.
Definition PhysicWorld.hpp:185
float getWorldDeltaTime() const
Removes the given entity from the simulation.
Definition PhysicWorld.hpp:169
std::vector< unsigned int > getEntities() const
Definition PhysicWorld.hpp:176
virtual void onUpdate() override
Definition PhysicWorld.cpp:205
virtual void onAttach() override
Definition PhysicWorld.cpp:200
void addSolver(Args &&...args)
This method add a Solver to physics simulation.
Definition PhysicWorld.hpp:145
void addEntity(const unsigned int &id)
Adds the given entity to the simulation.
Definition PhysicWorld.cpp:217
It calculates all the entities position from the current velocity.
Definition PhysicWorld.hpp:76
virtual void solve() override
This method is executed at every physic simulation step.
Definition PhysicWorld.cpp:171
PositionSolver(PhysicWorld &world)
Instance basic PositionSolver object.
Definition PhysicWorld.hpp:86
A Solver defines a generic behaviour in a Physic World.
Definition PhysicWorld.hpp:22
PhysicWorld & world
the reference to the PhysicWorld
Definition PhysicWorld.hpp:42
Solver(PhysicWorld &world)
Instances basic Solver.
Definition PhysicWorld.hpp:36
virtual void solve()
This method is executed at every physic simulation step.
Definition PhysicWorld.hpp:29
This namespaces contains all utilities for entities affected by physic.
void updateVelocity(const unsigned int &id, const glm::vec3 velocity)
Updates the velocity of the given entity.
Definition PhysicWorld.cpp:253
glm::vec3 getVelocity(const unsigned int &id)
Retrieves the velocity of the given entity.
Definition PhysicWorld.cpp:246
void resetGravitySolver(const unsigned int &id)
Resets velocity on the on y-axis, acceleration and force of the given entity.
Definition PhysicWorld.cpp:236
void updateForce(const unsigned int &id, const glm::vec3 force)
Updates the force of the given entity.
Definition PhysicWorld.cpp:302
void addVelocity(const unsigned int &id, const glm::vec3 offset)
Adds the given offset to the velocity of the given entity.
Definition PhysicWorld.cpp:260
void addForce(const unsigned int &id, const glm::vec3 offset)
Adds the given offset to the force of the given entity.
Definition PhysicWorld.cpp:309
void updateAcceleration(const unsigned int &id, const glm::vec3 acceleration)
Updates the acceleration of the given entity.
Definition PhysicWorld.cpp:281
void updateRestitutionFactor(const unsigned int &id, const float &factor)
Updates the restitution factor of the given entity.
Definition PhysicWorld.cpp:267
float getMass(const unsigned int &id)
Retrieves the mass of the given entity.
Definition PhysicWorld.cpp:316
glm::vec3 getForce(const unsigned int &id)
Retrieves the force of the given entity.
Definition PhysicWorld.cpp:295
void addAcceleration(const unsigned int &id, const glm::vec3 offset)
Adds the given offset to the acceleration of the given entity.
Definition PhysicWorld.cpp:288
glm::vec3 getAcceleration(const unsigned int &id)
Retrieves the acceleration of the given entity.
Definition PhysicWorld.cpp:274
void updateMass(const unsigned int &id, const float &mass)
Updates the mass of the given entity.
Definition PhysicWorld.cpp:323
It contains all the ECS systems.