| 12 |
|
|
| 13 |
|
#include "ray.h" |
| 14 |
|
|
| 15 |
+ |
#include "octree.h" |
| 16 |
+ |
|
| 17 |
|
#include "rpaint.h" |
| 18 |
|
|
| 19 |
|
#include "random.h" |
| 20 |
|
|
| 21 |
|
|
| 22 |
+ |
getrect(s, r) /* get a box */ |
| 23 |
+ |
char *s; |
| 24 |
+ |
register RECT *r; |
| 25 |
+ |
{ |
| 26 |
+ |
int x0, y0, x1, y1; |
| 27 |
+ |
|
| 28 |
+ |
if (*s && !strncmp(s, "all", strlen(s))) { |
| 29 |
+ |
r->l = r->d = 0; |
| 30 |
+ |
r->r = hresolu; |
| 31 |
+ |
r->u = vresolu; |
| 32 |
+ |
return(0); |
| 33 |
+ |
} |
| 34 |
+ |
if (sscanf(s, "%d %d %d %d", &x0, &y0, &x1, &y1) != 4) { |
| 35 |
+ |
if (dev->getcur == NULL) |
| 36 |
+ |
return(-1); |
| 37 |
+ |
(*dev->comout)("Pick first corner\n"); |
| 38 |
+ |
if ((*dev->getcur)(&x0, &y0) == ABORT) |
| 39 |
+ |
return(-1); |
| 40 |
+ |
(*dev->comout)("Pick second corner\n"); |
| 41 |
+ |
if ((*dev->getcur)(&x1, &y1) == ABORT) |
| 42 |
+ |
return(-1); |
| 43 |
+ |
} |
| 44 |
+ |
if (x0 < x1) { |
| 45 |
+ |
r->l = x0; |
| 46 |
+ |
r->r = x1; |
| 47 |
+ |
} else { |
| 48 |
+ |
r->l = x1; |
| 49 |
+ |
r->r = x0; |
| 50 |
+ |
} |
| 51 |
+ |
if (y0 < y1) { |
| 52 |
+ |
r->d = y0; |
| 53 |
+ |
r->u = y1; |
| 54 |
+ |
} else { |
| 55 |
+ |
r->d = y1; |
| 56 |
+ |
r->u = y0; |
| 57 |
+ |
} |
| 58 |
+ |
if (r->l < 0) r->l = 0; |
| 59 |
+ |
if (r->d < 0) r->d = 0; |
| 60 |
+ |
if (r->r > hresolu) r->r = hresolu; |
| 61 |
+ |
if (r->u > vresolu) r->u = vresolu; |
| 62 |
+ |
if (r->l > r->r) r->l = r->r; |
| 63 |
+ |
if (r->d > r->u) r->d = r->u; |
| 64 |
+ |
return(0); |
| 65 |
+ |
} |
| 66 |
+ |
|
| 67 |
+ |
|
| 68 |
+ |
getinterest(s, direc, vec, mp) /* get area of interest */ |
| 69 |
+ |
char *s; |
| 70 |
+ |
int direc; |
| 71 |
+ |
FVECT vec; |
| 72 |
+ |
double *mp; |
| 73 |
+ |
{ |
| 74 |
+ |
int x, y; |
| 75 |
+ |
RAY thisray; |
| 76 |
+ |
register int i; |
| 77 |
+ |
|
| 78 |
+ |
if (sscanf(s, "%lf", mp) != 1) |
| 79 |
+ |
*mp = 1.0; |
| 80 |
+ |
else if (*mp < -FTINY) /* negative zoom is reduction */ |
| 81 |
+ |
*mp = -1.0 / *mp; |
| 82 |
+ |
else if (*mp <= FTINY) { /* too small */ |
| 83 |
+ |
error(COMMAND, "illegal magnification"); |
| 84 |
+ |
return(-1); |
| 85 |
+ |
} |
| 86 |
+ |
if (sscanf(s, "%*lf %lf %lf %lf", &vec[0], &vec[1], &vec[2]) != 3) { |
| 87 |
+ |
if (dev->getcur == NULL) |
| 88 |
+ |
return(-1); |
| 89 |
+ |
(*dev->comout)("Pick view center\n"); |
| 90 |
+ |
if ((*dev->getcur)(&x, &y) == ABORT) |
| 91 |
+ |
return(-1); |
| 92 |
+ |
viewray(thisray.rorg, thisray.rdir, &ourview, |
| 93 |
+ |
(x+.5)/hresolu, (y+.5)/vresolu); |
| 94 |
+ |
if (!direc || ourview.type == VT_PAR) { |
| 95 |
+ |
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
| 96 |
+ |
if (!localhit(&thisray, &thescene)) { |
| 97 |
+ |
error(COMMAND, "not a local object"); |
| 98 |
+ |
return(-1); |
| 99 |
+ |
} |
| 100 |
+ |
} |
| 101 |
+ |
if (direc) |
| 102 |
+ |
if (ourview.type == VT_PAR) |
| 103 |
+ |
for (i = 0; i < 3; i++) |
| 104 |
+ |
vec[i] = thisray.rop[i] - ourview.vp[i]; |
| 105 |
+ |
else |
| 106 |
+ |
VCOPY(vec, thisray.rdir); |
| 107 |
+ |
else |
| 108 |
+ |
VCOPY(vec, thisray.rop); |
| 109 |
+ |
} else if (direc) |
| 110 |
+ |
for (i = 0; i < 3; i++) |
| 111 |
+ |
vec[i] -= ourview.vp[i]; |
| 112 |
+ |
return(0); |
| 113 |
+ |
} |
| 114 |
+ |
|
| 115 |
+ |
|
| 116 |
|
float * /* keep consistent with COLOR typedef */ |
| 117 |
|
greyof(col) /* convert color to greyscale */ |
| 118 |
|
register COLOR col; |
| 142 |
|
} |
| 143 |
|
/* jitter ray direction */ |
| 144 |
|
p->x = h = xmin + (xmax-xmin)*frandom(); |
| 145 |
+ |
h /= hresolu; |
| 146 |
|
p->y = v = ymin + (ymax-ymin)*frandom(); |
| 147 |
+ |
v /= vresolu; |
| 148 |
|
|
| 149 |
< |
rayview(thisray.rorg, thisray.rdir, &ourview, h, v); |
| 149 |
> |
viewray(thisray.rorg, thisray.rdir, &ourview, h, v); |
| 150 |
|
|
| 151 |
|
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
| 152 |
|
|
| 164 |
|
{ |
| 165 |
|
/* free old image */ |
| 166 |
|
freepkids(&ptrunk); |
| 167 |
< |
/* set up frame */ |
| 168 |
< |
if (ourview.hresolu > dev->xsiz || ourview.vresolu > dev->ysiz) |
| 169 |
< |
error(USER, "resolution mismatch"); |
| 167 |
> |
/* compute resolution */ |
| 168 |
> |
if (viewaspect(&ourview)*dev->xsiz > dev->pixaspect*dev->ysiz) { |
| 169 |
> |
vresolu = dev->ysiz; |
| 170 |
> |
hresolu = vresolu/viewaspect(&ourview)*dev->pixaspect; |
| 171 |
> |
} else { |
| 172 |
> |
hresolu = dev->xsiz; |
| 173 |
> |
vresolu = hresolu*viewaspect(&ourview)/dev->pixaspect; |
| 174 |
> |
} |
| 175 |
|
pframe.l = pframe.d = 0; |
| 176 |
< |
pframe.r = ourview.hresolu; pframe.u = ourview.vresolu; |
| 176 |
> |
pframe.r = hresolu; pframe.u = vresolu; |
| 177 |
|
pdepth = 0; |
| 178 |
|
/* clear device */ |
| 179 |
< |
(*dev->clear)(ourview.hresolu, ourview.vresolu); |
| 179 |
> |
(*dev->clear)(hresolu, vresolu); |
| 180 |
|
/* get first value */ |
| 181 |
< |
paint(&ptrunk, 0, 0, ourview.hresolu, ourview.vresolu); |
| 181 |
> |
paint(&ptrunk, 0, 0, hresolu, vresolu); |
| 182 |
|
} |
| 183 |
|
|
| 184 |
|
|
| 185 |
|
redraw() /* redraw the image */ |
| 186 |
|
{ |
| 187 |
< |
(*dev->clear)(ourview.hresolu, ourview.vresolu); |
| 187 |
> |
(*dev->clear)(hresolu, vresolu); |
| 188 |
|
(*dev->comout)("redrawing...\n"); |
| 189 |
< |
repaint(0, 0, ourview.hresolu, ourview.vresolu); |
| 189 |
> |
repaint(0, 0, hresolu, vresolu); |
| 190 |
|
(*dev->comout)("\n"); |
| 191 |
|
} |
| 192 |
|
|
| 199 |
|
reg.l = xmin; reg.r = xmax; |
| 200 |
|
reg.d = ymin; reg.u = ymax; |
| 201 |
|
|
| 202 |
< |
paintrect(&ptrunk, 0, 0, ourview.hresolu, ourview.vresolu, ®); |
| 202 |
> |
paintrect(&ptrunk, 0, 0, hresolu, vresolu, ®); |
| 203 |
|
} |
| 204 |
|
|
| 205 |
|
|
| 210 |
|
{ |
| 211 |
|
int mx, my; |
| 212 |
|
|
| 110 |
– |
if (dev->inpready) |
| 111 |
– |
return; /* break for input */ |
| 112 |
– |
|
| 213 |
|
if (xmax - xmin <= 0 || ymax - ymin <= 0) |
| 214 |
|
return; |
| 215 |
|
|
| 347 |
|
{ |
| 348 |
|
char *err; |
| 349 |
|
|
| 350 |
< |
if (vp->hresolu > dev->xsiz || vp->vresolu > dev->ysiz) { |
| 251 |
< |
error(COMMAND, "view not set - resolution mismatch"); |
| 252 |
< |
} else if ((err = setview(vp)) != NULL) { |
| 350 |
> |
if ((err = setview(vp)) != NULL) { |
| 351 |
|
sprintf(errmsg, "view not set - %s", err); |
| 352 |
|
error(COMMAND, errmsg); |
| 353 |
|
} else if (bcmp(vp, &ourview, sizeof(VIEW))) { |
| 354 |
< |
bcopy(&ourview, &oldview, sizeof(VIEW)); |
| 355 |
< |
bcopy(vp, &ourview, sizeof(VIEW)); |
| 356 |
< |
newimage(); |
| 354 |
> |
copyview(&oldview, &ourview); |
| 355 |
> |
copyview(&ourview, vp); |
| 356 |
> |
newimage(); /* newimage() calls with vp=&ourview! */ |
| 357 |
|
} |
| 358 |
|
} |
| 359 |
|
|
| 360 |
|
|
| 361 |
< |
moveview(angle, mag, vc) /* move viewpoint */ |
| 362 |
< |
double angle, mag; |
| 361 |
> |
moveview(angle, elev, mag, vc) /* move viewpoint */ |
| 362 |
> |
double angle, elev, mag; |
| 363 |
|
FVECT vc; |
| 364 |
|
{ |
| 365 |
|
extern double sqrt(), dist2(); |
| 366 |
|
double d; |
| 367 |
< |
FVECT v; |
| 367 |
> |
FVECT v1; |
| 368 |
|
VIEW nv; |
| 369 |
|
register int i; |
| 370 |
|
|
| 371 |
|
VCOPY(nv.vup, ourview.vup); |
| 372 |
< |
nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu; |
| 372 |
> |
nv.hoff = ourview.hoff; nv.voff = ourview.voff; |
| 373 |
|
spinvector(nv.vdir, ourview.vdir, ourview.vup, angle*(PI/180.)); |
| 374 |
+ |
if (elev != 0.0) { |
| 375 |
+ |
fcross(v1, ourview.vup, nv.vdir); |
| 376 |
+ |
normalize(v1); |
| 377 |
+ |
spinvector(nv.vdir, nv.vdir, v1, elev*(PI/180.)); |
| 378 |
+ |
} |
| 379 |
|
if ((nv.type = ourview.type) == VT_PAR) { |
| 380 |
|
nv.horiz = ourview.horiz / mag; |
| 381 |
|
nv.vert = ourview.vert / mag; |
| 382 |
+ |
d = 0.0; /* don't move closer */ |
| 383 |
|
for (i = 0; i < 3; i++) |
| 384 |
< |
v[i] = vc[i] - ourview.vp[i]; |
| 281 |
< |
d = DOT(v, ourview.vdir); /* don't move closer */ |
| 384 |
> |
d += (vc[i] - ourview.vp[i])*ourview.vdir[i]; |
| 385 |
|
} else { |
| 386 |
|
nv.horiz = ourview.horiz; |
| 387 |
|
nv.vert = ourview.vert; |