aboutsummaryrefslogtreecommitdiffstats
path: root/include/YAGE/Physics/body.hpp
blob: 5a0e879eab50be45f19b88957e784ee4037c1b61 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#ifndef YAGE_BODY_HPP
#define YAGE_BODY_HPP

#include "Math/matrix.hpp"

namespace yage
{

class Body
{
public:
	// gravity constant
	static const double GRAVITY;	
protected:
	// center of mass of the object
	Vector2d position_=Vector2d(0, 0);

	// mass of the object
    double mass_=1;
	
	// current velocity of the object
	Vector2d velocity_=Vector2d(0, 0);

	// boolean that defines if gravity can act on the object
	bool gravity_=true;
	
	// current acceleration
	Vector2d acceleration_=Vector2d(0, 0);

	// force acting on the body
	Vector2d force_=Vector2d(0, 0);
	
public:
	virtual ~Body();

	// apply force to the object and update the velocity
	virtual void applyForce(const Vector2d &force)=0;
	virtual void update()=0;

	double xPosition() const;
	double yPosition() const;
protected:
	// protected constructor to initialize member variables
	Body(const Vector2d &position=Vector2d(0, 0),
	     double mass=1,
	     const Vector2d &velocity=Vector2d(0, 0),
	     bool gravity=false);
};

} // yage

#endif