| 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 = ourview.hresolu; |
| 31 |
+ |
r->u = ourview.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 > ourview.hresolu) r->r = ourview.hresolu; |
| 61 |
+ |
if (r->u > ourview.vresolu) r->u = ourview.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 |
+ |
rayview(thisray.rorg, thisray.rdir, &ourview, x+.5, y+.5); |
| 93 |
+ |
if (!direc || ourview.type == VT_PAR) { |
| 94 |
+ |
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
| 95 |
+ |
if (!localhit(&thisray, &thescene)) { |
| 96 |
+ |
error(COMMAND, "not a local object"); |
| 97 |
+ |
return(-1); |
| 98 |
+ |
} |
| 99 |
+ |
} |
| 100 |
+ |
if (direc) |
| 101 |
+ |
if (ourview.type == VT_PAR) |
| 102 |
+ |
for (i = 0; i < 3; i++) |
| 103 |
+ |
vec[i] = thisray.rop[i] - ourview.vp[i]; |
| 104 |
+ |
else |
| 105 |
+ |
VCOPY(vec, thisray.rdir); |
| 106 |
+ |
else |
| 107 |
+ |
VCOPY(vec, thisray.rop); |
| 108 |
+ |
} else if (direc) |
| 109 |
+ |
for (i = 0; i < 3; i++) |
| 110 |
+ |
vec[i] -= ourview.vp[i]; |
| 111 |
+ |
return(0); |
| 112 |
+ |
} |
| 113 |
+ |
|
| 114 |
+ |
|
| 115 |
|
float * /* keep consistent with COLOR typedef */ |
| 116 |
|
greyof(col) /* convert color to greyscale */ |
| 117 |
|
register COLOR col; |
| 163 |
|
freepkids(&ptrunk); |
| 164 |
|
/* set up frame */ |
| 165 |
|
if (ourview.hresolu > dev->xsiz || ourview.vresolu > dev->ysiz) |
| 166 |
< |
error(USER, "resolution mismatch"); |
| 166 |
> |
newview(&ourview); /* beware recursive loop! */ |
| 167 |
|
pframe.l = pframe.d = 0; |
| 168 |
|
pframe.r = ourview.hresolu; pframe.u = ourview.vresolu; |
| 169 |
|
pdepth = 0; |
| 342 |
|
{ |
| 343 |
|
char *err; |
| 344 |
|
|
| 345 |
< |
if (vp->hresolu > dev->xsiz || vp->vresolu > dev->ysiz) { |
| 346 |
< |
error(COMMAND, "view not set - resolution mismatch"); |
| 347 |
< |
} else if ((err = setview(vp)) != NULL) { |
| 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 |
> |
} |
| 353 |
> |
if ((err = setview(vp)) != NULL) { |
| 354 |
|
sprintf(errmsg, "view not set - %s", err); |
| 355 |
|
error(COMMAND, errmsg); |
| 356 |
|
} else if (bcmp(vp, &ourview, sizeof(VIEW))) { |
| 357 |
|
bcopy(&ourview, &oldview, sizeof(VIEW)); |
| 358 |
|
bcopy(vp, &ourview, sizeof(VIEW)); |
| 359 |
< |
newimage(); |
| 359 |
> |
newimage(); /* newimage() calls with vp=&ourview! */ |
| 360 |
|
} |
| 361 |
|
} |
| 362 |
|
|