| 18 |
|
|
| 19 |
|
#include "random.h" |
| 20 |
|
|
| 21 |
+ |
#ifndef WFLUSH |
| 22 |
+ |
#define WFLUSH 30 /* flush after this many rays */ |
| 23 |
+ |
#endif |
| 24 |
|
|
| 25 |
+ |
|
| 26 |
|
getrect(s, r) /* get a box */ |
| 27 |
|
char *s; |
| 28 |
|
register RECT *r; |
| 31 |
|
|
| 32 |
|
if (*s && !strncmp(s, "all", strlen(s))) { |
| 33 |
|
r->l = r->d = 0; |
| 34 |
< |
r->r = ourview.hresolu; |
| 35 |
< |
r->u = ourview.vresolu; |
| 34 |
> |
r->r = hresolu; |
| 35 |
> |
r->u = vresolu; |
| 36 |
|
return(0); |
| 37 |
|
} |
| 38 |
|
if (sscanf(s, "%d %d %d %d", &x0, &y0, &x1, &y1) != 4) { |
| 61 |
|
} |
| 62 |
|
if (r->l < 0) r->l = 0; |
| 63 |
|
if (r->d < 0) r->d = 0; |
| 64 |
< |
if (r->r > ourview.hresolu) r->r = ourview.hresolu; |
| 65 |
< |
if (r->u > ourview.vresolu) r->u = ourview.vresolu; |
| 64 |
> |
if (r->r > hresolu) r->r = hresolu; |
| 65 |
> |
if (r->u > vresolu) r->u = vresolu; |
| 66 |
|
if (r->l > r->r) r->l = r->r; |
| 67 |
|
if (r->d > r->u) r->d = r->u; |
| 68 |
|
return(0); |
| 93 |
|
(*dev->comout)("Pick view center\n"); |
| 94 |
|
if ((*dev->getcur)(&x, &y) == ABORT) |
| 95 |
|
return(-1); |
| 96 |
< |
rayview(thisray.rorg, thisray.rdir, &ourview, x+.5, y+.5); |
| 96 |
> |
viewray(thisray.rorg, thisray.rdir, &ourview, |
| 97 |
> |
(x+.5)/hresolu, (y+.5)/vresolu); |
| 98 |
|
if (!direc || ourview.type == VT_PAR) { |
| 99 |
|
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
| 100 |
|
if (!localhit(&thisray, &thescene)) { |
| 134 |
|
register PNODE *p; |
| 135 |
|
int xmin, ymin, xmax, ymax; |
| 136 |
|
{ |
| 137 |
+ |
extern long nrays; |
| 138 |
+ |
static long lastflush = 0; |
| 139 |
|
static RAY thisray; |
| 140 |
|
double h, v; |
| 141 |
|
register int i; |
| 147 |
|
return; |
| 148 |
|
} |
| 149 |
|
/* jitter ray direction */ |
| 150 |
< |
p->x = h = xmin + (xmax-xmin)*frandom(); |
| 151 |
< |
p->y = v = ymin + (ymax-ymin)*frandom(); |
| 150 |
> |
h = xmin + (xmax-xmin)*frandom(); |
| 151 |
> |
v = ymin + (ymax-ymin)*frandom(); |
| 152 |
|
|
| 153 |
< |
rayview(thisray.rorg, thisray.rdir, &ourview, h, v); |
| 147 |
< |
|
| 153 |
> |
viewray(thisray.rorg, thisray.rdir, &ourview, h/hresolu, v/vresolu); |
| 154 |
|
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
| 149 |
– |
|
| 155 |
|
rayvalue(&thisray); |
| 156 |
|
|
| 157 |
+ |
p->x = h; |
| 158 |
+ |
p->y = v; |
| 159 |
|
copycolor(p->v, thisray.rcol); |
| 153 |
– |
|
| 160 |
|
scalecolor(p->v, exposure); |
| 161 |
|
|
| 162 |
|
(*dev->paintr)(greyscale?greyof(p->v):p->v, xmin, ymin, xmax, ymax); |
| 163 |
+ |
|
| 164 |
+ |
if (dev->flush != NULL && nrays - lastflush >= WFLUSH) { |
| 165 |
+ |
lastflush = nrays; |
| 166 |
+ |
(*dev->flush)(); |
| 167 |
+ |
} |
| 168 |
|
} |
| 169 |
|
|
| 170 |
|
|
| 172 |
|
{ |
| 173 |
|
/* free old image */ |
| 174 |
|
freepkids(&ptrunk); |
| 175 |
< |
/* set up frame */ |
| 176 |
< |
if (ourview.hresolu > dev->xsiz || ourview.vresolu > dev->ysiz) |
| 177 |
< |
newview(&ourview); /* beware recursive loop! */ |
| 175 |
> |
/* compute resolution */ |
| 176 |
> |
hresolu = dev->xsiz; |
| 177 |
> |
vresolu = dev->ysiz; |
| 178 |
> |
normaspect(viewaspect(&ourview), &dev->pixaspect, &hresolu, &vresolu); |
| 179 |
|
pframe.l = pframe.d = 0; |
| 180 |
< |
pframe.r = ourview.hresolu; pframe.u = ourview.vresolu; |
| 180 |
> |
pframe.r = hresolu; pframe.u = vresolu; |
| 181 |
|
pdepth = 0; |
| 182 |
|
/* clear device */ |
| 183 |
< |
(*dev->clear)(ourview.hresolu, ourview.vresolu); |
| 183 |
> |
(*dev->clear)(hresolu, vresolu); |
| 184 |
|
/* get first value */ |
| 185 |
< |
paint(&ptrunk, 0, 0, ourview.hresolu, ourview.vresolu); |
| 185 |
> |
paint(&ptrunk, 0, 0, hresolu, vresolu); |
| 186 |
|
} |
| 187 |
|
|
| 188 |
|
|
| 189 |
|
redraw() /* redraw the image */ |
| 190 |
|
{ |
| 191 |
< |
(*dev->clear)(ourview.hresolu, ourview.vresolu); |
| 191 |
> |
(*dev->clear)(hresolu, vresolu); |
| 192 |
|
(*dev->comout)("redrawing...\n"); |
| 193 |
< |
repaint(0, 0, ourview.hresolu, ourview.vresolu); |
| 193 |
> |
repaint(0, 0, hresolu, vresolu); |
| 194 |
|
(*dev->comout)("\n"); |
| 195 |
|
} |
| 196 |
|
|
| 203 |
|
reg.l = xmin; reg.r = xmax; |
| 204 |
|
reg.d = ymin; reg.u = ymax; |
| 205 |
|
|
| 206 |
< |
paintrect(&ptrunk, 0, 0, ourview.hresolu, ourview.vresolu, ®); |
| 206 |
> |
paintrect(&ptrunk, 0, 0, hresolu, vresolu, ®); |
| 207 |
|
} |
| 208 |
|
|
| 209 |
|
|
| 214 |
|
{ |
| 215 |
|
int mx, my; |
| 216 |
|
|
| 205 |
– |
if (dev->inpready) |
| 206 |
– |
return; /* break for input */ |
| 207 |
– |
|
| 217 |
|
if (xmax - xmin <= 0 || ymax - ymin <= 0) |
| 218 |
|
return; |
| 219 |
|
|
| 351 |
|
{ |
| 352 |
|
char *err; |
| 353 |
|
|
| 345 |
– |
if (vp->hresolu > dev->xsiz || vp->vresolu > dev->ysiz) /* shrink */ |
| 346 |
– |
if (vp->vresolu * dev->xsiz < vp->hresolu * dev->ysiz) { |
| 347 |
– |
vp->vresolu = dev->xsiz * vp->vresolu / vp->hresolu; |
| 348 |
– |
vp->hresolu = dev->xsiz; |
| 349 |
– |
} else { |
| 350 |
– |
vp->hresolu = dev->ysiz * vp->hresolu / vp->vresolu; |
| 351 |
– |
vp->vresolu = dev->ysiz; |
| 352 |
– |
} |
| 354 |
|
if ((err = setview(vp)) != NULL) { |
| 355 |
|
sprintf(errmsg, "view not set - %s", err); |
| 356 |
|
error(COMMAND, errmsg); |
| 357 |
< |
} else if (bcmp(vp, &ourview, sizeof(VIEW))) { |
| 358 |
< |
bcopy(&ourview, &oldview, sizeof(VIEW)); |
| 359 |
< |
bcopy(vp, &ourview, sizeof(VIEW)); |
| 360 |
< |
newimage(); /* newimage() calls with vp=&ourview! */ |
| 357 |
> |
} else if (bcmp((char *)vp, (char *)&ourview, sizeof(VIEW))) { |
| 358 |
> |
copystruct(&oldview, &ourview); |
| 359 |
> |
copystruct(&ourview, vp); |
| 360 |
> |
newimage(); |
| 361 |
|
} |
| 362 |
|
} |
| 363 |
|
|
| 373 |
|
register int i; |
| 374 |
|
|
| 375 |
|
VCOPY(nv.vup, ourview.vup); |
| 376 |
< |
nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu; |
| 376 |
> |
nv.hoff = ourview.hoff; nv.voff = ourview.voff; |
| 377 |
|
spinvector(nv.vdir, ourview.vdir, ourview.vup, angle*(PI/180.)); |
| 378 |
|
if (elev != 0.0) { |
| 379 |
|
fcross(v1, ourview.vup, nv.vdir); |