diff --git a/src/Quad.cpp b/src/Quad.cpp index 41af0d2..ff46f71 100644 --- a/src/Quad.cpp +++ b/src/Quad.cpp @@ -1,4 +1,6 @@ #include "Quad.h" +#include +#include /*Quad::Quad(Vector topL, Vector topR, Vector botR, Vector botL) { this->topL=topL; @@ -6,6 +8,7 @@ this->botR=botR; this->botL=botL; }*/ + Quad::Quad(Vector topLeft, int width, int height) { topL.x = topLeft.x; topL.y = topLeft.y; @@ -15,6 +18,7 @@ Quad::Quad(Vector topLeft, int width, int height) { botR.y = topLeft.y-height; botL.x = topLeft.x; botL.y = topLeft.y-height; + center = Vector(abs(topL.x-topR.x),abs(topL.y-botL.y)); } Quad::Quad(Vector corner1,Vector corner2) { topL.x = corner1.x; @@ -25,6 +29,7 @@ Quad::Quad(Vector corner1,Vector corner2) { botR.y = corner2.y; botL.x = corner1.x; botL.y = corner2.y; + center = Vector(abs(topL.x-topR.x),abs(topL.y-botL.y)); } Quad::Quad() {} @@ -61,13 +66,25 @@ void Quad::setColor(Color c) { } void Quad::translate(Vector vec) { - topL.x += vec.x; - topR.x += vec.x; - botR.x += vec.x; - botL.x += vec.x; + if(vec.x != 0) { + topL.x += vec.x; + topR.x += vec.x; + botR.x += vec.x; + botL.x += vec.x; + } + if(vec.y != 0) { + topL.y += vec.y; + topR.y += vec.y; + botR.y += vec.y; + botL.y += vec.y; + } +} - topL.y += vec.y; - topR.y += vec.y; - botR.y += vec.y; - botL.y += vec.y; +std::vector Quad::yvalues() { + std::vector values; + values.push_back(topL.y); + values.push_back(topR.y); + values.push_back(botR.y); + values.push_back(botL.y); + return values; } \ No newline at end of file diff --git a/src/Quad.h b/src/Quad.h index 71947e8..6696cd9 100644 --- a/src/Quad.h +++ b/src/Quad.h @@ -1,15 +1,18 @@ -#include "Color.h" +#include #include "SDL2/SDL.h" #include "Vector.h" +#include "Color.h" class Quad { public: Color color; Vector topL,topR,botR,botL; + Vector center; //Quad(Vector topL, Vector topR, Vector botR, Vector botL); Quad(Vector topLeft, int width, int height); Quad(Vector corner1, Vector corner2); Quad(); + std::vector yvalues(); void setColor(Color c); void render(SDL_Renderer *renderer); void translate(Vector vec);