YAGE
Yet Another Game Engine
body.hpp
1 /* ----------------------------------------------------------------------------
2  * body.hpp
3  *
4  * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License
5  * See file LICENSE for more details
6  * ----------------------------------------------------------------------------
7  */
8 
9 #ifndef YAGE_BODY_HPP
10 #define YAGE_BODY_HPP
11 
12 #include "Math/matrix.hpp"
13 
14 namespace yage
15 {
16 
17 class Body
18 {
19 public:
20  // gravity constant
21  static const double GRAVITY;
22 protected:
23  // center of mass of the object
24  Vector2d position_=Vector2d(0, 0);
25 
26  // mass of the object
27  double mass_=1;
28 
29  // current velocity of the object
30  Vector2d velocity_=Vector2d(0, 0);
31 
32  // boolean that defines if gravity can act on the object
33  bool gravity_=true;
34 
35  // current acceleration
36  Vector2d acceleration_=Vector2d(0, 0);
37 
38  // force acting on the body
39  Vector2d force_=Vector2d(0, 0);
40 
41 public:
42  virtual ~Body();
43 
44  // apply force to the object and update the velocity
45  virtual void applyForce(const Vector2d &force)=0;
46  virtual void update()=0;
47 
48  double xPosition() const;
49  double yPosition() const;
50 protected:
51  // protected constructor to initialize member variables
52  Body(const Vector2d &position=Vector2d(0, 0),
53  double mass=1,
54  const Vector2d &velocity=Vector2d(0, 0),
55  bool gravity=false);
56 };
57 
58 } // yage
59 
60 #endif
Definition: body.hpp:17
Definition: camera2d.hpp:17