From bd26db954e14d2196c4f8a83d1fbf09c87c66ef9 Mon Sep 17 00:00:00 2001 From: Krow Savcik Date: Sun, 31 Dec 2023 15:28:42 +0200 Subject: feature: line toggling Added line toggling with 'T' --- README.md | 1 + draw.c | 26 ++++++++++++++++---------- draw.h | 2 +- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 0aabdca..c819c30 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ Controls - **W,A,S,D** for moving. - **M** for toggling mouse-lock. +- **T** for toggling line drawing. - **arrows** for rotating camera. - **J,K** for moving vertically. - **I** for object importing. diff --git a/draw.c b/draw.c index 9e79b93..9b703be 100644 --- a/draw.c +++ b/draw.c @@ -6,8 +6,9 @@ #include "sim.h" /*#define SHADOW*/ -#define TRIANGLELINES -#define MAXTRIANGLE 2048 +/*#define TRIANGLELINES*/ +int drawlines; +#define MAXTRIANGLE (1<<16) #define MIN(a,b) (((a) < (b)) ? (a) : (b)) #define MAX(a,b) (((a) > (b)) ? (a) : (b)) #define INTTOCOL(C) (C>>16), ((C>>8)%256), (C%256) @@ -112,7 +113,10 @@ void redo_obj() { tgs_cnt = 0; - add_obj("obj/car.obj", P(0,0,0)); +/* add_obj("obj/car.obj", P(0,0,0));*/ +/* add_obj("obj/peach.obj", P(0,0,0));*/ +/* add_obj("obj/toad.obj", P(20,0,0));*/ + add_obj("obj/psyduck.obj", P(0,0,0)); } void @@ -230,6 +234,8 @@ draw_triangle(Point x, Point y, Point z) mny = MIN(a.y, MIN(b.y, c.y)); mxy = MAX(a.y, MAX(b.y, c.y)); +/* if (mnx < 0 || mxx >= w || mny < 0 || mxy >= h) return;*/ + /* Fake depth :> */ for(i = MAX(mnx, 0); i <= MIN(mxx, w-1); ++i) { @@ -247,13 +253,13 @@ draw_triangle(Point x, Point y, Point z) } SDL_RenderDrawPoints(ren, pts_queue, pts_queue_cnt); -#ifdef TRIANGLELINES - SDL_SetRenderDrawColor(ren, 0xff, 0xff, 0xff, 0xff); - SDL_SetRenderDrawColor(ren, 0x00, 0x00, 0x00, 0xff); - SDL_RenderDrawLine(ren, a.x, a.y, b.x, b.y); - SDL_RenderDrawLine(ren, c.x, c.y, b.x, b.y); - SDL_RenderDrawLine(ren, a.x, a.y, c.x, c.y); -#endif + if (drawlines) { +/* SDL_SetRenderDrawColor(ren, 0xff, 0xff, 0xff, 0xff);*/ + SDL_SetRenderDrawColor(ren, 0x00, 0x00, 0x00, 0xff); + SDL_RenderDrawLine(ren, a.x, a.y, b.x, b.y); + SDL_RenderDrawLine(ren, c.x, c.y, b.x, b.y); + SDL_RenderDrawLine(ren, a.x, a.y, c.x, c.y); + } } void diff --git a/draw.h b/draw.h index 779f23e..e33ebd9 100644 --- a/draw.h +++ b/draw.h @@ -3,4 +3,4 @@ int draw_init(); void add_obj_interactive(); void redo_obj(); -extern int w, h; +extern int w, h, drawlines; -- cgit v1.2.3