aboutsummaryrefslogtreecommitdiffstats
path: root/yage/physics
diff options
context:
space:
mode:
Diffstat (limited to 'yage/physics')
-rw-r--r--yage/physics/CMakeLists.txt6
-rw-r--r--yage/physics/README.md13
-rw-r--r--yage/physics/body.cpp34
-rw-r--r--yage/physics/body.h58
-rw-r--r--yage/physics/collider.h43
-rw-r--r--yage/physics/collisionbody.h28
-rw-r--r--yage/physics/particlebody.cpp54
-rw-r--r--yage/physics/particlebody.h33
-rw-r--r--yage/physics/physics.h19
-rw-r--r--yage/physics/rectanglecollider.cpp36
-rw-r--r--yage/physics/rectanglecollider.h30
-rw-r--r--yage/physics/rigidbody.cpp20
-rw-r--r--yage/physics/rigidbody.h28
13 files changed, 0 insertions, 402 deletions
diff --git a/yage/physics/CMakeLists.txt b/yage/physics/CMakeLists.txt
deleted file mode 100644
index 46c97596..00000000
--- a/yage/physics/CMakeLists.txt
+++ /dev/null
@@ -1,6 +0,0 @@
-set(YAGE_PHYSICS_SOURCES
- physics/rectanglecollider.cpp
- physics/rigidbody.cpp
- physics/particlebody.cpp
- physics/body.cpp
- )
diff --git a/yage/physics/README.md b/yage/physics/README.md
deleted file mode 100644
index c1419155..00000000
--- a/yage/physics/README.md
+++ /dev/null
@@ -1,13 +0,0 @@
-# Physics Engine
-
-## 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.
diff --git a/yage/physics/body.cpp b/yage/physics/body.cpp
deleted file mode 100644
index 81d26699..00000000
--- a/yage/physics/body.cpp
+++ /dev/null
@@ -1,34 +0,0 @@
-/* ----------------------------------------------------------------------------
- * body.cpp
- *
- * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License
- * See file LICENSE for more details
- * ----------------------------------------------------------------------------
- */
-
-#include <yage/physics/body.h>
-
-#include <utility>
-
-namespace yage
-{
-
-const double Body::GRAVITY = -9.81;
-
-double Body::xPosition() const
-{
- return position_[0];
-}
-
-double Body::yPosition() const
-{
- return position_[1];
-}
-
-Body::Body(Vector2d position, double mass, Vector2d velocity, bool gravity)
- : position_(std::move(position)), mass_(mass),
- velocity_(std::move(velocity)), gravity_(gravity)
-{
-}
-
-} // namespace yage
diff --git a/yage/physics/body.h b/yage/physics/body.h
deleted file mode 100644
index 90682682..00000000
--- a/yage/physics/body.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/* ----------------------------------------------------------------------------
- * body.h
- *
- * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License
- * See file LICENSE for more details
- * ----------------------------------------------------------------------------
- */
-
-#ifndef YAGE_PHYSICS_BODY_H
-#define YAGE_PHYSICS_BODY_H
-
-#include <math/matrix.h>
-
-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:
- // 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(Vector2d position = Vector2d(0, 0), double mass = 1,
- Vector2d velocity = Vector2d(0, 0), bool gravity = false);
-};
-
-} // namespace yage
-
-#endif
diff --git a/yage/physics/collider.h b/yage/physics/collider.h
deleted file mode 100644
index 2fd2ff89..00000000
--- a/yage/physics/collider.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/* ----------------------------------------------------------------------------
- * collider.h
- *
- * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License
- * See file LICENSE for more details
- * ----------------------------------------------------------------------------
- */
-
-#ifndef YAGE_PHYSICS_COLLIDER_H
-#define YAGE_PHYSICS_COLLIDER_H
-
-#include <glm/glm.hpp>
-
-namespace yage
-{
-
-// The Collider class helps collision detection by providing a general shape
-// for different shapes to have their own collision algorithms.
-class Collider
-{
-protected:
- // position of the object
- glm::vec2 position_;
-
- // size of the object
- glm::vec2 size_;
-
-public:
- 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;
-
- // function that returns if a point is inside the shape
- virtual bool inside(const glm::vec2 &point) const = 0;
-};
-
-} // namespace yage
-
-#endif
diff --git a/yage/physics/collisionbody.h b/yage/physics/collisionbody.h
deleted file mode 100644
index 715c4a54..00000000
--- a/yage/physics/collisionbody.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/* ----------------------------------------------------------------------------
- * collisionbody.h
- *
- * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License
- * See file LICENSE for more details
- * ----------------------------------------------------------------------------
- */
-
-#ifndef YAGE_COLLISION_BODY_H
-#define YAGE_COLLISION_BODY_H
-
-#include "body.h"
-
-namespace yage
-{
-
-// a collision body will be a body that is static and not affected by gravity,
-// with infinite mass
-class CollisionBody : public Body
-{
-public:
- CollisionBody();
- virtual ~CollisionBody();
-};
-
-} // yage
-
-#endif
diff --git a/yage/physics/particlebody.cpp b/yage/physics/particlebody.cpp
deleted file mode 100644
index 3ccba546..00000000
--- a/yage/physics/particlebody.cpp
+++ /dev/null
@@ -1,54 +0,0 @@
-/* ----------------------------------------------------------------------------
- * particlebody.cpp
- *
- * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License
- * See file LICENSE for more details
- * ----------------------------------------------------------------------------
- */
-
-#include <yage/physics/particlebody.h>
-
-#include <cmath>
-#include <iostream>
-
-namespace yage
-{
-
-ParticleBody::ParticleBody(const Vector2d &position, double mass,
- const Vector2d &velocity, bool gravity)
- : Body(position, mass, velocity, gravity)
-{
-}
-
-void ParticleBody::applyForce(const Vector2d &force)
-{
- force_ += force;
-}
-
-void ParticleBody::update()
-{
- // set the time_step for 60fps
- double time_step = 1.0 / 60.0;
-
- // set the last acceleration
- Vector2d last_acceleration = acceleration_;
-
- // update the position of the body
- position_ += velocity_ * time_step +
- (0.5 * last_acceleration * std::pow(time_step, 2));
-
- // update the acceleration
- if (gravity_) {
- acceleration_ =
- Vector2d(force_.x() / mass_, (GRAVITY + force_.y()) / mass_);
- } else {
- acceleration_ = Vector2d(force_.x() / mass_, force_.y() / mass_);
- }
-
- Vector2d avg_acceleration = (acceleration_ + last_acceleration) / 2.0;
-
- // update the velocity of the body
- velocity_ += avg_acceleration * time_step;
-}
-
-} // namespace yage
diff --git a/yage/physics/particlebody.h b/yage/physics/particlebody.h
deleted file mode 100644
index c750c1a4..00000000
--- a/yage/physics/particlebody.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/* ----------------------------------------------------------------------------
- * particlebody.h
- *
- * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License
- * See file LICENSE for more details
- * ----------------------------------------------------------------------------
- */
-
-#ifndef YAGE_PHYSICS_PARTICLE_BODY_H
-#define YAGE_PHYSICS_PARTICLE_BODY_H
-
-#include "body.h"
-
-#include <math/matrix.h>
-
-namespace yage
-{
-
-class ParticleBody : public Body
-{
-public:
- 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
- void applyForce(const Vector2d &force) override;
- void update() override;
-};
-
-} // namespace yage
-
-#endif
diff --git a/yage/physics/physics.h b/yage/physics/physics.h
deleted file mode 100644
index 900f4b6a..00000000
--- a/yage/physics/physics.h
+++ /dev/null
@@ -1,19 +0,0 @@
-/* ----------------------------------------------------------------------------
- * physics.h
- *
- * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License
- * See file LICENSE for more details
- * ----------------------------------------------------------------------------
- */
-
-#ifndef YAGE_PHYSICS_H
-#define YAGE_PHYSICS_H
-
-#include "body.h"
-#include "collider.h"
-#include "collisionbody.h"
-#include "particlebody.h"
-#include "rectanglecollider.h"
-#include "rigidbody.h"
-
-#endif
diff --git a/yage/physics/rectanglecollider.cpp b/yage/physics/rectanglecollider.cpp
deleted file mode 100644
index d9a1a6c1..00000000
--- a/yage/physics/rectanglecollider.cpp
+++ /dev/null
@@ -1,36 +0,0 @@
-/* ----------------------------------------------------------------------------
- * rectanglecollider.cpp
- *
- * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License
- * See file LICENSE for more details
- * ----------------------------------------------------------------------------
- */
-
-#include <yage/physics/rectanglecollider.h>
-
-namespace yage
-{
-
-RectangleCollider::RectangleCollider(const glm::vec2 &position,
- const glm::vec2 &size)
- : Collider(position, size)
-{
-}
-
-bool RectangleCollider::collides(const Collider &collider) const
-{
- for (int i = position_.x; i < position_.x + size_.x; ++i) {
- for (int j = position_.y; j < position_.y + size_.y; ++j) {
- return collider.inside(glm::vec2(i, j));
- }
- }
- return false;
-}
-
-inline bool RectangleCollider::inside(const glm::vec2 &point) const
-{
- return position_.x < point.x && position_.x + size_.x > point.x &&
- position_.y < point.y && position_.y + size_.y > point.y;
-}
-
-} // namespace yage
diff --git a/yage/physics/rectanglecollider.h b/yage/physics/rectanglecollider.h
deleted file mode 100644
index c009f665..00000000
--- a/yage/physics/rectanglecollider.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/* ----------------------------------------------------------------------------
- * rectanglecollider.h
- *
- * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License
- * See file LICENSE for more details
- * ----------------------------------------------------------------------------
- */
-
-#ifndef YAGE_RECTANGLE_COLLIDER_H
-#define YAGE_RECTANGLE_COLLIDER_H
-
-#include "collider.h"
-
-#include <glm/glm.hpp>
-
-namespace yage
-{
-
-class RectangleCollider : public Collider
-{
-public:
- RectangleCollider(const glm::vec2 &position, const glm::vec2 &size);
-
- bool collides(const Collider &collider) const override;
- bool inside(const glm::vec2 &point) const override;
-};
-
-} // namespace yage
-
-#endif
diff --git a/yage/physics/rigidbody.cpp b/yage/physics/rigidbody.cpp
deleted file mode 100644
index efbef8d9..00000000
--- a/yage/physics/rigidbody.cpp
+++ /dev/null
@@ -1,20 +0,0 @@
-/* ----------------------------------------------------------------------------
- * rigidbody.cpp
- *
- * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License
- * See file LICENSE for more details
- * ----------------------------------------------------------------------------
- */
-
-#include <yage/physics/rigidbody.h>
-
-namespace yage
-{
-
-RigidBody::RigidBody(const Vector2d &position, double mass,
- const Vector2d &velocity, bool gravity)
- : ParticleBody(position, mass, velocity, gravity)
-{
-}
-
-} // namespace yage
diff --git a/yage/physics/rigidbody.h b/yage/physics/rigidbody.h
deleted file mode 100644
index 67ccb4ca..00000000
--- a/yage/physics/rigidbody.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/* ----------------------------------------------------------------------------
- * rigidbody.h
- *
- * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License
- * See file LICENSE for more details
- * ----------------------------------------------------------------------------
- */
-
-#ifndef YAGE_RIGID_BODY_H
-#define YAGE_RIGID_BODY_H
-
-#include "particlebody.h"
-
-#include <glm/glm.hpp>
-
-namespace yage
-{
-
-class RigidBody : public ParticleBody
-{
-public:
- RigidBody(const Vector2d &position = Vector2d(0, 0), double mass = 1,
- const Vector2d &velocity = Vector2d(0, 0), bool gravity = true);
-};
-
-} // namespace yage
-
-#endif