diff --git a/libfxengine.a b/libfxengine.a index 001a3dc..850b3a5 100644 Binary files a/libfxengine.a and b/libfxengine.a differ diff --git a/src/render/triangle.c b/src/render/triangle.c index 7820c6d..85f4f34 100644 --- a/src/render/triangle.c +++ b/src/render/triangle.c @@ -18,8 +18,8 @@ void render_update(const uint32_t libprof_channel) // gestion du temps avec libprof if (prof_elapsed) { - prof_leave(0); - uint32_t frame_interval = prof_time(0); + prof_leave(libprof_channel); + uint32_t frame_interval = prof_time(libprof_channel); //sleep_us(0, MINIMUM_FRAME_DELAY-frame_interval); if (frame_intervals1->x < 0 && face->s2->x < 0 && face->s3->x < 0) + if (face->s1->x < 0 && face->s2->x < 0 && face->s3->x < 0) return; - if (face->s1->x >= render_width && face->s2->x >= render_width && face->s3->x >= render_width) + if (face->s1->x >= render_width && face->s2->x >= render_width && face->s3->x >= render_width) return; - if (face->s1->y < 0 && face->s2->y < 0 && face->s3->y < 0) + if (face->s1->y < 0 && face->s2->y < 0 && face->s3->y < 0) return; - if (face->s1->y >= render_height && face->s2->y >= render_height && face->s3->y >= render_height) + if (face->s1->y >= render_height && face->s2->y >= render_height && face->s3->y >= render_height) return; - if (face->s1->z <= 0 && face->s2->z <= 0 && face->s3->z <= 0) + if (face->s1->z <= 0 && face->s2->z <= 0 && face->s3->z <= 0) return; line cotes[3]; @@ -184,7 +184,7 @@ void render_display_triangle(const render_triangle * face) } for (int32_t t=0;t<3;t++) { - if (line_get_x(y,&cotes[t],&tx2)&&tx1!=tx2) + if (line_get_x(y,&cotes[t],&tx2) && tx1!=tx2) break; } @@ -197,19 +197,26 @@ void render_display_triangle(const render_triangle * face) // calcul de vx, vy vx=(xcalc*fact_1-ycalc*fact_2); // 0 s1->z + (vx * zAB + vy * zAC) / 32768; - vx /= 32768; - vy /= 32768; + z=face->s1->z + (vx * zAB + vy * zAC) / 32768.0; + vx /= 32768.0; + vy /= 32768.0; + double vx2= ( vx/face->s2->z ) / ((1-vx)/face->s1->z + vx/face->s2->z); + double vy2= ( vy/face->s3->z ) / ((1-vy)/face->s1->z + vy/face->s3->z); + /* Perspective correction vx /= (double) face->s2->z / ((1 - vx) / face->s1->z + vx / (double) face->s2->z); vy /= (double) face->s3->z / ((1 - vy) / face->s1->z + vy / (double) face->s3->z); - + */ // Affichage du point - const uint8_t color = bitmap_get_pixel_r(face->texture, 8*vx, 8*vy); + const uint8_t color = bitmap_get_pixel_r(face->texture, face->texture->size_px_x * vx2, + face->texture->size_px_y * vy2); - if (color) + if (color >> 1) + { + //dpixel(x,y, C_BLACK); if (render_zbuffer_set_px(x,y,z)) dpixel(x, y, 3 * (color % 2)); // 3* means cast to black and white, and vx,and vy casted between 0 and 7 + } } } }