From daa9dc84d7fb6e7c8f84b1ee3adfaacaad7de72f Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Sun, 23 Jul 2017 14:19:28 +0100 Subject: Fixing gravity --- include/YAGE/Math/matrix.hpp | 22 ++++++++++++++-------- include/YAGE/Physics/body.hpp | 12 ++++++------ include/YAGE/Physics/particlebody.hpp | 6 +++--- include/YAGE/Physics/rigidbody.hpp | 6 +++--- 4 files changed, 26 insertions(+), 20 deletions(-) (limited to 'include') diff --git a/include/YAGE/Math/matrix.hpp b/include/YAGE/Math/matrix.hpp index 238f7d09..c7c40f00 100644 --- a/include/YAGE/Math/matrix.hpp +++ b/include/YAGE/Math/matrix.hpp @@ -269,15 +269,9 @@ template bool operator==(const Matrix &lhs, const Matrix &rhs) { for(int i=0; idata_[col]; } - + virtual std::string toString() const + { + std::stringstream ss; + ss<<"["; + for(std::size_t i=0; idata_.size()-1; ++i) + { + ss<data_[i]<<" "; + } + ss<data_[this->data_.size()-1]<<"]"; + return ss.str(); + } }; template class Vector2 : public Vector<2, Type> { public: Vector2() : Vector<2, Type>() {} + Vector2(Type x, Type y) { this->data_[0]=x; this->data_[1]=y; } + Vector2(const Matrix<2, 1, Type> &other) : Vector<2, Type>(other) {} Type& x() diff --git a/include/YAGE/Physics/body.hpp b/include/YAGE/Physics/body.hpp index f09cd5d5..5a0e879e 100644 --- a/include/YAGE/Physics/body.hpp +++ b/include/YAGE/Physics/body.hpp @@ -19,7 +19,7 @@ protected: double mass_=1; // current velocity of the object - Vector2d velocity_=Vector2d(0.f, 0.f); + Vector2d velocity_=Vector2d(0, 0); // boolean that defines if gravity can act on the object bool gravity_=true; @@ -37,13 +37,13 @@ public: virtual void applyForce(const Vector2d &force)=0; virtual void update()=0; - float xPosition() const; - float yPosition() const; + double xPosition() const; + double yPosition() const; protected: // protected constructor to initialize member variables - Body(const Vector2d &position=Vector2d(0.f, 0.f), - double mass=1.0, - const Vector2d &velocity=Vector2d(0.f, 0.f), + Body(const Vector2d &position=Vector2d(0, 0), + double mass=1, + const Vector2d &velocity=Vector2d(0, 0), bool gravity=false); }; diff --git a/include/YAGE/Physics/particlebody.hpp b/include/YAGE/Physics/particlebody.hpp index 09ad8c7b..62e6fc43 100644 --- a/include/YAGE/Physics/particlebody.hpp +++ b/include/YAGE/Physics/particlebody.hpp @@ -11,9 +11,9 @@ namespace yage class ParticleBody : public Body { public: - ParticleBody(const Vector2d &position=Vector2d(0.f, 0.f), - double mass=1.0, - const Vector2d &velocity=Vector2d(0.f, 0.f), + 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 diff --git a/include/YAGE/Physics/rigidbody.hpp b/include/YAGE/Physics/rigidbody.hpp index 48380dac..05d8d0ad 100644 --- a/include/YAGE/Physics/rigidbody.hpp +++ b/include/YAGE/Physics/rigidbody.hpp @@ -11,9 +11,9 @@ namespace yage class RigidBody : public ParticleBody { public: - RigidBody(const glm::vec2 &position=glm::vec2(0.f, 0.f), - double mass=1.0, - const glm::vec2 &velocity=glm::vec2(0.f, 0.f), + RigidBody(const Vector2d &position=Vector2d(0, 0), + double mass=1, + const Vector2d &velocity=Vector2d(0, 0), bool gravity=true); }; -- cgit