Commit a4f1ea16 authored by Nicholas Walton's avatar Nicholas Walton

Implemented triangle clipping. Works perfectly! Needs optimizing

parent 0e6af59d
This diff is collapsed.
......@@ -11,12 +11,12 @@ extern "C"{
typedef struct {
int w, h, cell_size;
Vec2i start, end;
vec2i_t start, end;
uint8_t* cells;
} Grid;
typedef struct{
Vec2f a, b;
vec2_t a, b;
} Wall;
typedef enum{
......@@ -31,7 +31,7 @@ extern "C"{
#define DRAW_OFFSETX 0
#define DRAW_OFFSETY 0
void MazeDrawCell(Grid* grid, int x, int y, KSprite* dest, uint32_t color){
void MazeDrawCell(Grid* grid, int x, int y, ksprite_t* dest, uint32_t color){
if(x < 0 || x > grid->w-1 || y < 0 || y > grid->h-1) return;
KSDrawRectFilled(dest, x*grid->cell_size+DRAW_OFFSETX, y*grid->cell_size+DRAW_OFFSETY, (x+1)*grid->cell_size-1+DRAW_OFFSETX, (y+1)*grid->cell_size-1+DRAW_OFFSETY, color);
uint8_t cell = grid->cells[y*grid->w + x];
......@@ -102,12 +102,12 @@ extern "C"{
top_edge_wall.b.x = grid->w*grid->cell_size;
top_edge_wall.b.y = grid->h*grid->cell_size;
sb_push(hwalls, top_edge_wall);
Vec2f intersection;
vec2_t intersection;
for(int hwall_it = 0; hwall_it < sb_count(hwalls); ++hwall_it){
bool did_split = false;
for(int vwall_it = 0; vwall_it < sb_count(vwalls); ++vwall_it){
if(Vec2fIntersectLineSegments(hwalls[hwall_it].a, hwalls[hwall_it].b, vwalls[vwall_it].a, vwalls[vwall_it].b, &intersection)){
if(!Vec2fEquals(intersection, hwalls[hwall_it].a) && !Vec2fEquals(intersection, hwalls[hwall_it].b) && !Vec2fEquals(intersection, vwalls[vwall_it].a) && !Vec2fEquals(intersection, vwalls[vwall_it].b)) {
if(Vec2IntersectLineSegments(hwalls[hwall_it].a, hwalls[hwall_it].b, vwalls[vwall_it].a, vwalls[vwall_it].b, &intersection)){
if(!Vec2Equals(intersection, hwalls[hwall_it].a) && !Vec2Equals(intersection, hwalls[hwall_it].b) && !Vec2Equals(intersection, vwalls[vwall_it].a) && !Vec2Equals(intersection, vwalls[vwall_it].b)) {
did_split = true;
Wall left_wall;
left_wall.a = hwalls[hwall_it].a;
......@@ -133,7 +133,7 @@ extern "C"{
sb_free(vwalls);
}
bool MazeGenerateAnimated(Grid* grid, Wall** walls, int w, int h, int cell_size, KSprite* frame_buffer, bool (*EventCallback)(KSprite*, bool*)){
bool MazeGenerateAnimated(Grid* grid, Wall** walls, int w, int h, int cell_size, ksprite_t* frame_buffer, bool (*EventCallback)(ksprite_t*, bool*)){
bool disable_animation = false;
if(grid->cells){
free(grid->cells);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment