aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorYann Herklotz <ymherklotz@gmail.com>2017-06-27 10:53:12 +0100
committerYann Herklotz <ymherklotz@gmail.com>2017-06-27 10:53:12 +0100
commit3b2e4639de929e640fe672e0d77e0faef3acc027 (patch)
treeaad08ed80aa9663a09614de065f3d40dd347b23f /include
parent205f2459063a123cabd83fb66b3880a72fb357bf (diff)
downloadYAGE-3b2e4639de929e640fe672e0d77e0faef3acc027.tar.gz
YAGE-3b2e4639de929e640fe672e0d77e0faef3acc027.zip
Implementing Vector2d
Diffstat (limited to 'include')
-rw-r--r--include/YAGE/Math/matrix.hpp36
-rw-r--r--include/YAGE/Physics/body.hpp18
-rw-r--r--include/YAGE/Physics/particlebody.hpp8
3 files changed, 49 insertions, 13 deletions
diff --git a/include/YAGE/Math/matrix.hpp b/include/YAGE/Math/matrix.hpp
index d1c5fd74..238f7d09 100644
--- a/include/YAGE/Math/matrix.hpp
+++ b/include/YAGE/Math/matrix.hpp
@@ -236,6 +236,36 @@ Matrix<M, N, T> operator-(const T &lhs, Matrix<M, N, T> rhs)
}
template<int M, int N, class T>
+Matrix<M, N, T> operator*(Matrix<M, N, T> lhs, const T &rhs)
+{
+ for(auto &data : lhs)
+ {
+ data*=rhs;
+ }
+ return lhs;
+}
+
+template<int M, int N, class T>
+Matrix<M, N, T> operator*(const T &lhs, Matrix<M, N, T> rhs)
+{
+ for(auto &data : rhs)
+ {
+ data*=lhs;
+ }
+ return rhs;
+}
+
+template<int M, int N, class T>
+Matrix<M, N, T> operator/(Matrix<M, N, T> lhs, const T &rhs)
+{
+ for(auto &data : lhs)
+ {
+ data/=rhs;
+ }
+ return lhs;
+}
+
+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)
@@ -280,6 +310,12 @@ 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 54fdeb3f..f09cd5d5 100644
--- a/include/YAGE/Physics/body.hpp
+++ b/include/YAGE/Physics/body.hpp
@@ -1,7 +1,7 @@
#ifndef YAGE_BODY_HPP
#define YAGE_BODY_HPP
-#include <glm/glm.hpp>
+#include "Math/matrix.hpp"
namespace yage
{
@@ -13,37 +13,37 @@ public:
static const double GRAVITY;
protected:
// center of mass of the object
- glm::vec2 position_=glm::vec2(0.f, 0.f);
+ Vector2d position_=Vector2d(0, 0);
// mass of the object
- double mass_=1.0;
+ double mass_=1;
// current velocity of the object
- glm::vec2 velocity_=glm::vec2(0.f, 0.f);
+ Vector2d velocity_=Vector2d(0.f, 0.f);
// boolean that defines if gravity can act on the object
bool gravity_=true;
// current acceleration
- glm::vec2 acceleration_=glm::vec2(0.f, 0.f);
+ Vector2d acceleration_=Vector2d(0, 0);
// force acting on the body
- glm::vec2 force_=glm::vec2(0.f, 0.f);
+ Vector2d force_=Vector2d(0, 0);
public:
virtual ~Body();
// apply force to the object and update the velocity
- virtual void applyForce(const glm::vec2 &force)=0;
+ virtual void applyForce(const Vector2d &force)=0;
virtual void update()=0;
float xPosition() const;
float yPosition() const;
protected:
// protected constructor to initialize member variables
- Body(const glm::vec2 &position=glm::vec2(0.f, 0.f),
+ Body(const Vector2d &position=Vector2d(0.f, 0.f),
double mass=1.0,
- const glm::vec2 &velocity=glm::vec2(0.f, 0.f),
+ const Vector2d &velocity=Vector2d(0.f, 0.f),
bool gravity=false);
};
diff --git a/include/YAGE/Physics/particlebody.hpp b/include/YAGE/Physics/particlebody.hpp
index d9d5e08c..09ad8c7b 100644
--- a/include/YAGE/Physics/particlebody.hpp
+++ b/include/YAGE/Physics/particlebody.hpp
@@ -1,7 +1,7 @@
#ifndef YAGE_PARTICLE_BODY_HPP
#define YAGE_PARTICLE_BODY_HPP
-#include <glm/glm.hpp>
+#include "Math/matrix.hpp"
#include "body.hpp"
@@ -11,13 +11,13 @@ namespace yage
class ParticleBody : public Body
{
public:
- ParticleBody(const glm::vec2 &position=glm::vec2(0.f, 0.f),
+ ParticleBody(const Vector2d &position=Vector2d(0.f, 0.f),
double mass=1.0,
- const glm::vec2 &velocity=glm::vec2(0.f, 0.f),
+ const Vector2d &velocity=Vector2d(0.f, 0.f),
bool gravity=true);
// apply a force to the rigid body
- virtual void applyForce(const glm::vec2 &force);
+ virtual void applyForce(const Vector2d &force);
virtual void update();
};