/* example use of pmap_poly to infer projective mapping from a quadrilateral */

#include "poly.h"
#define SIZE 50

main()
{
    static poly p = {
        4,
      /* u  v  sx  sy */
        {0, 0,  0,  0}, /* vert[0] */
        {1, 0, 40,  0}, /* vert[1] */
        {1, 1, 30, 30}, /* vert[2] */
        {0, 1, 10, 20}  /* vert[3] */
    };
    double ST[3][3];
    double scr[3], tex[3];
    int x, y;

    /* compute screen to texture transform ST */
    pmap_poly(&p, ST);

    /* scan a square area of screen space, transforming to texture space */
    for (y=0; y<SIZE; y++)
        for (x=0; x<SIZE; x++) {
            scr[0] = x;
            scr[1] = y;
            scr[2] = 1.;
            mx3d_transform(scr, ST, tex);
            tex[0] /= tex[2];
            tex[1] /= tex[2];
            printf("scr(%d,%d) transforms to tex(%g,%g)\n",
                x, y, tex[0], tex[1]);
        }
}
