aboutsummaryrefslogtreecommitdiffstats
path: root/include/YAGE/Physics
diff options
context:
space:
mode:
Diffstat (limited to 'include/YAGE/Physics')
-rw-r--r--include/YAGE/Physics/README.org44
-rw-r--r--include/YAGE/Physics/body.hpp51
-rw-r--r--include/YAGE/Physics/collider.hpp18
-rw-r--r--include/YAGE/Physics/collisionbody.hpp8
-rw-r--r--include/YAGE/Physics/particlebody.hpp23
-rw-r--r--include/YAGE/Physics/rectanglecollider.hpp14
-rw-r--r--include/YAGE/Physics/rigidbody.hpp12
7 files changed, 94 insertions, 76 deletions
diff --git a/include/YAGE/Physics/README.org b/include/YAGE/Physics/README.org
index 0a2a5066..0620cc93 100644
--- a/include/YAGE/Physics/README.org
+++ b/include/YAGE/Physics/README.org
@@ -1,23 +1,27 @@
-#+TITLE: README
-#+DATE: <2017-04-17 Mon>
-#+AUTHOR:
-#+EMAIL: yannherklotz@yann-arch
-#+OPTIONS: ':nil *:t -:t ::t <:t H:3 \n:nil ^:t arch:headline
-#+OPTIONS: author:t c:nil creator:comment d:(not "LOGBOOK") date:t
-#+OPTIONS: e:t email:nil f:t inline:t num:t p:nil pri:nil stat:t
-#+OPTIONS: tags:t tasks:t tex:t timestamp:t toc:t todo:t |:t
-#+CREATOR: Emacs 25.1.1 (Org mode 8.2.10)
-#+DESCRIPTION:
-#+EXCLUDE_TAGS: noexport
-#+KEYWORDS:
-#+LANGUAGE: en
-#+SELECT_TAGS: export
+#+ TITLE : README
+#+ DATE : <2017 - 04 - 17 Mon>
+#+ AUTHOR:
+#+ EMAIL : yannherklotz @yann - arch
+#+ OPTIONS : ':nil *:t -:t ::t <:t H:3 \n:nil ^:t arch:headline
+#+ OPTIONS : author : t c : nil creator : comment d : (not"LOGBOOK") date : t
+#+ OPTIONS : e : t email : nil f : t inline : t num : t p : nil pri : nil stat : t
+#+ OPTIONS : tags : t tasks : t tex : t timestamp : t toc : t todo : t | : t
+#+ CREATOR : Emacs 25.1.1(Org mode 8.2.10)
+#+ DESCRIPTION:
+#+ EXCLUDE_TAGS : noexport
+#+ KEYWORDS:
+#+ LANGUAGE : en
+#+ SELECT_TAGS : export
-* Physics Engine
+*Physics Engine
-** Acceleration, speed and position
+ **Acceleration,
+ speed and position
- I have a = dv/dt; v=dp/dt;
-
- I am going to use the second order runga kutta method with a=0, b=1, alpha=1/2 and beta=1/2
-
+ I have a = dv / dt;
+v = dp / dt;
+
+I am going to use the second order runga kutta method with a = 0, b = 1,
+ alpha =
+ 1 / 2 and beta =
+ 1 / 2
diff --git a/include/YAGE/Physics/body.hpp b/include/YAGE/Physics/body.hpp
index fab28fc1..c67d2b12 100644
--- a/include/YAGE/Physics/body.hpp
+++ b/include/YAGE/Physics/body.hpp
@@ -11,43 +11,46 @@
#include "Math/matrix.hpp"
-namespace yage {
-class Body {
+namespace yage
+{
+class Body
+{
public:
- // gravity constant
- static const double GRAVITY;
+ // gravity constant
+ static const double GRAVITY;
protected:
- // center of mass of the object
- Vector2d position_ = Vector2d(0, 0);
+ // center of mass of the object
+ Vector2d position_ = Vector2d(0, 0);
- // mass of the object
- double mass_ = 1;
+ // mass of the object
+ double mass_ = 1;
- // current velocity of the object
- Vector2d velocity_ = Vector2d(0, 0);
+ // current velocity of the object
+ Vector2d velocity_ = Vector2d(0, 0);
- // boolean that defines if gravity can act on the object
- bool gravity_ = true;
+ // boolean that defines if gravity can act on the object
+ bool gravity_ = true;
- // current acceleration
- Vector2d acceleration_ = Vector2d(0, 0);
+ // current acceleration
+ Vector2d acceleration_ = Vector2d(0, 0);
- // force acting on the body
- Vector2d force_ = Vector2d(0, 0);
+ // force acting on the body
+ Vector2d force_ = Vector2d(0, 0);
public:
- // apply force to the object and update the velocity
- virtual void applyForce(const Vector2d& force) = 0;
- virtual void update() = 0;
+ // 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;
+ 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);
+ // protected constructor to initialize member variables
+ Body(Vector2d position = Vector2d(0, 0), double mass = 1,
+ Vector2d velocity = Vector2d(0, 0), bool gravity = false);
};
-} // namespace yage
+} // namespace yage
#endif
diff --git a/include/YAGE/Physics/collider.hpp b/include/YAGE/Physics/collider.hpp
index 92b90de2..7b4ff060 100644
--- a/include/YAGE/Physics/collider.hpp
+++ b/include/YAGE/Physics/collider.hpp
@@ -11,11 +11,13 @@
#include <glm/glm.hpp>
-namespace yage {
+namespace yage
+{
// The Collider class helps collision detection by providing a general shape
// for different shapes to have their own collision algorithms.
-class Collider {
+class Collider
+{
protected:
// position of the object
glm::vec2 position_;
@@ -24,16 +26,18 @@ protected:
glm::vec2 size_;
public:
- Collider(const glm::vec2& position, const glm::vec2& size)
- : position_(position), size_(size) {}
+ Collider(const glm::vec2 &position, const glm::vec2 &size)
+ : position_(position), size_(size)
+ {
+ }
// function that checks if two colliders are colliding
- virtual bool collides(const Collider& collider) const = 0;
+ virtual bool collides(const Collider &collider) const = 0;
// function that returns if a point is inside the shape
- virtual bool inside(const glm::vec2& point) const = 0;
+ virtual bool inside(const glm::vec2 &point) const = 0;
};
-} // namespace yage
+} // namespace yage
#endif
diff --git a/include/YAGE/Physics/collisionbody.hpp b/include/YAGE/Physics/collisionbody.hpp
index 5ddacacd..b7403e81 100644
--- a/include/YAGE/Physics/collisionbody.hpp
+++ b/include/YAGE/Physics/collisionbody.hpp
@@ -11,16 +11,18 @@
#include "Physics/body.hpp"
-namespace yage {
+namespace yage
+{
// a collision body will be a body that is static and not affected by gravity,
// with infinite mass
-class CollisionBody : public Body {
+class CollisionBody : public Body
+{
public:
CollisionBody();
virtual ~CollisionBody();
};
-} // yage
+} // yage
#endif
diff --git a/include/YAGE/Physics/particlebody.hpp b/include/YAGE/Physics/particlebody.hpp
index ff8b3b85..a3091773 100644
--- a/include/YAGE/Physics/particlebody.hpp
+++ b/include/YAGE/Physics/particlebody.hpp
@@ -6,26 +6,27 @@
* ----------------------------------------------------------------------------
*/
-#ifndef YAGE_PARTICLE_BODY_HPP
-#define YAGE_PARTICLE_BODY_HPP
+#ifndef YAGE_PHYSICS_PARTICLE_BODY_HPP
+#define YAGE_PHYSICS_PARTICLE_BODY_HPP
#include "Math/matrix.hpp"
+#include "Physics/body.hpp"
-#include "body.hpp"
+namespace yage
+{
-namespace yage {
-
-class ParticleBody : public Body {
+class ParticleBody : public Body
+{
public:
- ParticleBody(const Vector2d& position = Vector2d(0, 0), double mass = 1,
- const Vector2d& velocity = Vector2d(0, 0),
+ ParticleBody(const Vector2d &position = Vector2d(0, 0), double mass = 1,
+ const Vector2d &velocity = Vector2d(0, 0),
bool gravity = true);
// apply a force to the rigid body
- virtual void applyForce(const Vector2d& force);
- virtual void update();
+ void applyForce(const Vector2d &force) override;
+ void update() override;
};
-} // yage
+} // yage
#endif
diff --git a/include/YAGE/Physics/rectanglecollider.hpp b/include/YAGE/Physics/rectanglecollider.hpp
index 7f9dd7f7..ba1d8384 100644
--- a/include/YAGE/Physics/rectanglecollider.hpp
+++ b/include/YAGE/Physics/rectanglecollider.hpp
@@ -13,16 +13,18 @@
#include <glm/glm.hpp>
-namespace yage {
+namespace yage
+{
-class RectangleCollider : public Collider {
+class RectangleCollider : public Collider
+{
public:
- RectangleCollider(const glm::vec2& position, const glm::vec2& size);
+ RectangleCollider(const glm::vec2 &position, const glm::vec2 &size);
- virtual bool collides(const Collider& collider) const;
- virtual bool inside(const glm::vec2& point) const;
+ bool collides(const Collider &collider) const override;
+ bool inside(const glm::vec2 &point) const override;
};
-} // yage
+} // yage
#endif
diff --git a/include/YAGE/Physics/rigidbody.hpp b/include/YAGE/Physics/rigidbody.hpp
index fd19dc7c..6fc969f5 100644
--- a/include/YAGE/Physics/rigidbody.hpp
+++ b/include/YAGE/Physics/rigidbody.hpp
@@ -13,14 +13,16 @@
#include "particlebody.hpp"
-namespace yage {
+namespace yage
+{
-class RigidBody : public ParticleBody {
+class RigidBody : public ParticleBody
+{
public:
- RigidBody(const Vector2d& position = Vector2d(0, 0), double mass = 1,
- const Vector2d& velocity = Vector2d(0, 0), bool gravity = true);
+ RigidBody(const Vector2d &position = Vector2d(0, 0), double mass = 1,
+ const Vector2d &velocity = Vector2d(0, 0), bool gravity = true);
};
-} // yage
+} // yage
#endif