correct perspective deformation
(this is quite slow, and I will turn `double` to `int` as soon as possible)
This commit is contained in:
parent
d2ce3c3e3a
commit
1aad8e5f9e
BIN
libfxengine.a
BIN
libfxengine.a
Binary file not shown.
|
@ -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_interval<frame_interval_min)
|
||||
frame_interval_min = frame_interval;
|
||||
|
@ -31,14 +31,14 @@ void render_update(const uint32_t libprof_channel)
|
|||
prof_init(libprof_channel+1, 0);
|
||||
}
|
||||
//dupdate();
|
||||
prof_clear(0);
|
||||
prof_enter(0);
|
||||
prof_clear(libprof_channel);
|
||||
prof_enter(libprof_channel);
|
||||
|
||||
render_zbuffer_clear();
|
||||
|
||||
///render_set(dh, dv, roulis, camera);
|
||||
|
||||
dclear(C_WHITE);
|
||||
//dclear(C_WHITE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -143,15 +143,15 @@ void render_display_triangle(const render_triangle * face)
|
|||
return;
|
||||
|
||||
// incomplete clipping
|
||||
if (face->s1->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 <vx< 10_000
|
||||
vy=(ycalc*fact_3-xcalc*fact_4); // idem
|
||||
z=face->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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue