1 |
< |
/* Copyright (c) 1986 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1991 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
27 |
|
* The last vertex is automatically connected to the first. |
28 |
|
*/ |
29 |
|
|
30 |
+ |
#ifdef SMLFLT |
31 |
+ |
#define VERTEPS 1e-2 /* allowed vertex error */ |
32 |
+ |
#else |
33 |
|
#define VERTEPS 1e-4 /* allowed vertex error */ |
34 |
+ |
#endif |
35 |
|
|
36 |
|
|
37 |
|
FACE * |
38 |
|
getface(o) /* get arguments for a face */ |
39 |
|
OBJREC *o; |
40 |
|
{ |
37 |
– |
double fabs(); |
41 |
|
double d1; |
42 |
|
int badvert; |
43 |
|
FVECT v1, v2, v3; |
54 |
|
if (o->oargs.nfargs < 9 || o->oargs.nfargs % 3) |
55 |
|
objerror(o, USER, "bad # arguments"); |
56 |
|
|
57 |
+ |
o->os = (char *)f; /* save face */ |
58 |
+ |
|
59 |
|
f->va = o->oargs.farg; |
60 |
|
f->nv = o->oargs.nfargs / 3; |
61 |
|
/* compute area and normal */ |
74 |
|
f->area = normalize(f->norm); |
75 |
|
if (f->area == 0.0) { |
76 |
|
objerror(o, WARNING, "zero area"); /* used to be fatal */ |
77 |
< |
f->const = 0.0; |
77 |
> |
f->offset = 0.0; |
78 |
|
f->ax = 0; |
79 |
|
return(f); |
80 |
|
} |
81 |
|
f->area *= 0.5; |
82 |
< |
/* compute constant */ |
82 |
> |
/* compute offset */ |
83 |
|
badvert = 0; |
84 |
< |
f->const = DOT(f->norm, VERTEX(f,0)); |
84 |
> |
f->offset = DOT(f->norm, VERTEX(f,0)); |
85 |
|
for (i = 1; i < f->nv; i++) { |
86 |
|
d1 = DOT(f->norm, VERTEX(f,i)); |
87 |
< |
badvert += fabs(d1 - f->const/i) > VERTEPS; |
88 |
< |
f->const += d1; |
87 |
> |
badvert += fabs(d1 - f->offset/i) > VERTEPS; |
88 |
> |
f->offset += d1; |
89 |
|
} |
90 |
< |
f->const /= f->nv; |
90 |
> |
f->offset /= (double)f->nv; |
91 |
|
if (badvert) |
92 |
|
objerror(o, WARNING, "non-planar vertex"); |
93 |
|
/* find axis */ |
95 |
|
if (fabs(f->norm[2]) > fabs(f->norm[f->ax])) |
96 |
|
f->ax = 2; |
97 |
|
|
93 |
– |
(FACE *)o->os = f; /* save face */ |
98 |
|
return(f); |
99 |
|
} |
100 |
|
|
102 |
|
freeface(o) /* free memory associated with face */ |
103 |
|
OBJREC *o; |
104 |
|
{ |
105 |
+ |
if (o->os == NULL) |
106 |
+ |
return; |
107 |
|
free(o->os); |
108 |
|
o->os = NULL; |
109 |
|
} |
116 |
|
int ncross, n; |
117 |
|
double x, y; |
118 |
|
register int xi, yi; |
119 |
< |
register double *p0, *p1; |
119 |
> |
register FLOAT *p0, *p1; |
120 |
|
|
121 |
|
xi = (f->ax+1)%3; |
122 |
|
yi = (f->ax+2)%3; |