| 5 |
|
* Rtrace support routines for holodeck rendering |
| 6 |
|
*/ |
| 7 |
|
|
| 8 |
+ |
#include <time.h> |
| 9 |
+ |
|
| 10 |
|
#include "rholo.h" |
| 11 |
|
#include "paths.h" |
| 12 |
|
#include "random.h" |
| 22 |
|
double gmin[2], gmax[2]; /* grid coordinate limits */ |
| 23 |
|
}; /* a grid coordinate range */ |
| 24 |
|
|
| 25 |
+ |
static void initeyelim(struct gclim *gcl, HOLO *hp, GCOORD *gc); |
| 26 |
+ |
static void groweyelim(struct gclim *gcl, GCOORD *gc, |
| 27 |
+ |
double r0, double r1, int tight); |
| 28 |
+ |
static int clipeyelim(short rrng[2][2], struct gclim *gcl); |
| 29 |
|
|
| 30 |
< |
static |
| 31 |
< |
initeyelim(gcl, hp, gc) /* initialize grid coordinate limits */ |
| 32 |
< |
register struct gclim *gcl; |
| 33 |
< |
register HOLO *hp; |
| 34 |
< |
GCOORD *gc; |
| 30 |
> |
|
| 31 |
> |
static void |
| 32 |
> |
initeyelim( /* initialize grid coordinate limits */ |
| 33 |
> |
struct gclim *gcl, |
| 34 |
> |
HOLO *hp, |
| 35 |
> |
GCOORD *gc |
| 36 |
> |
) |
| 37 |
|
{ |
| 38 |
< |
register RREAL *v; |
| 39 |
< |
register int i; |
| 38 |
> |
RREAL *v; |
| 39 |
> |
int i; |
| 40 |
|
|
| 41 |
|
if (hp != NULL) { |
| 42 |
|
hdgrid(gcl->egp, gcl->hp = hp, myeye.vpt); |
| 46 |
|
gcl->erg2 *= (1./3.) * myeye.rng*myeye.rng; |
| 47 |
|
} |
| 48 |
|
if (gc != NULL) |
| 49 |
< |
copystruct(&gcl->gc, gc); |
| 49 |
> |
gcl->gc = *gc; |
| 50 |
|
gcl->gmin[0] = gcl->gmin[1] = FHUGE; |
| 51 |
|
gcl->gmax[0] = gcl->gmax[1] = -FHUGE; |
| 52 |
|
} |
| 53 |
|
|
| 54 |
|
|
| 55 |
< |
static |
| 56 |
< |
groweyelim(gcl, gc, r0, r1, tight) /* grow grid limits about eye point */ |
| 57 |
< |
register struct gclim *gcl; |
| 58 |
< |
GCOORD *gc; |
| 59 |
< |
double r0, r1; |
| 60 |
< |
int tight; |
| 55 |
> |
static void |
| 56 |
> |
groweyelim( /* grow grid limits about eye point */ |
| 57 |
> |
struct gclim *gcl, |
| 58 |
> |
GCOORD *gc, |
| 59 |
> |
double r0, |
| 60 |
> |
double r1, |
| 61 |
> |
int tight |
| 62 |
> |
) |
| 63 |
|
{ |
| 64 |
|
FVECT gp, ab; |
| 65 |
|
double ab2, od, cfact; |
| 107 |
|
f = wallpos*(wallpos*sqcoef[gw] + licoef[gw]) + cnst; |
| 108 |
|
for (i = 0; i < 2; i++) { |
| 109 |
|
if (i) { /* swap x and y coefficients */ |
| 110 |
< |
register double t; |
| 110 |
> |
double t; |
| 111 |
|
t = a; a = c; c = t; |
| 112 |
|
t = d; d = e; e = t; |
| 113 |
|
} |
| 116 |
|
d*(c*d-b*e) + f*b*b); |
| 117 |
|
while (n-- > 0) { |
| 118 |
|
if (gc->w>>1 == gi[i] && |
| 119 |
< |
(gc->w&1) ^ root[n] < gp[gc->w>>1]) { |
| 119 |
> |
(gc->w&1) ^ (root[n] < gp[gc->w>>1])) { |
| 120 |
|
if (gc->w&1) |
| 121 |
|
gcl->gmin[i] = -FHUGE; |
| 122 |
|
else |
| 142 |
|
n = quadratic(root, a, b*yex+d, yex*(yex*c+e)+f); |
| 143 |
|
while (n-- > 0) { |
| 144 |
|
if (gc->w>>1 == gi[i] && |
| 145 |
< |
(gc->w&1) ^ root[n] < gp[gc->w>>1]) |
| 145 |
> |
(gc->w&1) ^ (root[n] < gp[gc->w>>1])) |
| 146 |
|
continue; |
| 147 |
|
if (root[n] < gcl->gmin[i]) |
| 148 |
|
gcl->gmin[i] = root[n]; |
| 155 |
|
|
| 156 |
|
|
| 157 |
|
static int |
| 158 |
< |
clipeyelim(rrng, gcl) /* clip eye limits to grid cell */ |
| 159 |
< |
register short rrng[2][2]; |
| 160 |
< |
register struct gclim *gcl; |
| 158 |
> |
clipeyelim( /* clip eye limits to grid cell */ |
| 159 |
> |
short rrng[2][2], |
| 160 |
> |
struct gclim *gcl |
| 161 |
> |
) |
| 162 |
|
{ |
| 163 |
|
int incell = 1; |
| 164 |
< |
register int i; |
| 164 |
> |
int i; |
| 165 |
|
|
| 166 |
|
for (i = 0; i < 2; i++) { |
| 167 |
|
if (gcl->gmin[i] < gcl->gc.i[i]) |
| 181 |
|
} |
| 182 |
|
|
| 183 |
|
|
| 184 |
< |
packrays(rod, p) /* pack ray origins and directions */ |
| 185 |
< |
register float *rod; |
| 186 |
< |
register PACKET *p; |
| 184 |
> |
void |
| 185 |
> |
packrays( /* pack ray origins and directions */ |
| 186 |
> |
float *rod, |
| 187 |
> |
PACKET *p |
| 188 |
> |
) |
| 189 |
|
{ |
| 190 |
|
#if 0 |
| 191 |
|
double dist2sum = 0.; |
| 198 |
|
GCOORD gc[2]; |
| 199 |
|
FVECT ro, rd; |
| 200 |
|
double d; |
| 201 |
< |
register int i; |
| 201 |
> |
int i; |
| 202 |
|
|
| 203 |
|
if (!hdbcoord(gc, hdlist[p->hd], p->bi)) |
| 204 |
|
error(CONSISTENCY, "bad beam index in packrays"); |
| 216 |
|
retry: |
| 217 |
|
if (useyelim) { |
| 218 |
|
initeyelim(&eyelim, NULL, gc+1); |
| 219 |
< |
p->ra[i].r[0][0] = (int)(frandom()*rrng0[0][1]) |
| 220 |
< |
+ rrng0[0][0]; |
| 208 |
< |
p->ra[i].r[0][1] = (int)(frandom()*rrng0[1][1]) |
| 209 |
< |
+ rrng0[1][0]; |
| 219 |
> |
p->ra[i].r[0][0] = irandom(rrng0[0][1]) + rrng0[0][0]; |
| 220 |
> |
p->ra[i].r[0][1] = irandom(rrng0[1][1]) + rrng0[1][0]; |
| 221 |
|
groweyelim(&eyelim, gc, |
| 222 |
|
(1./256.)*(p->ra[i].r[0][0]+.5), |
| 223 |
|
(1./256.)*(p->ra[i].r[0][1]+.5), 1); |
| 230 |
|
#endif |
| 231 |
|
goto retry; |
| 232 |
|
} |
| 233 |
< |
p->ra[i].r[1][0] = (int)(frandom()*rrng1[0][1]) |
| 234 |
< |
+ rrng1[0][0]; |
| 224 |
< |
p->ra[i].r[1][1] = (int)(frandom()*rrng1[1][1]) |
| 225 |
< |
+ rrng1[1][0]; |
| 233 |
> |
p->ra[i].r[1][0] = irandom(rrng1[0][1]) + rrng1[0][0]; |
| 234 |
> |
p->ra[i].r[1][1] = irandom(rrng1[1][1]) + rrng1[1][0]; |
| 235 |
|
} else { |
| 236 |
< |
p->ra[i].r[0][0] = frandom() * 256.; |
| 237 |
< |
p->ra[i].r[0][1] = frandom() * 256.; |
| 238 |
< |
p->ra[i].r[1][0] = frandom() * 256.; |
| 239 |
< |
p->ra[i].r[1][1] = frandom() * 256.; |
| 236 |
> |
p->ra[i].r[0][0] = random() & 0xff; |
| 237 |
> |
p->ra[i].r[0][1] = random() & 0xff; |
| 238 |
> |
p->ra[i].r[1][0] = random() & 0xff; |
| 239 |
> |
p->ra[i].r[1][1] = random() & 0xff; |
| 240 |
|
} |
| 241 |
|
d = hdray(ro, rd, hdlist[p->hd], gc, p->ra[i].r); |
| 242 |
|
#if 0 |
| 261 |
|
} |
| 262 |
|
|
| 263 |
|
|
| 264 |
< |
donerays(p, rvl) /* encode finished ray computations */ |
| 265 |
< |
register PACKET *p; |
| 266 |
< |
register float *rvl; |
| 264 |
> |
void |
| 265 |
> |
donerays( /* encode finished ray computations */ |
| 266 |
> |
PACKET *p, |
| 267 |
> |
float *rvl |
| 268 |
> |
) |
| 269 |
|
{ |
| 270 |
|
double d; |
| 271 |
< |
register int i; |
| 271 |
> |
int i; |
| 272 |
|
|
| 273 |
|
for (i = 0; i < p->nr; i++) { |
| 274 |
|
setcolr(p->ra[i].v, rvl[0], rvl[1], rvl[2]); |
| 283 |
|
|
| 284 |
|
|
| 285 |
|
int |
| 286 |
< |
done_rtrace() /* clean up and close rtrace calculation */ |
| 286 |
> |
done_rtrace(void) /* clean up and close rtrace calculation */ |
| 287 |
|
{ |
| 288 |
|
int status; |
| 289 |
|
/* already closed? */ |
| 290 |
|
if (!nprocs) |
| 291 |
< |
return; |
| 291 |
> |
return(0); |
| 292 |
|
/* flush beam queue */ |
| 293 |
|
done_packets(flush_queue()); |
| 294 |
|
/* sync holodeck */ |
| 304 |
|
} |
| 305 |
|
|
| 306 |
|
|
| 307 |
< |
new_rtrace() /* restart rtrace calculation */ |
| 307 |
> |
void |
| 308 |
> |
new_rtrace(void) /* restart rtrace calculation */ |
| 309 |
|
{ |
| 310 |
|
char combuf[128]; |
| 311 |
|
|
| 329 |
|
} |
| 330 |
|
|
| 331 |
|
|
| 332 |
< |
getradfile() /* run rad and get needed variables */ |
| 332 |
> |
int |
| 333 |
> |
getradfile(void) /* run rad and get needed variables */ |
| 334 |
|
{ |
| 335 |
|
static short mvar[] = {OCTREE,EYESEP,-1}; |
| 336 |
|
static char tf1[] = TEMPLATE; |
| 337 |
|
char tf2[64]; |
| 338 |
|
char combuf[256]; |
| 339 |
< |
char *pippt; |
| 340 |
< |
register int i; |
| 341 |
< |
register char *cp; |
| 339 |
> |
char *pippt = NULL; |
| 340 |
> |
int i; |
| 341 |
> |
char *cp; |
| 342 |
|
/* check if rad file specified */ |
| 343 |
|
if (!vdef(RIF)) |
| 344 |
|
return(0); |
| 361 |
|
pippt = NULL; |
| 362 |
|
} |
| 363 |
|
if (pippt != NULL) |
| 364 |
< |
strcpy(pippt, "> /dev/null"); /* nothing to match */ |
| 364 |
> |
strcpy(pippt, "> " NULL_DEVICE); /* nothing to match */ |
| 365 |
|
else |
| 366 |
|
sprintf(cp, ")[ \t]*=' > %s", tf2); |
| 367 |
|
#ifdef DEBUG |
| 372 |
|
loadvars(tf2); /* load variables */ |
| 373 |
|
unlink(tf2); |
| 374 |
|
} |
| 375 |
< |
rtargc += wordfile(rtargv+rtargc, tf1); /* get rtrace options */ |
| 375 |
> |
/* get rtrace options */ |
| 376 |
> |
rtargc += wordfile(rtargv+rtargc, MAXRTARGC-rtargc, tf1); |
| 377 |
|
unlink(tf1); /* clean up */ |
| 378 |
|
return(1); |
| 379 |
|
} |
| 380 |
|
|
| 381 |
|
|
| 382 |
< |
report(t) /* report progress so far */ |
| 383 |
< |
time_t t; |
| 382 |
> |
void |
| 383 |
> |
report( /* report progress so far */ |
| 384 |
> |
time_t t |
| 385 |
> |
) |
| 386 |
|
{ |
| 387 |
|
static time_t seconds2go = 1000000; |
| 388 |
|
|