diff options
author | Yann Herklotz <ymherklotz@gmail.com> | 2017-07-23 14:19:28 +0100 |
---|---|---|
committer | Yann Herklotz <ymherklotz@gmail.com> | 2017-07-23 14:19:28 +0100 |
commit | daa9dc84d7fb6e7c8f84b1ee3adfaacaad7de72f (patch) | |
tree | 60909899b320f03193896b277006fb01a506629f /include | |
parent | 85fe87aa7a52733dc80f61617bf65f22b2d98ccb (diff) | |
download | YAGE-daa9dc84d7fb6e7c8f84b1ee3adfaacaad7de72f.tar.gz YAGE-daa9dc84d7fb6e7c8f84b1ee3adfaacaad7de72f.zip |
Fixing gravity
Diffstat (limited to 'include')
-rw-r--r-- | include/YAGE/Math/matrix.hpp | 22 | ||||
-rw-r--r-- | include/YAGE/Physics/body.hpp | 12 | ||||
-rw-r--r-- | include/YAGE/Physics/particlebody.hpp | 6 | ||||
-rw-r--r-- | include/YAGE/Physics/rigidbody.hpp | 6 |
4 files changed, 26 insertions, 20 deletions
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<int M, int N, class T> bool operator==(const Matrix<M, N, T> &lhs, const Matrix<M, N, T> &rhs) { for(int i=0; i<M; ++i) - { for(int j=0; j<N; ++j) - { if(lhs[i][j]!=rhs[i][j]) - { - return false; - } - } - } + return false; return true; } @@ -303,18 +297,30 @@ public: return this->data_[col]; } - + virtual std::string toString() const + { + std::stringstream ss; + ss<<"["; + for(std::size_t i=0; i<this->data_.size()-1; ++i) + { + ss<<this->data_[i]<<" "; + } + ss<<this->data_[this->data_.size()-1]<<"]"; + return ss.str(); + } }; template<class Type=double> class Vector2 : public Vector<2, Type> { public: Vector2<Type>() : Vector<2, Type>() {} + Vector2<Type>(Type x, Type y) { this->data_[0]=x; this->data_[1]=y; } + Vector2<Type>(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); }; |