void mesh(Mesh* mymesh){ register int i; vecp v; matp m; int *ip,calculatedisplaykoordinates=1; i=mymesh->mode; if ((!mymesh->normalsinitialized) &&((i==MESHONESIDED)||(i==SQUAREMESHONESIDED))) { calcnormals(&mymesh->Garray[0],1); mymesh->normalsinitialized=1; /*calculatedisplaykoordinates=0*/ } ip=mymesh->transf2dc; meq(mymesh->mc2wcmn,getmc2wcmn()); meq(mymesh->mc2wcm,getmc2wcm()); veq(mymesh->mc2wcv,getmc2wcv()); m=mymesh->mc2wcm; v=mymesh->mc2wcv; for (i=0;i<mymesh->xdim*mymesh->ydim;i++){ veq(mymesh->tva[i],vsum(matvecmul(m,mymesh->va[i]),v)); *(ip++)=0; } if (calculatedisplaykoordinates) for (i=0;i<mymesh->xdim*mymesh->ydim;i++) wc2dc(&mymesh->points[i].x,&mymesh->points[i].y,mymesh->tva[i]); meq(mymesh->mc2wcmn,getmc2wcmn()); for (i=0;i<(mymesh->xdim-1)*(mymesh->ydim-1);i++)insertGobject(&mymesh->Garray[i]); }
static struct color *RGBtoYST(struct color *c) { double mat[3][3] = { { Wr, Wg, Wb }, { 1, -.5, -.5}, { 0, .5*sqrt(3), -.5*sqrt(3) } }; matvecmul(mat, c); return c; }
static struct color *YSTtoRGB(struct color *c) { double mat[3][3] = { { 1, Wg+Wb, (Wb - Wg) / sqrt(3) }, { 1, -Wr, (2*Wb + Wr) / sqrt(3) }, { 1, -Wr, -(2*Wg + Wr) / sqrt(3) } }; matvecmul(mat, c); return c; }
void contour3d(Contour* c){ int i,j,*k; vecp v; matp m; if (c->initialized==0){ c->tva=malloc((c->vaakt+1)*sizeof(vec)); c->na=malloc((c->polakt+1)*sizeof(vec)); c->sp=malloc((c->polakt+1)*sizeof(vec)); c->points=malloc((c->polakt+1)*sizeof(DPoint)); c->Garray=malloc((c->polakt+1)*sizeof(Gobject)); for (i=0;i<=c->polakt;i++) { c->Garray[i].na=c->na; c->Garray[i].tva=c->tva; c->Garray[i].poswc=(vecp) &c->sp[i]; /* compiler distinguishes between vec* and vecp */ c->Garray[i].points=c->points; c->Garray[i].polygons=&c->pol[i*6]; c->Garray[i].drawstruct=drawtrianglelight; j=c->pol[i*6]; veq(c->na[i],vnorm(vp(vdiff(c->va[j+4],c->va[j+3]),vdiff(c->va[j+5],c->va[j+3])))); } c->initialized=1; } /* Transformation, die jedes Mal durchlaufen wird. */ meq(c->mc2wcmn,getmc2wcmn()); meq(c->mc2wcm,getmc2wcm()); veq(c->mc2wcv,getmc2wcv()); m=c->mc2wcm; v=c->mc2wcv; for (i=0;i<=c->vaakt;i++) { veq(c->tva[i],vsum(matvecmul(m,c->va[i]),v)); wc2dc(&c->points[i].x,&c->points[i].y,c->tva[i]); } for (i=0;i<=c->polakt;i++){ /* Schwerpunkt in Weltkoordinaten */ k=&c->pol[i*6+3]; veq(c->sp[i],sm(0.33333, vsum(vsum(c->tva[*k],c->tva[*(k+1)]),c->tva[*(k+2)]))); insertGobject(&c->Garray[i]); } }