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); |
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])); |