
#include <math.h>
#include "cgm.h"

static float    angel;
static int      stupid,
                z=0,
                a,b,c,d;
static CGM      *c1,*c2;

void transform(int x,int y,int *xx,int *yy)
{
    *xx=(a*x>>14)+(b*y>>14);
    *yy=(c*x>>14)+(d*y>>14);

    /* Projection */
    if(stupid!=5)
    {
        *xx= (*xx)*400/(90+z);
        *yy= (*yy)*400/(90+z);
    }
    else
    {
        *xx= (*xx)*400/(80+1000);
        *yy= (*yy)*400/(80+1000);
    }
    
    *xx= (*xx*100>>14)+320*2;
    *yy=-(*yy*100>>14)+200*2;
}

long *staraz_init(void)
{
    c1=cgm_load("data/stara.cgm");
    c2=cgm_load("data/stara2.cgm");
    return(c1->pal);
}

void staraz(unsigned char *buf,int tid)
{
    int n;

    angel=tid/1000.0;
    stupid=0;
    for(n=0;n<6;n++)
    {
        z=(100000+tid+n*200)%1000;
        a=cos(angel)*16384;b=-sin(angel)*16384;
        c=sin(angel)*16384;d=cos(angel)*16384;

        cgm_render((n&1)?c1:c2,buf,transform);
        stupid++;
    }
}
