inbetween vector operations
This commit is contained in:
+32
-1
@@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
// 2D Vectors
|
// 2D Vectors
|
||||||
@@ -14,7 +15,19 @@ class Vec2D{
|
|||||||
T y = 0;
|
T y = 0;
|
||||||
T dist(Vec2D* v) { return sqrt(pow((v->x - x), 2) + pow((v->y - y), 2));};
|
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 sqrt(pow(x, 2) + pow(y, 2));};
|
||||||
|
|
||||||
|
T angle(Vec2D &v){
|
||||||
|
T angle = atan2(v.y, v.x) - atan2(y,x);
|
||||||
|
if(angle > M_PI) angle -= M_PI_2;
|
||||||
|
if(angle < -M_PI) angle += M_PI_2;
|
||||||
|
return angle;
|
||||||
|
//return acos(dot(v));
|
||||||
|
};
|
||||||
|
|
||||||
|
T dot(Vec2D &v){
|
||||||
|
return (x*v.x) + (y*v.y);
|
||||||
|
};
|
||||||
|
|
||||||
Vec2D& norm() { return *this * (1.0/length());};
|
Vec2D& norm() { return *this * (1.0/length());};
|
||||||
|
|
||||||
Vec2D& operator=(const Vec2D& vec){
|
Vec2D& operator=(const Vec2D& vec){
|
||||||
@@ -64,3 +77,21 @@ struct Color{
|
|||||||
int g;
|
int g;
|
||||||
int b;
|
int b;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*template <typename T>*/
|
||||||
|
/*bool contains(T X, T Y) {*/
|
||||||
|
/* for (unsigned int i=0;i<Coords.size()-2;i+=2)*/
|
||||||
|
/* {*/
|
||||||
|
/* if (((Y-Coords[i+1])*(Coords[i+2]-Coords[i]) - (X-Coords[i])*(Coords[i+3]-Coords[i+1]))<0)*/
|
||||||
|
/* {*/
|
||||||
|
/* return (false);*/
|
||||||
|
/* }*/
|
||||||
|
/* }*/
|
||||||
|
/* //The last test is special*/
|
||||||
|
/* unsigned int j = Coords.size();*/
|
||||||
|
/* if (((Y-Coords[j-1])*(Coords[0]-Coords[j-2]) - (X-Coords[j-2])*(Coords[1]-Coords[j-1]))<0)*/
|
||||||
|
/* {*/
|
||||||
|
/* return (false);*/
|
||||||
|
/* }*/
|
||||||
|
/* return (true);*/
|
||||||
|
/*}*/
|
||||||
|
|||||||
+3
-1
@@ -23,8 +23,10 @@ class Signal : public Movable{
|
|||||||
|
|
||||||
void draw(sf::RenderWindow *window) {
|
void draw(sf::RenderWindow *window) {
|
||||||
sf::CircleShape circle(radius);
|
sf::CircleShape circle(radius);
|
||||||
circle.setFillColor(sf::Color::Red);
|
circle.setFillColor(sf::Color());
|
||||||
circle.setPosition(position.x, position.y);
|
circle.setPosition(position.x, position.y);
|
||||||
|
// circle.getPoint();
|
||||||
|
// circle.getPointCount()
|
||||||
window->draw(circle);
|
window->draw(circle);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user