1 |
– |
/* Copyright (c) 1997 Silicon Graphics, Inc. */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ SGI"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* Holodeck beam support for display process |
6 |
|
*/ |
16 |
|
|
17 |
|
|
18 |
|
int |
19 |
< |
npixels(vp, hr, vr, hp, bi) /* compute appropriate number to evaluate */ |
19 |
> |
npixels(vp, hr, vr, hp, bi) /* compute appropriate nrays to evaluate */ |
20 |
|
register VIEW *vp; |
21 |
|
int hr, vr; |
22 |
|
HOLO *hp; |
24 |
|
{ |
25 |
|
VIEW vrev; |
26 |
|
GCOORD gc[2]; |
27 |
< |
FVECT cp[4], ip[4]; |
28 |
< |
double af, ab; |
27 |
> |
FVECT cp[4], ip[4], pf, pb; |
28 |
> |
double af, ab, sf2, sb2, dfb2, df2, db2, penalty; |
29 |
|
register int i; |
30 |
+ |
/* special case */ |
31 |
+ |
if (hr <= 0 | vr <= 0) |
32 |
+ |
return(0); |
33 |
|
/* compute cell corners in image */ |
34 |
|
if (!hdbcoord(gc, hp, bi)) |
35 |
|
error(CONSISTENCY, "bad beam index in npixels"); |
36 |
|
hdcell(cp, hp, gc+1); /* find cell on front image */ |
37 |
< |
for (i = 0; i < 4; i++) { |
37 |
> |
for (i = 3; i--; ) /* compute front center */ |
38 |
> |
pf[i] = 0.5*(cp[0][i] + cp[2][i]); |
39 |
> |
sf2 = 0.25*dist2(cp[0], cp[2]); /* compute half diagonal length */ |
40 |
> |
for (i = 0; i < 4; i++) { /* compute visible quad */ |
41 |
|
viewloc(ip[i], vp, cp[i]); |
42 |
|
if (ip[i][2] < 0.) { |
43 |
|
af = 0; |
51 |
|
(ip[2][0]-ip[0][0])*(ip[1][1]-ip[0][1]); |
52 |
|
af += (ip[2][0]-ip[3][0])*(ip[1][1]-ip[3][1]) - |
53 |
|
(ip[1][0]-ip[3][0])*(ip[2][1]-ip[3][1]); |
54 |
< |
if (af >= 0) af *= 0.5; |
52 |
< |
else af *= -0.5; |
54 |
> |
af *= af >= 0 ? 0.5 : -0.5; |
55 |
|
getback: |
56 |
|
copystruct(&vrev, vp); /* compute reverse view */ |
57 |
|
for (i = 0; i < 3; i++) { |
61 |
|
vrev.vvec[i] = -vp->vvec[i]; |
62 |
|
} |
63 |
|
hdcell(cp, hp, gc); /* find cell on back image */ |
64 |
< |
for (i = 0; i < 4; i++) { |
64 |
> |
for (i = 3; i--; ) /* compute rear center */ |
65 |
> |
pb[i] = 0.5*(cp[0][i] + cp[2][i]); |
66 |
> |
sb2 = 0.25*dist2(cp[0], cp[2]); /* compute half diagonal length */ |
67 |
> |
for (i = 0; i < 4; i++) { /* compute visible quad */ |
68 |
|
viewloc(ip[i], &vrev, cp[i]); |
69 |
< |
if (ip[i][2] < 0.) |
70 |
< |
return((int)(af + 0.5)); |
69 |
> |
if (ip[i][2] < 0.) { |
70 |
> |
ab = 0; |
71 |
> |
goto finish; |
72 |
> |
} |
73 |
|
ip[i][0] *= (double)hr; /* scale by resolution */ |
74 |
|
ip[i][1] *= (double)vr; |
75 |
|
} |
78 |
|
(ip[2][0]-ip[0][0])*(ip[1][1]-ip[0][1]); |
79 |
|
ab += (ip[2][0]-ip[3][0])*(ip[1][1]-ip[3][1]) - |
80 |
|
(ip[1][0]-ip[3][0])*(ip[2][1]-ip[3][1]); |
81 |
< |
if (ab >= 0) ab *= 0.5; |
82 |
< |
else ab *= -0.5; |
83 |
< |
/* round off smaller area */ |
84 |
< |
if (af <= ab) |
85 |
< |
return((int)(af + 0.5)); |
86 |
< |
return((int)(ab + 0.5)); |
81 |
> |
ab *= ab >= 0 ? 0.5 : -0.5; |
82 |
> |
finish: /* compute penalty based on dist. sightline - viewpoint */ |
83 |
> |
df2 = dist2(vp->vp, pf); |
84 |
> |
db2 = dist2(vp->vp, pb); |
85 |
> |
dfb2 = dist2(pf, pb); |
86 |
> |
penalty = dfb2 + df2 - db2; |
87 |
> |
penalty = df2 - 0.25*penalty*penalty/dfb2; |
88 |
> |
if (df2 > db2) penalty /= df2 <= dfb2 ? sb2 : sb2*df2/dfb2; |
89 |
> |
else penalty /= db2 <= dfb2 ? sf2 : sf2*db2/dfb2; |
90 |
> |
if (penalty < 1.) penalty = 1.; |
91 |
> |
/* round off smaller non-zero area */ |
92 |
> |
if (ab <= FTINY || (af > FTINY && af <= ab)) |
93 |
> |
return((int)(af/penalty + 0.5)); |
94 |
> |
return((int)(ab/penalty + 0.5)); |
95 |
|
} |
96 |
|
|
97 |
|
|
281 |
|
if (cl.cl == NULL) |
282 |
|
goto memerr; |
283 |
|
cl.n = 0; /* add cells within pyramid */ |
284 |
< |
visit_cells(org, dir, hp, addcell, &cl); |
284 |
> |
visit_cells(org, dir, hp, addcell, (char *)&cl); |
285 |
|
if (!cl.n) { |
286 |
< |
free((char *)cl.cl); |
286 |
> |
free((void *)cl.cl); |
287 |
|
return(NULL); |
288 |
|
} |
289 |
|
*np = cl.n * orient; |