52 |
|
VERTEX *vlist = NULL; /* our vertex list */ |
53 |
|
int nverts = 0; /* number of vertices in our list */ |
54 |
|
|
55 |
< |
#define novert(i) ((i)<0|(i)>=nverts || !(vlist[i].flags&V_DEFINED)) |
55 |
> |
#define novert(i) (((i)<0)|((i)>=nverts) || !(vlist[i].flags&V_DEFINED)) |
56 |
|
|
57 |
|
#define CHUNKSIZ 128 /* vertex allocation chunk size */ |
58 |
|
|
199 |
|
char *pn, *mod, *obj; |
200 |
|
register VERTEX *v1, *v2, *v3; |
201 |
|
{ |
202 |
+ |
static char vfmt[] = "%18.12g %18.12g %18.12g\n"; |
203 |
|
static int ntri = 0; |
204 |
+ |
int flatness = ISFLAT; |
205 |
|
BARYCCM bvecs; |
206 |
< |
FLOAT bvm[3][3]; |
206 |
> |
RREAL bvm[3][3]; |
207 |
|
register int i; |
208 |
|
/* compute barycentric coordinates */ |
209 |
|
if (v1->flags & v2->flags & v3->flags & (V_HASINDX|V_HASNORM)) |
210 |
|
if (comp_baryc(&bvecs, v1->pos, v2->pos, v3->pos) < 0) |
211 |
|
return; |
212 |
+ |
/* check flatness */ |
213 |
+ |
if (v1->flags & v2->flags & v3->flags & V_HASNORM) { |
214 |
+ |
flatness = flat_tri(v1->pos, v2->pos, v3->pos, |
215 |
+ |
v1->nor, v2->nor, v3->nor); |
216 |
+ |
if (flatness == DEGEN) |
217 |
+ |
return; |
218 |
+ |
} |
219 |
|
/* put out texture (if any) */ |
220 |
< |
if (v1->flags & v2->flags & v3->flags & V_HASNORM && |
212 |
< |
!flat_tri(v1->pos, v2->pos, v3->pos, |
213 |
< |
v1->nor, v2->nor, v3->nor)) { |
220 |
> |
if (flatness == ISBENT || flatness == RVBENT) { |
221 |
|
printf("\n%s texfunc %s\n", mod, TEXNAME); |
222 |
|
mod = TEXNAME; |
223 |
|
printf("4 dx dy dz %s\n", TCALNAME); |
242 |
|
} |
243 |
|
put_baryc(&bvecs, bvm, 2); |
244 |
|
} |
245 |
< |
/* put out triangle */ |
245 |
> |
/* put out (reversed) triangle */ |
246 |
|
printf("\n%s polygon %s.%d\n", mod, obj, ++ntri); |
247 |
|
printf("0\n0\n9\n"); |
248 |
< |
printf("%18.12g %18.12g %18.12g\n", v1->pos[0],v1->pos[1],v1->pos[2]); |
249 |
< |
printf("%18.12g %18.12g %18.12g\n", v2->pos[0],v2->pos[1],v2->pos[2]); |
250 |
< |
printf("%18.12g %18.12g %18.12g\n", v3->pos[0],v3->pos[1],v3->pos[2]); |
248 |
> |
if (flatness == RVFLAT || flatness == RVBENT) { |
249 |
> |
printf(vfmt, v3->pos[0],v3->pos[1],v3->pos[2]); |
250 |
> |
printf(vfmt, v2->pos[0],v2->pos[1],v2->pos[2]); |
251 |
> |
printf(vfmt, v1->pos[0],v1->pos[1],v1->pos[2]); |
252 |
> |
} else { |
253 |
> |
printf(vfmt, v1->pos[0],v1->pos[1],v1->pos[2]); |
254 |
> |
printf(vfmt, v2->pos[0],v2->pos[1],v2->pos[2]); |
255 |
> |
printf(vfmt, v3->pos[0],v3->pos[1],v3->pos[2]); |
256 |
> |
} |
257 |
|
} |
258 |
|
|
259 |
|
|
270 |
|
if (vlist == NULL) |
271 |
|
vlist = (VERTEX *)malloc(nverts*sizeof(VERTEX)); |
272 |
|
else |
273 |
< |
vlist = (VERTEX *)realloc((char *)vlist, |
273 |
> |
vlist = (VERTEX *)realloc((void *)vlist, |
274 |
|
nverts*sizeof(VERTEX)); |
275 |
|
if (vlist == NULL) { |
276 |
|
fprintf(stderr, |