| 1 |
< |
/* Copyright (c) 1997 Silicon Graphics, Inc. */ |
| 1 |
> |
/* Copyright (c) 1998 Silicon Graphics, Inc. */ |
| 2 |
|
|
| 3 |
|
#ifndef lint |
| 4 |
|
static char SCCSid[] = "$SunId$ SGI"; |
| 13 |
|
#include "random.h" |
| 14 |
|
|
| 15 |
|
|
| 16 |
+ |
VIEWPOINT myeye; /* target view position */ |
| 17 |
+ |
|
| 18 |
+ |
|
| 19 |
|
packrays(rod, p) /* pack ray origins and directions */ |
| 20 |
|
register float *rod; |
| 21 |
|
register PACKET *p; |
| 22 |
|
{ |
| 23 |
< |
static FVECT ro, rd; |
| 23 |
> |
float packdc2[RPACKSIZ]; |
| 24 |
> |
int iterleft = 3*p->nr + 9; |
| 25 |
> |
BYTE rpos[2][2]; |
| 26 |
> |
FVECT ro, rd, rp1; |
| 27 |
|
GCOORD gc[2]; |
| 28 |
< |
int ila[2], hsh; |
| 29 |
< |
double d, sl[4]; |
| 30 |
< |
register int i; |
| 28 |
> |
double d, dc2, md2, td2, dc2worst = FHUGE; |
| 29 |
> |
int i; |
| 30 |
> |
register int ii; |
| 31 |
|
|
| 32 |
|
if (!hdbcoord(gc, hdlist[p->hd], p->bi)) |
| 33 |
|
error(CONSISTENCY, "bad beam index in packrays"); |
| 34 |
< |
ila[0] = p->hd; ila[1] = p->bi; |
| 35 |
< |
hsh = ilhash(ila,2) + p->nc; |
| 36 |
< |
for (i = 0; i < p->nr; i++) { |
| 37 |
< |
multisamp(sl, 4, urand(hsh+i)); |
| 38 |
< |
p->ra[i].r[0][0] = sl[0] * 256.; |
| 39 |
< |
p->ra[i].r[0][1] = sl[1] * 256.; |
| 40 |
< |
p->ra[i].r[1][0] = sl[2] * 256.; |
| 41 |
< |
p->ra[i].r[1][1] = sl[3] * 256.; |
| 42 |
< |
d = hdray(ro, rd, hdlist[p->hd], gc, p->ra[i].r); |
| 34 |
> |
td2 = myeye.rng + FTINY; td2 *= td2; |
| 35 |
> |
for (i = 0, md2 = 0.; i < p->nr || (md2 > td2 && iterleft--); ) { |
| 36 |
> |
rpos[0][0] = frandom() * 256.; |
| 37 |
> |
rpos[0][1] = frandom() * 256.; |
| 38 |
> |
rpos[1][0] = frandom() * 256.; |
| 39 |
> |
rpos[1][1] = frandom() * 256.; |
| 40 |
> |
d = hdray(ro, rd, hdlist[p->hd], gc, rpos); |
| 41 |
> |
if (myeye.rng > FTINY) { /* check eyepoint */ |
| 42 |
> |
register int nexti; |
| 43 |
> |
|
| 44 |
> |
VSUM(rp1, ro, rd, d); |
| 45 |
> |
dc2 = dist2line(myeye.vpt, ro, rp1) / p->nr; |
| 46 |
> |
if (i == p->nr) { /* packet full */ |
| 47 |
> |
if (dc2 >= dc2worst) /* quick check */ |
| 48 |
> |
continue; |
| 49 |
> |
nexti = 0; /* find worst */ |
| 50 |
> |
for (ii = i; --ii; ) |
| 51 |
> |
if (packdc2[ii] > packdc2[nexti]) |
| 52 |
> |
nexti = ii; |
| 53 |
> |
if (dc2 >= (dc2worst = packdc2[nexti])) |
| 54 |
> |
continue; /* worse than worst */ |
| 55 |
> |
md2 -= dc2worst; |
| 56 |
> |
} else |
| 57 |
> |
nexti = i++; |
| 58 |
> |
md2 += packdc2[nexti] = dc2; /* new distance */ |
| 59 |
> |
ii = nexti; /* put it here */ |
| 60 |
> |
} else |
| 61 |
> |
ii = i++; |
| 62 |
|
if (p->offset != NULL) { |
| 63 |
< |
VSUM(ro, ro, rd, d); /* exterior only */ |
| 64 |
< |
p->offset[i] = d; |
| 63 |
> |
if (!vdef(OBSTRUCTIONS)) |
| 64 |
> |
d *= frandom(); /* random offset */ |
| 65 |
> |
VSUM(ro, ro, rd, d); /* advance ray */ |
| 66 |
> |
p->offset[ii] = d; |
| 67 |
|
} |
| 68 |
< |
VCOPY(rod, ro); |
| 69 |
< |
rod += 3; |
| 70 |
< |
VCOPY(rod, rd); |
| 71 |
< |
rod += 3; |
| 68 |
> |
p->ra[ii].r[0][0] = rpos[0][0]; |
| 69 |
> |
p->ra[ii].r[0][1] = rpos[0][1]; |
| 70 |
> |
p->ra[ii].r[1][0] = rpos[1][0]; |
| 71 |
> |
p->ra[ii].r[1][1] = rpos[1][1]; |
| 72 |
> |
VCOPY(rod+6*ii, ro); |
| 73 |
> |
VCOPY(rod+6*ii+3, rd); |
| 74 |
|
} |
| 75 |
+ |
#ifdef DEBUG |
| 76 |
+ |
fprintf(stderr, "%f mean distance for target %f (%d iterations left)\n", |
| 77 |
+ |
sqrt(md2), myeye.rng, iterleft); |
| 78 |
+ |
#endif |
| 79 |
|
} |
| 80 |
|
|
| 81 |
|
|
| 105 |
|
/* already closed? */ |
| 106 |
|
if (!nprocs) |
| 107 |
|
return; |
| 75 |
– |
wputs("closing rtrace process...\n"); |
| 108 |
|
/* flush beam queue */ |
| 109 |
|
done_packets(flush_queue()); |
| 110 |
+ |
/* sync holodeck */ |
| 111 |
+ |
hdsync(NULL, 1); |
| 112 |
|
/* close rtrace */ |
| 113 |
|
if ((status = end_rtrace())) |
| 114 |
|
error(WARNING, "bad exit status from rtrace"); |
| 115 |
< |
if (vdef(REPORT)) /* report time */ |
| 115 |
> |
if (vdef(REPORT)) { /* report time */ |
| 116 |
> |
eputs("rtrace process closed\n"); |
| 117 |
|
report(0); |
| 118 |
+ |
} |
| 119 |
|
return(status); /* return status */ |
| 120 |
|
} |
| 121 |
|
|
| 126 |
|
|
| 127 |
|
if (nprocs > 0) /* already running? */ |
| 128 |
|
return; |
| 93 |
– |
wputs("restarting rtrace process...\n"); |
| 129 |
|
starttime = time(NULL); /* reset start time and counts */ |
| 130 |
|
npacksdone = nraysdone = 0L; |
| 131 |
|
if (vdef(TIME)) /* reset end time */ |
| 137 |
|
} |
| 138 |
|
if (start_rtrace() < 1) /* start rtrace */ |
| 139 |
|
error(WARNING, "cannot restart rtrace"); |
| 140 |
< |
else if (vdef(REPORT)) |
| 140 |
> |
else if (vdef(REPORT)) { |
| 141 |
> |
eputs("rtrace process restarted\n"); |
| 142 |
|
report(0); |
| 143 |
+ |
} |
| 144 |
|
} |
| 145 |
|
|
| 146 |
|
|
| 147 |
|
getradfile() /* run rad and get needed variables */ |
| 148 |
|
{ |
| 149 |
< |
static short mvar[] = {OCTREE,-1}; |
| 149 |
> |
static short mvar[] = {OCTREE,EYESEP,-1}; |
| 150 |
|
static char tf1[] = TEMPLATE; |
| 151 |
|
char tf2[64]; |
| 152 |
|
char combuf[256]; |
| 155 |
|
register char *cp; |
| 156 |
|
/* check if rad file specified */ |
| 157 |
|
if (!vdef(RIF)) |
| 158 |
< |
return; |
| 158 |
> |
return(0); |
| 159 |
|
/* create rad command */ |
| 160 |
|
mktemp(tf1); |
| 161 |
|
sprintf(tf2, "%s.rif", tf1); |
| 178 |
|
strcpy(pippt, "> /dev/null"); /* nothing to match */ |
| 179 |
|
else |
| 180 |
|
sprintf(cp, ")[ \t]*=' > %s", tf2); |
| 181 |
< |
if (system(combuf)) { |
| 182 |
< |
unlink(tf2); /* clean up */ |
| 183 |
< |
unlink(tf1); |
| 184 |
< |
error(SYSTEM, "cannot execute rad command"); |
| 148 |
< |
} |
| 181 |
> |
#ifdef DEBUG |
| 182 |
> |
wputs(combuf); wputs("\n"); |
| 183 |
> |
#endif |
| 184 |
> |
system(combuf); /* ignore exit code */ |
| 185 |
|
if (pippt == NULL) { |
| 186 |
|
loadvars(tf2); /* load variables */ |
| 187 |
|
unlink(tf2); |
| 188 |
|
} |
| 189 |
|
rtargc += wordfile(rtargv+rtargc, tf1); /* get rtrace options */ |
| 190 |
|
unlink(tf1); /* clean up */ |
| 191 |
+ |
return(1); |
| 192 |
|
} |
| 193 |
|
|
| 194 |
|
|