//Makes a mesh ball. #define MAX_VERTICES 1024 #define MAX_TRIS 1024 class Ball { I32 vertex_cnt; I32 tri_cnt; CD3I32 v[MAX_VERTICES]; CMeshTri t[MAX_TRIS]; } *b; class BallDefineStruct { F64 radius fmtstr "$$DA-TRM,A=\"Radius :%8.3f\"$$\n"; I64 n_longitude fmtstr "$$DA-TRM,A=\"Longitude Faces:%5d\"$$\n"; I64 n_lattitude fmtstr "$$DA-TRM,A=\"Lattitude Rings:%5d\"$$\n"; }; U0 BDInit(BallDefineStruct *bd) { MemSet(bd,0,sizeof(BallDefineStruct)); bd->n_longitude=16; bd->n_lattitude=8; bd->radius =20.0; } U0 BDCorrect(BallDefineStruct *bd) { bd->n_longitude=(bd->n_longitude+1)/2; bd->n_lattitude=(bd->n_lattitude+1)/2; } I64 AddVertex(BallDefineStruct *,I64 x,I64 y,I64 z) { I64 i; for (i=0;ivertex_cnt;i++) if (b->v[i].x==x && b->v[i].y==y && b->v[i].z==z) return i; i=b->vertex_cnt++; b->v[i].x=x; b->v[i].y=y; b->v[i].z=z; return i; } I64 AddTri(BallDefineStruct *,I64 c,I64 n0,I64 n1,I64 n2) { I64 result=b->tri_cnt++; b->t[result].color=c; b->t[result].nums[0]=n0; b->t[result].nums[1]=n1; b->t[result].nums[2]=n2; return result; } U8 *Ball2CSprite() { //See $LK,"::/Adam/Gr/GrSpritePlot.CPP",A="FL:::/Adam/Gr/GrSpritePlot.CPP,1"$ for how CSprite are stored. U8 *result=MAlloc(sizeof(CSpriteMeshU8s)+ b->vertex_cnt*sizeof(CD3I32)+b->tri_cnt*sizeof(CMeshTri) +sprite_elem_base_sizes[SPT_END]), *dst=result; *dst++ =SPT_MESH; *dst(I32 *)++ =b->vertex_cnt; *dst(I32 *)++ =b->tri_cnt; MemCpy(dst,&b->v,b->vertex_cnt*sizeof(CD3I32)); dst+=b->vertex_cnt*sizeof(CD3I32); MemCpy(dst,&b->t,b->tri_cnt*sizeof(CMeshTri)); dst+=b->tri_cnt*sizeof(CMeshTri); *dst++ =SPT_END; return result; } public U8 *BallGen() { U8 *result; I64 i,j,n,m,c,p1,p2,p3,p4; BallDefineStruct bd1,bd2; F64 r,r1,r2,z1,z2,d_a1,d_a2; BDInit(&bd1); while (TRUE) { if (!DocForm(&bd1)) return NULL; MemCpy(&bd2,&bd1,sizeof(BallDefineStruct)); BDCorrect(&bd2); c=PopUpColorLighting; if (c<0) return NULL; b=CAlloc(sizeof(Ball)); r=bd2.radius; n=bd2.n_lattitude; m=bd2.n_longitude; d_a1=2*ã/n/4; d_a2=2*ã/m/2; for (j=-n;j\",BI=%d$$"); "%h7c",'\n'; "Vertices:%d\n",b->vertex_cnt; Free(b); "Do another"; if (YorN) Free(result); else break; } return result; }