--- ray/src/cv/mgflib/mgf2inv.c 1995/12/05 10:34:12 1.3 +++ ray/src/cv/mgflib/mgf2inv.c 2003/08/05 20:40:16 1.10 @@ -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.10 2003/08/05 20:40:16 greg 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 */ @@ -97,7 +98,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 +112,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); @@ -338,7 +339,7 @@ put_material() /* put out current material */ mgf2rgb(&c_cmaterial->rs_c, c_cmaterial->rs, rgbval); printf("%sspecularColor %.4f %.4f %.4f\n", tabs, rgbval[0], rgbval[1], rgbval[2]); - printf("%sshininess %.3f\n", tabs, 1.-c_cmaterial->rs_a); + printf("%sshininess %.3f\n", tabs, 1.-sqrt(c_cmaterial->rs_a)); } if (c_cmaterial->ed > FTINY) { mgf2rgb(&c_cmaterial->ed_c, 1.0, rgbval); @@ -351,7 +352,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); @@ -458,7 +460,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 +470,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]));