From 7b144ed3df31855ab61fb5dc45435f192a6bfd5b Mon Sep 17 00:00:00 2001 From: Sebastian Date: Thu, 10 Oct 2024 09:54:54 +0200 Subject: [PATCH] drag_start and drag_origin not working... --- src/datatypes.h | 62 ++++++++++++++++++++++++++++++++++++++----------- src/main.cpp | 2 +- 2 files changed, 50 insertions(+), 14 deletions(-) diff --git a/src/datatypes.h b/src/datatypes.h index 86dfcaa..0688c56 100644 --- a/src/datatypes.h +++ b/src/datatypes.h @@ -14,7 +14,8 @@ class Vec2D{ T x = 0; T y = 0; T dist(Vec2D* v) { return sqrt(pow((v->x - x), 2) + pow((v->y - y), 2));}; - T length() { return sqrt(pow(x, 2) + pow(y, 2));}; + + T length() { return (T)sqrt(pow(x, 2) + pow(y, 2));}; T angle(Vec2D &v){ T angle = atan2(v.y, v.x) - atan2(y,x); @@ -33,7 +34,7 @@ class Vec2D{ return (x*v.x) + (y*v.y); }; - Vec2D& norm() { return *this * (1.0/length());}; + Vec2D norm() { return *this / length();}; Vec2D& operator=(const Vec2D& vec){ if (this == &vec){ @@ -50,31 +51,66 @@ class Vec2D{ return *this; }; - friend Vec2D operator+(const Vec2D& left, const Vec2D& right){ - return Vec2D(left.x + right.x, left.y + right.y); - }; - Vec2D& operator-=(const Vec2D& vec){ this->x -= vec.x; this->y -= vec.y; return *this; }; - friend Vec2D operator-(const Vec2D& left, const Vec2D& right){ - return Vec2D(left.x - right.x, left.y - right.y); - }; - - Vec2D& operator*(const Vec2D& vec){ + Vec2D& operator*=(const Vec2D& vec){ this->x *= vec.x; this->y *= vec.y; return *this; }; - - Vec2D& operator*(T scalar){ + + Vec2D& operator/=(const Vec2D& vec){ + this->x /= vec.x; + this->y /= vec.y; + return *this; + }; + + Vec2D& operator*=(T scalar){ this->x *= scalar; this->y *= scalar; return *this; }; + + Vec2D& operator/=(T scalar){ + this->x /= scalar; + this->y /= scalar; + return *this; + }; + +}; + +template +Vec2D operator+(const Vec2D& left, const Vec2D& right){ + return Vec2D(left.x + right.x, left.y + right.y); +}; + +template +Vec2D operator-(const Vec2D& left, const Vec2D& right){ + return Vec2D(left.x - right.x, left.y - right.y); +}; + +template +Vec2D operator*(const Vec2D& left, const Vec2D& right){ + return Vec2D(left.x * right.x, left.y * right.y); +}; + +template +Vec2D operator/(const Vec2D& left, const Vec2D& right){ + return Vec2D(left.x / right.x, left.y / right.y); +}; + +template +Vec2D operator/(const Vec2D& left, T scalar){ + return Vec2D(left.x / scalar, left.y / scalar); +}; + +template +Vec2D operator*(const Vec2D& left, T scalar){ + return Vec2D(left.x * scalar, left.y * scalar); }; struct Color{ diff --git a/src/main.cpp b/src/main.cpp index a19eb31..6f532e7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -115,7 +115,7 @@ int main(){ } if(mouse_toggled) drag_origin = n.position; if(mouse_pressed && n.clicked){ - n.position = mouse_pos - (drag_start - drag_origin); + n.position = mouse_pos; // - (drag_start - drag_origin); } if(!mouse_pressed) n.clicked = false; n.update();