added method to fetch all yvalues, may remove

This commit is contained in:
Solomon W. 2020-05-29 14:05:33 -04:00
parent d425ac7483
commit f066dc1760
2 changed files with 29 additions and 9 deletions

View File

@ -1,4 +1,6 @@
#include "Quad.h"
#include <cstdlib>
#include <stdint.h>
/*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<int> Quad::yvalues() {
std::vector<int> values;
values.push_back(topL.y);
values.push_back(topR.y);
values.push_back(botR.y);
values.push_back(botL.y);
return values;
}

View File

@ -1,15 +1,18 @@
#include "Color.h"
#include <vector>
#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<int> yvalues();
void setColor(Color c);
void render(SDL_Renderer *renderer);
void translate(Vector vec);