I want to map a 2d picture onto an arbitrary 2d quadrilateral, for the purpose of particle system. To do that, I split the picture into two triangles, and then linearly interpolated u,v along the triangle edges, using the following code:
struct tlerp {
double x,i;
double u,v;
double ui,vi;
} tlerp;
void tlerp_init(tlerp *l
, double first_step, double steps
, double sx, double ex
, double su, double eu
, double sv, double ev) {
l->i = (ex - sx) / steps;
l->ui = (eu - su) / steps;
l->vi = (ev - sv) / steps;
l->x = sx + first_step*l->i;
l->u = su + first_step*l->ui;
l->v = sv + first_step*l->vi;
}
void tlerp_advance(tlerp *l) {
l->x += l->i;
l->u += l->ui;
l->v += l->vi;
}
But the result is garbled. My guess is that linear interpolation can't be used here, because the space inside quadrilateral is obviously non-linear (on the attached picture it gets more compressed the closer it gets to the top). Is there some way to make it linear again?
As always, I'm not using an OpenGL/DirectX, so can't use any built-in solution.