drag_start and drag_origin not working...
This commit is contained in:
+49
-13
@@ -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<typename T>
|
||||
Vec2D<T> operator+(const Vec2D<T>& left, const Vec2D<T>& right){
|
||||
return Vec2D<T>(left.x + right.x, left.y + right.y);
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
Vec2D<T> operator-(const Vec2D<T>& left, const Vec2D<T>& right){
|
||||
return Vec2D<T>(left.x - right.x, left.y - right.y);
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
Vec2D<T> operator*(const Vec2D<T>& left, const Vec2D<T>& right){
|
||||
return Vec2D<T>(left.x * right.x, left.y * right.y);
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
Vec2D<T> operator/(const Vec2D<T>& left, const Vec2D<T>& right){
|
||||
return Vec2D<T>(left.x / right.x, left.y / right.y);
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
Vec2D<T> operator/(const Vec2D<T>& left, T scalar){
|
||||
return Vec2D<T>(left.x / scalar, left.y / scalar);
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
Vec2D<T> operator*(const Vec2D<T>& left, T scalar){
|
||||
return Vec2D<T>(left.x * scalar, left.y * scalar);
|
||||
};
|
||||
|
||||
struct Color{
|
||||
|
||||
+1
-1
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user