diff options
author | Yann Herklotz <ymherklotz@gmail.com> | 2017-04-15 22:38:14 +0100 |
---|---|---|
committer | Yann Herklotz <ymherklotz@gmail.com> | 2017-04-15 22:38:14 +0100 |
commit | 325d8c2348b5cabe32d1e90ce28a049f278e3f8c (patch) | |
tree | d90a4f188a7489f46b9835eae007c9b45f6627c2 /src | |
parent | daa032e2f6c86da16902f654055d8b040d7670bb (diff) | |
download | YAGE-325d8c2348b5cabe32d1e90ce28a049f278e3f8c.tar.gz YAGE-325d8c2348b5cabe32d1e90ce28a049f278e3f8c.zip |
Added test bench
Diffstat (limited to 'src')
-rw-r--r-- | src/rectanglecollider.cpp | 24 | ||||
-rw-r--r-- | src/resourcemanager.cpp | 2 | ||||
-rw-r--r-- | src/rigidbody.cpp | 16 |
3 files changed, 41 insertions, 1 deletions
diff --git a/src/rectanglecollider.cpp b/src/rectanglecollider.cpp new file mode 100644 index 00000000..812b10d1 --- /dev/null +++ b/src/rectanglecollider.cpp @@ -0,0 +1,24 @@ +#include "Physics/rectanglecollider.hpp" + +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; +} + +} // yage diff --git a/src/resourcemanager.cpp b/src/resourcemanager.cpp index 06f71078..4105f4e4 100644 --- a/src/resourcemanager.cpp +++ b/src/resourcemanager.cpp @@ -7,7 +7,7 @@ TextureCache ResourceManager::texture_cache_; Texture ResourceManager::getTexture(const std::string &texture_path) { - return texture_cache_.getTexture(texture_path); + return texture_cache_.getTexture(texture_path); } } // yage diff --git a/src/rigidbody.cpp b/src/rigidbody.cpp new file mode 100644 index 00000000..3f719784 --- /dev/null +++ b/src/rigidbody.cpp @@ -0,0 +1,16 @@ +#include "Physics/rigidbody.hpp" + +namespace yage +{ + +RigidBody::RigidBody(const glm::vec2 ¢er_of_mass, double mass, const glm::vec2 &velocity, bool gravity) : + Body(center_of_mass, mass, velocity, gravity) +{} + +void RigidBody::applyForce(const glm::vec2 &force) +{ + // a=F/m + glm::vec2 acceleration(force.x/mass_, force.y/mass_); +} + +} // yage |