NasNas
An intuitive and beginner friendly 2D game framework for C++
PhysicsComponent.hpp
1 // Created by Modar Nasser on 15/06/2020.
2 
3 #pragma once
4 
5 #include <SFML/System/Vector2.hpp>
6 
7 namespace ns::ecs {
8 
10  public:
11  explicit PhysicsComponent(float mass=1.f, const sf::Vector2f& linear_damping={1.f, 1.f}, float angular_damping=1.f);
12 
13  float mass = 1.f;
14 
15  sf::Vector2f linear_velocity = {0.f, 0.f};
16  sf::Vector2f linear_damping = {1.f, 1.f};
17 
18  float angular_velocity = 0.f;
19  float angular_damping = 1.f;
20 
21  void applyForce(sf::Vector2f force);
22  void applyTorque(float torque);
23 
24  auto getDirection() const -> sf::Vector2f;
25  auto getAngle() const -> float;
26 
27  auto getMomentum() const -> sf::Vector2f;
28 
29  void update();
30 
31  private:
32  sf::Vector2f m_forces;
33  float m_torque = 0.f;
34  float m_angle = 0.f;
35  };
36 
37  using Physics = PhysicsComponent;
38 
39 }