From 36185af6603ea090acb0445600ebf75ffb68b334 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20Hord=C3=A9?= Date: Wed, 22 Aug 2018 18:39:06 +0200 Subject: [PATCH] fix: debogue de la fonction trianglefill --- lib/2d.c | 27 ++++++++++++++------------- makefile | 6 +++++- system/system.c | 12 +++++++++++- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/lib/2d.c b/lib/2d.c index 42ed92e..230c681 100755 --- a/lib/2d.c +++ b/lib/2d.c @@ -68,29 +68,24 @@ void hline(u32 x1, u32 x2, u32 y, u8 color) { writepxl(x2, y, color); } + /******************************************************************************/ /* Affiche un triangle rempli entre les points spécifiés */ void trianglefilled(vertex2d *AA, vertex2d *BB, vertex2d *CC, u8 color) { - vertex2d *A,*B,*C; + vertex2d *A,*B,*C,*TEMP; u32 a, b, y, last; int dx1, dx2, dx3, dy1, dy2, dy3 , sa, sb; A=AA; B=BB; C=CC; - if (AA->y > BB->y) { - A=BB; - B=AA; - } - if (BB->y > CC->y) { - C=BB; - B=CC; - } - if (AA->y > CC->y) { - C=AA; - A=CC; - } + if (A->y > B->y) + swapvertex(A,B); + if (B->y > C->y) + swapvertex(B,C); + if (A->y > C->y) + swapvertex(A,C); if(A->y == C->y) { //meme ligne a = b = A->x; if(B->x < a) a = B->x; @@ -133,6 +128,12 @@ void trianglefilled(vertex2d *AA, vertex2d *BB, vertex2d *CC, u8 color) { } } +void swapvertex(vertex2d* A, vertex2d* B){ + vertex2d temp = *A; + *A = *B; + *B = temp; +} + /******************************************************************************/ /* Affiche un triangle entre les points spécifiés */ diff --git a/makefile b/makefile index 1fc204c..1a27187 100755 --- a/makefile +++ b/makefile @@ -21,9 +21,13 @@ copy: test: all copy qemu +retest: clean test + view: (hexdump -C ./final/cos2000.img|head -c10000) +debug: debug-system + debug-boot: all copy qemu-debug (sleep 2;cgdb -x ./debug/boot.txt) @@ -34,7 +38,7 @@ debug-system: all copy qemu-debug (sleep 2;cgdb -x ./debug/system.txt) qemu-debug: - (qemu-system-i386 -m 1G -fda ./final/cos2000.img -s -S &) + (killall qemu-system-i386;qemu-system-i386 -m 1G -fda ./final/cos2000.img -s -S &) qemu: (qemu-system-i386 -m 1G -fda ./final/cos2000.img -s) diff --git a/system/system.c b/system/system.c index a77660b..b1b37d0 100755 --- a/system/system.c +++ b/system/system.c @@ -94,8 +94,16 @@ void test2d() { setvmode(0x84); fill(0x00); struct vertex2d a,b,c; + a.x=230; + a.y=157; + b.x=375; + b.y=29; + c.x=278; + c.y=276; + trianglefilled(&a,&b,&c,random(0, 16)); + triangle(&a,&b,&c,2); randomize(); - for(int i=0;i<100;i++) + for(int i=0;i<3200;i++) { a.x=random(0, 800); a.y=random(0, 600); @@ -105,6 +113,8 @@ void test2d() { c.y=random(0, 600); trianglefilled(&a,&b,&c,random(0, 16)); triangle(&a,&b,&c,2); + printf("\r\nA:%d,%d B:%d,%d C:%d,%d",a.x,a.y,b.x,b.y,c.x,c.y); + waitascii(); } }