--- ray/src/cv/mgflib/mgf2inv.c 1995/12/05 10:59:27 1.4 +++ ray/src/cv/mgflib/mgf2inv.c 2003/11/15 17:54:06 1.11 @@ -1,9 +1,6 @@ -/* Copyright (c) 1995 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: mgf2inv.c,v 1.11 2003/11/15 17:54:06 schorsch Exp $"; #endif - /* * Convert MGF to Inventor file. * @@ -12,17 +9,21 @@ static char SCCSid[] = "$SunId$ LBL"; #include +#include + #include #include +#include + #include "parser.h" #include "lookup.h" #define O_INV1 1 /* Inventor 1.0 output */ #define O_INV2 2 /* Inventor 2.0 output */ -#define O_VRML 3 /* VRML output */ +#define O_VRML1 3 /* VRML 1.0 output */ #define MAXID 48 /* maximum identifier length */ @@ -60,15 +61,24 @@ char tabs[MAXIND*SHIFTW+1]; /* current tab-in string * int outtype = O_INV2; /* output format */ -extern int i_comment(), i_object(), i_xf(), - i_cyl(), i_face(), i_sph(); +int i_comment(int ac, char **av); +int i_object(int ac, char **av); +int i_xf(int ac, char **av); +int put_xform(register XF_SPEC *spec); +int put_material(void); +int i_face(int ac, char **av); +int i_sph(int ac, char **av); +int i_cyl(int ac, char **av); +char * to_id(register char *name); +char * to_id(register char *name); +void flush_cache(void); -extern char *to_id(); - -main(argc, argv) -int argc; -char *argv[]; +int +main( + int argc, + char *argv[] +) { int i; /* initialize dispatch table */ @@ -97,7 +107,7 @@ char *argv[]; /* get options and print format line */ for (i = 1; i < argc && argv[i][0] == '-'; i++) if (!strcmp(argv[i], "-vrml")) - outtype = O_VRML; + outtype = O_VRML1; else if (!strcmp(argv[i], "-1")) outtype = O_INV1; else if (!strcmp(argv[i], "-2")) @@ -111,8 +121,8 @@ char *argv[]; case O_INV2: printf("#Inventor V2.0 ascii\n"); break; - case O_VRML: - printf("#VRML 1.0 ascii\n"); + case O_VRML1: + printf("#VRML V1.0 ascii\n"); break; } printf("## Translated from MGF Version %d.%d\n", MG_VMAJOR, MG_VMINOR); @@ -153,8 +163,10 @@ userr: } -indent(deeper) /* indent in or out */ -int deeper; +void +indent( /* indent in or out */ + int deeper +) { static int level; /* current nesting level */ register int i; @@ -174,9 +186,10 @@ int deeper; int -i_comment(ac, av) /* transfer comment as is */ -int ac; -char **av; +i_comment( /* transfer comment as is */ + int ac, + char **av +) { fputs(tabs, stdout); putchar('#'); /* Inventor comment character */ @@ -190,9 +203,10 @@ char **av; int -i_object(ac, av) /* group object name */ -int ac; -char **av; +i_object( /* group object name */ + int ac, + char **av +) { static int objnest; @@ -216,9 +230,10 @@ char **av; int -i_xf(ac, av) /* transform object(s) */ -int ac; -char **av; +i_xf( /* transform object(s) */ + int ac, + char **av +) { static long xfid; register XF_SPEC *spec; @@ -284,8 +299,9 @@ char **av; int -put_xform(spec) /* translate and print transform */ -register XF_SPEC *spec; +put_xform( /* translate and print transform */ + register XF_SPEC *spec +) { register char **av; register int n; @@ -315,7 +331,7 @@ register XF_SPEC *spec; int -put_material() /* put out current material */ +put_material(void) /* put out current material */ { char *mname = curmatname; float rgbval[3]; @@ -351,7 +367,8 @@ put_material() /* put out current material */ indent(0); printf("%s}\n", tabs); if (outtype != O_INV1) - printf("%sShapeHints { shapeType %s }\n", tabs, + printf("%sShapeHints { shapeType %s faceType UNKNOWN_FACE_TYPE }\n", + tabs, c_cmaterial->sided ? "SOLID" : "UNKNOWN_SHAPE_TYPE"); indent(0); printf("%s}\n", tabs); @@ -361,9 +378,10 @@ put_material() /* put out current material */ int -i_face(ac, av) /* translate an N-sided face */ -int ac; -char **av; +i_face( /* translate an N-sided face */ + int ac, + char **av +) { static char lastmat[MAXID]; struct face *newf; @@ -411,9 +429,10 @@ char **av; int -i_sph(ac, av) /* translate sphere description */ -int ac; -char **av; +i_sph( /* translate sphere description */ + int ac, + char **av +) { register C_VERTEX *cent; @@ -441,9 +460,10 @@ char **av; int -i_cyl(ac, av) /* translate a cylinder description */ -int ac; -char **av; +i_cyl( /* translate a cylinder description */ + int ac, + char **av +) { register C_VERTEX *v1, *v2; FVECT va; @@ -458,7 +478,7 @@ char **av; if (put_material() < 0) return(MG_EBADMAT); /* get endpoints */ - if ((v1 = c_getvert(av[1])) == NULL | (v2 = c_getvert(av[3])) == NULL) + if (((v1 = c_getvert(av[1])) == NULL) | ((v2 = c_getvert(av[3])) == NULL)) return(MG_EUNDEF); /* get radius */ if (!isflt(av[2])) @@ -468,7 +488,12 @@ char **av; va[1] = v2->p[1] - v1->p[1]; va[2] = v2->p[2] - v1->p[2]; length = sqrt(DOT(va,va)); - angle = acos(va[1]/length); + if (va[1] >= length) + angle = 0.; + else if (va[1] <= -length) + angle = PI; + else + angle = acos(va[1]/length); printf("%sTranslation { translation %13.9g %13.9g %13.9g }\n", tabs, .5*(v1->p[0]+v2->p[0]), .5*(v1->p[1]+v2->p[1]), .5*(v1->p[2]+v2->p[2])); @@ -484,8 +509,9 @@ char **av; char * -to_id(name) /* make sure a name is a valid Inventor ID */ -register char *name; +to_id( /* make sure a name is a valid Inventor ID */ + register char *name +) { static char id[MAXID]; register char *cp; @@ -500,7 +526,8 @@ register char *name; } -flush_cache() /* put out cached faces */ +void +flush_cache(void) /* put out cached faces */ { int donorms = 0; register struct face *f;