diff --git a/src/Quad.cpp b/src/Quad.cpp index 2134b11..41af0d2 100644 --- a/src/Quad.cpp +++ b/src/Quad.cpp @@ -1,23 +1,73 @@ #include "Quad.h" -#include -Quad::Quad(Vertex topL, Vertex topR, Vertex botR, Vertex botL) { +/*Quad::Quad(Vector topL, Vector topR, Vector botR, Vector botL) { this->topL=topL; this->topR=topR; this->botR=botR; this->botL=botL; +}*/ +Quad::Quad(Vector topLeft, int width, int height) { + topL.x = topLeft.x; + topL.y = topLeft.y; + topR.x = topLeft.x+width; + topR.y = topLeft.y; + botR.x = topLeft.x+width; + botR.y = topLeft.y-height; + botL.x = topLeft.x; + botL.y = topLeft.y-height; +} +Quad::Quad(Vector corner1,Vector corner2) { + topL.x = corner1.x; + topL.y = corner1.y; + topR.x = corner2.x; + topR.y = corner1.x; + botR.x = corner2.x; + botR.y = corner2.y; + botL.x = corner1.x; + botL.y = corner2.y; } - Quad::Quad() {} -void Quad::setColor(myColor c) { +void Quad::render(SDL_Renderer *renderer) { + uint8_t r,g,b,a; + SDL_GetRenderDrawColor(renderer,&r,&g,&b,&a); + SDL_SetRenderDrawColor(renderer, color.r,color.g,color.b,color.a); + int xstart,xend; + if(topL.x > topR.x) { + xstart = topR.x; + xend = topL.x; + } else { + xstart = topL.x; + xend = topR.x; + } + int ystart,yend; + if(topL.y > botL.y) { + ystart = botL.y; + yend = topL.y; + } else { + ystart = topL.y; + yend = botL.y; + } + for(int x=xstart; xcolor=c; } -void Quad::render() { - glColor4f(color.r,color.g,color.b,color.a); - glVertex3f(topL.x,topL.y,topL.z); - glVertex3f(topR.x,topR.y,topR.z); - glVertex3f(botR.x,botR.y,botR.z); - glVertex3f(botL.x,botL.y,botL.z); +void Quad::translate(Vector vec) { + topL.x += vec.x; + topR.x += vec.x; + botR.x += vec.x; + botL.x += vec.x; + + topL.y += vec.y; + topR.y += vec.y; + botR.y += vec.y; + botL.y += vec.y; } \ No newline at end of file diff --git a/src/Quad.h b/src/Quad.h index c2b2a05..71947e8 100644 --- a/src/Quad.h +++ b/src/Quad.h @@ -1,13 +1,16 @@ #include "Color.h" -#include "Vertex.h" -#include +#include "SDL2/SDL.h" +#include "Vector.h" class Quad { public: - myColor color; - Vertex topL,topR,botR,botL; - Quad(Vertex topL, Vertex topR, Vertex botR, Vertex botL); + Color color; + Vector topL,topR,botR,botL; + //Quad(Vector topL, Vector topR, Vector botR, Vector botL); + Quad(Vector topLeft, int width, int height); + Quad(Vector corner1, Vector corner2); Quad(); - void setColor(myColor c); - void render(); + void setColor(Color c); + void render(SDL_Renderer *renderer); + void translate(Vector vec); }; \ No newline at end of file