mirror of
https://github.com/PoetryInCode/simple-rigid-sim.git
synced 2025-06-08 10:33:09 -04:00
added method to fetch all yvalues, may remove
This commit is contained in:
parent
d425ac7483
commit
f066dc1760
33
src/Quad.cpp
33
src/Quad.cpp
@ -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;
|
||||
}
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user