Gamedev Framework (gf)  0.5.0
A C++11 framework for 2D games
PhysicsBody.h
1 #ifndef GF_PHYSICS_BODY_H
2 #define GF_PHYSICS_BODY_H
3 
4 #include <memory>
5 
6 #include "Circ.h"
7 #include "PhysicsGeometry.h"
8 #include "Polygon.h"
9 #include "Rect.h"
10 #include "Time.h"
11 #include "Transform.h"
12 #include "Vector.h"
13 
14 namespace gf {
15 #ifndef DOXYGEN_SHOULD_SKIP_THIS
16 inline namespace v1 {
17 #endif
18 
19  struct RenderStates;
20  class RenderTarget;
21  struct Penetration;
22 
36  class GF_API PhysicsBody {
37  public:
41  enum Type {
44  };
45 
52  PhysicsBody(const PhysicsGeometry& geometry, Type type = Dynamic);
53 
59  Type getType() const {
60  return m_type;
61  }
62 
68  void step(float dt);
69 
78  void render(RenderTarget& target, const RenderStates& states) const;
79 
91  return m_position;
92  }
93 
99  void setPosition(Vector2f position);
100 
106  void move(Vector2f offset);
107 
114  return m_linearVelocity;
115  }
116 
122  void setLinearVelocity(Vector2f velocity) {
123  m_linearVelocity = velocity;
124  }
125 
133  void applyLinearImpulse(Vector2f impulse);
134 
141  return m_acceleration;
142  }
143 
151  void applyForce(Vector2f force);
152 
158  float getAngle() const {
159  return m_angle;
160  }
161 
167  void setAngle(float angle) {
168  m_angle = angle;
169  }
170 
176  void turn(float arc) {
177  m_angle += arc;
178  }
179 
183  void setVelocityFromAngle();
184 
192  void updateTransform();
193 
200  const Transform& getTransform() const;
201 
202 
215  void setRestitution(float restitution) {
216  m_restitution = restitution;
217  }
218 
224  float getRestitution() const {
225  return m_restitution;
226  }
227 
233  void setStaticFriction(float friction) {
234  m_staticFriction = friction;
235  }
236 
242  float getStaticFriction() const {
243  return m_staticFriction;
244  }
245 
251  void setDynamicFriction(float friction) {
252  m_dynamicFriction = friction;
253  }
254 
260  float getDynamicFriction() const {
261  return m_dynamicFriction;
262  }
263 
269  void setLinearDamping(float damping) {
270  m_linearDamping = damping;
271  }
272 
278  float getLinearDamping() const {
279  return m_linearDamping;
280  }
281 
289  void setDensity(float density);
290 
298  float getInverseMass() const {
299  return m_inverseMass;
300  }
301 
310  bool collidesWith(const PhysicsBody& other, Penetration& p) const;
311 
312  private:
313  Type m_type;
314 
315  Vector2f m_position;
316  Vector2f m_linearVelocity;
317  Vector2f m_acceleration;
318 
319  float m_angle;
320 
321  float m_inverseMass;
322 
323  float m_restitution;
324  float m_staticFriction;
325  float m_dynamicFriction;
326  float m_linearDamping;
327 
328  Transform m_transform;
329 
330  const PhysicsGeometry& m_geometry;
331  };
332 
333 #ifndef DOXYGEN_SHOULD_SKIP_THIS
334 }
335 #endif
336 }
337 
338 #endif // GF_PHYSICS_BODY_H
Vector2f getLinearVelocity() const
Get the linear velocity of the body.
Definition: PhysicsBody.h:113
The row has a dynamic layout.
void setLinearDamping(float damping)
Set the linear damping of the body.
Definition: PhysicsBody.h:269
float getInverseMass() const
Get the inverse mass of the body.
Definition: PhysicsBody.h:298
Base class for all render targets (window, texture, ...)
Definition: RenderTarget.h:66
Type getType() const
Get the type of the body.
Definition: PhysicsBody.h:59
Vector2f getAcceleration() const
Get the acceleration of the body.
Definition: PhysicsBody.h:140
Define the states used for drawing to a RenderTarget.
Definition: RenderStates.h:82
A physics body.
Definition: PhysicsBody.h:36
A simple transformation (rotation then translation)
Definition: Transform.h:204
float getAngle() const
Get the angle of the body.
Definition: PhysicsBody.h:158
Type
Type of body.
Definition: PhysicsBody.h:41
float getDynamicFriction() const
Get the dynamic friction coefficient of the body.
Definition: PhysicsBody.h:260
float getLinearDamping() const
Get the linear damping of the body.
Definition: PhysicsBody.h:278
Static body with infinite mass.
Definition: PhysicsBody.h:42
The namespace for gf classes.
Definition: Action.h:34
float getStaticFriction() const
Get the static friction coefficient of the body.
Definition: PhysicsBody.h:242
float angle(Direction direction)
Get an angle from a direction.
void setRestitution(float restitution)
Set the restitution of the body of the body.
Definition: PhysicsBody.h:215
Vector2f getPosition() const
Get the position of the body.
Definition: PhysicsBody.h:90
Data about the collision between two objects.
Definition: Collision.h:43
void setAngle(float angle)
Set the angle of the body.
Definition: PhysicsBody.h:167
void turn(float arc)
Change the angle of the body.
Definition: PhysicsBody.h:176
The geometry of a physics body.
Definition: PhysicsGeometry.h:46
void setDynamicFriction(float friction)
Set the dynamic friction coefficient of the body.
Definition: PhysicsBody.h:251
float getRestitution() const
Get the restitution of the body of the body.
Definition: PhysicsBody.h:224
Dynamic bodies with finite mass.
Definition: PhysicsBody.h:43
void setStaticFriction(float friction)
Set the static friction coefficient of the body.
Definition: PhysicsBody.h:233
void setLinearVelocity(Vector2f velocity)
Set the linear velocity of the body.
Definition: PhysicsBody.h:122