home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
-
- #define MX_N 4
- typedef float matrix[MX_N][MX_N];
- typedef float vector[MX_N];
-
- void
- MxMultiply(matrix a, matrix b, matrix c)
- {
- int i,j;
- matrix h;
-
- for (i=0;i<4;i++)
- for (j=0;j<4;j++)
- {
- h[i][j] = a[i][0]*b[0][j] +
- a[i][1]*b[1][j] +
- a[i][2]*b[2][j] +
- a[i][3]*b[3][j];
- };
-
- c = h;
- }
-
-
- int surface;
-
- #include <math.h>
-
- matrix XControlT =
- {0,0,0,0,
- 1/3.0, 1/3.0, 1/3.0, 1/3.0,
- 2/3.0, 2/3.0, 2/3.0, 2/3.0,
- 1, 1, 1, 1
- };
-
- matrix X,Y,Z;
-
- matrix YControlT =
- {
- 0, 1/3.0, 2/3.0, 1,
- 0, 1/3.0, 2/3.0, 1,
- 0, 1/3.0, 2/3.0, 1,
- 0, 1/3.0, 2/3.0, 1,
- };
-
- matrix ZControlT =
- {
- 0, 0, 0, 0,
- 0, 0, 0, 0,
- 0, 0, 0, 0,
- 0, 0, 0, 0,
- };
-
- matrix XControl,YControl,ZControl;
-
-
- matrix Bezier =
- {
- -1, 3, -3, 1,
- 3, -6, 3, 0,
- -3, 3, 0, 0,
- 1, 0, 0, 0
- };
- matrix B_Spline =
- {
- -1/6.0, 3/6.0, -3/6.0, 1/6.0,
- 3/6.0, -6/6.0, 3/6.0, 0,
- -3/6.0, 0, 3/6.0, 0,
- 1/6.0, 4/6.0, 1/6.0, 0,
- };
- matrix BezierInv =
- {
- 0, 0, 0, 1,
- 0, 0, 1/3.0, 1,
- 0, 1/3.0, 2/3.0, 1,
- 1, 1, 1, 1,
- };
- matrix Tchebi =
- {
- 0, 0, 0, 4,
- 0, 0, 2, 0,
- 0, 1, 0, -3,
- 1, 0, -1, 0
- };
- matrix Trans =
- {
- 1/6.0, 2/3.0, 1/6.0, 0 ,
- 0, 2/3.0, 1/3.0, 0 ,
- 0, 1/3.0, 2/3.0, 0 ,
- 0, 1/6.0, 2/3.0, 1/6.0
- };
- matrix TransT =
- {
- 1/6.0, 0, 0, 0,
- 2/3.0, 2/3.0, 1/3.0, 1/6.0,
- 1/6.0, 1/3.0, 2/3.0, 2/3.0,
- 0, 0, 0, 1/6.0
- };
- int ok = 1;
- double u1,v1,u2,v2;
-
- main(argc,argv)
- int argc;
- char *argv[];
- {
- char s[256];
-
- do
- {
- scanf("%[^\n]s",s);
- getchar();
- }
- while(strncmp(s,"ENDBODY",7) != 0);
-
- printf("# a DRAGON-ENFF-file\n");
- printf("v\n");
- printf("from 0 0 165.5\n");
- printf("at 0 0 0\n");
- printf("up 0 1 0\n");
- printf("angle 30\n");
- printf("hither 1\n");
- printf("resolution 300 300\n");
- printf("b 0.753 0.078 0.361\n");
- printf("l 500 500 500 1 1 1 1\n");
- printf("l 500 500 500 1 1 1 1\n");
- printf("f 1 0.5 0.1 0.75 0.25 20 0 0\n");
- printf("#\n");
-
- while(GetPatch())
- {
- FixPatch();
- PrintPatch();
- };
-
- printf("# end\n");
- exit(0);
- }
-
-
- int
- GetPatch()
- {
- int i,j,dum;
- char s[256];
-
- do
- {
- dum = scanf("%[^\n]s",s);
- getchar();
- }
- while((strncmp(s,"spline",6) != 0) && (strncmp(s,"end",3) != 0));
- if (strncmp(s,"end",3) == 0) return(0);
-
- for (i=0;i<4;i++)
- for(j =0; j<4; j++)
- scanf("%d %f %f %f",&dum, &(X[i][j]),&(Y[i][j]),&(Z[i][j]));
-
- return(1);
- }
-
-
- FixPatch()
- {
- MxMultiply(Trans,X,X);
- MxMultiply(X,TransT,X);
-
- MxMultiply(Trans,Y,Y);
- MxMultiply(Y,TransT,Y);
-
- MxMultiply(Trans,Z,Z);
- MxMultiply(Z,TransT,Z);
- }
-
-
- static int patch_no = 1;
-
-
- PrintPatch()
- {
- int i,j;
- double du,dv;
-
- printf("# a new Bezier-patch --> no: %d\n",patch_no);
- printf("pb 3 3\n");
- for(i=0;i<4;i++)
- for (j=0;j<4;j++)
- printf("%g %g %g\n",X[i][j],Y[i][j],Z[i][j]);
-
- patch_no++;
- }
-
-