1 |
– |
/* Copyright (c) 1995 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* Convert MGF to Inventor file. |
6 |
|
* |
9 |
|
|
10 |
|
#include <stdio.h> |
11 |
|
|
12 |
+ |
#include <stdlib.h> |
13 |
+ |
|
14 |
|
#include <math.h> |
15 |
|
|
16 |
|
#include <ctype.h> |
17 |
|
|
18 |
+ |
#include <string.h> |
19 |
+ |
|
20 |
|
#include "parser.h" |
21 |
|
|
22 |
|
#include "lookup.h" |
23 |
|
|
24 |
|
#define O_INV1 1 /* Inventor 1.0 output */ |
25 |
|
#define O_INV2 2 /* Inventor 2.0 output */ |
26 |
< |
#define O_VRML 3 /* VRML output */ |
26 |
> |
#define O_VRML1 3 /* VRML 1.0 output */ |
27 |
|
|
28 |
|
#define MAXID 48 /* maximum identifier length */ |
29 |
|
|
98 |
|
/* get options and print format line */ |
99 |
|
for (i = 1; i < argc && argv[i][0] == '-'; i++) |
100 |
|
if (!strcmp(argv[i], "-vrml")) |
101 |
< |
outtype = O_VRML; |
101 |
> |
outtype = O_VRML1; |
102 |
|
else if (!strcmp(argv[i], "-1")) |
103 |
|
outtype = O_INV1; |
104 |
|
else if (!strcmp(argv[i], "-2")) |
112 |
|
case O_INV2: |
113 |
|
printf("#Inventor V2.0 ascii\n"); |
114 |
|
break; |
115 |
< |
case O_VRML: |
116 |
< |
printf("#VRML 1.0 ascii\n"); |
115 |
> |
case O_VRML1: |
116 |
> |
printf("#VRML V1.0 ascii\n"); |
117 |
|
break; |
118 |
|
} |
119 |
|
printf("## Translated from MGF Version %d.%d\n", MG_VMAJOR, MG_VMINOR); |
339 |
|
mgf2rgb(&c_cmaterial->rs_c, c_cmaterial->rs, rgbval); |
340 |
|
printf("%sspecularColor %.4f %.4f %.4f\n", tabs, |
341 |
|
rgbval[0], rgbval[1], rgbval[2]); |
342 |
< |
printf("%sshininess %.3f\n", tabs, 1.-c_cmaterial->rs_a); |
342 |
> |
printf("%sshininess %.3f\n", tabs, 1.-sqrt(c_cmaterial->rs_a)); |
343 |
|
} |
344 |
|
if (c_cmaterial->ed > FTINY) { |
345 |
|
mgf2rgb(&c_cmaterial->ed_c, 1.0, rgbval); |
459 |
|
if (put_material() < 0) |
460 |
|
return(MG_EBADMAT); |
461 |
|
/* get endpoints */ |
462 |
< |
if ((v1 = c_getvert(av[1])) == NULL | (v2 = c_getvert(av[3])) == NULL) |
462 |
> |
if (((v1 = c_getvert(av[1])) == NULL) | ((v2 = c_getvert(av[3])) == NULL)) |
463 |
|
return(MG_EUNDEF); |
464 |
|
/* get radius */ |
465 |
|
if (!isflt(av[2])) |
469 |
|
va[1] = v2->p[1] - v1->p[1]; |
470 |
|
va[2] = v2->p[2] - v1->p[2]; |
471 |
|
length = sqrt(DOT(va,va)); |
472 |
< |
angle = acos(va[1]/length); |
472 |
> |
if (va[1] >= length) |
473 |
> |
angle = 0.; |
474 |
> |
else if (va[1] <= -length) |
475 |
> |
angle = PI; |
476 |
> |
else |
477 |
> |
angle = acos(va[1]/length); |
478 |
|
printf("%sTranslation { translation %13.9g %13.9g %13.9g }\n", tabs, |
479 |
|
.5*(v1->p[0]+v2->p[0]), .5*(v1->p[1]+v2->p[1]), |
480 |
|
.5*(v1->p[2]+v2->p[2])); |