added new method for defining, and added adaptive rendering

This commit is contained in:
Solomon W. 2020-05-28 15:28:31 -04:00
parent 0b3e1c4be0
commit f5bf1f1b2a
2 changed files with 70 additions and 17 deletions

View File

@ -1,23 +1,73 @@
#include "Quad.h" #include "Quad.h"
#include <iostream>
Quad::Quad(Vertex topL, Vertex topR, Vertex botR, Vertex botL) { /*Quad::Quad(Vector topL, Vector topR, Vector botR, Vector botL) {
this->topL=topL; this->topL=topL;
this->topR=topR; this->topR=topR;
this->botR=botR; this->botR=botR;
this->botL=botL; 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() {} 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; x<xend; x++) {
for(int y=ystart; y<yend; y++) {
SDL_RenderDrawPoint(renderer,x,y);
}
}
SDL_SetRenderDrawColor(renderer,r,g,b,a);
}
void Quad::setColor(Color c) {
this->color=c; this->color=c;
} }
void Quad::render() { void Quad::translate(Vector vec) {
glColor4f(color.r,color.g,color.b,color.a); topL.x += vec.x;
glVertex3f(topL.x,topL.y,topL.z); topR.x += vec.x;
glVertex3f(topR.x,topR.y,topR.z); botR.x += vec.x;
glVertex3f(botR.x,botR.y,botR.z); botL.x += vec.x;
glVertex3f(botL.x,botL.y,botL.z);
topL.y += vec.y;
topR.y += vec.y;
botR.y += vec.y;
botL.y += vec.y;
} }

View File

@ -1,13 +1,16 @@
#include "Color.h" #include "Color.h"
#include "Vertex.h" #include "SDL2/SDL.h"
#include <GL/glew.h> #include "Vector.h"
class Quad { class Quad {
public: public:
myColor color; Color color;
Vertex topL,topR,botR,botL; Vector topL,topR,botR,botL;
Quad(Vertex topL, Vertex topR, Vertex botR, Vertex botL); //Quad(Vector topL, Vector topR, Vector botR, Vector botL);
Quad(Vector topLeft, int width, int height);
Quad(Vector corner1, Vector corner2);
Quad(); Quad();
void setColor(myColor c); void setColor(Color c);
void render(); void render(SDL_Renderer *renderer);
void translate(Vector vec);
}; };