mirror of
https://github.com/PoetryInCode/simple-rigid-sim.git
synced 2025-06-10 03:13:10 -04:00
added new method for defining, and added adaptive rendering
This commit is contained in:
parent
0b3e1c4be0
commit
f5bf1f1b2a
70
src/Quad.cpp
70
src/Quad.cpp
@ -1,23 +1,73 @@
|
||||
#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->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; 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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
17
src/Quad.h
17
src/Quad.h
@ -1,13 +1,16 @@
|
||||
#include "Color.h"
|
||||
#include "Vertex.h"
|
||||
#include <GL/glew.h>
|
||||
#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);
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user