12 |
|
|
13 |
|
#include "ray.h" |
14 |
|
|
15 |
+ |
#include "octree.h" |
16 |
+ |
|
17 |
|
#include "rpaint.h" |
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; |
29 |
+ |
{ |
30 |
+ |
int x0, y0, x1, y1; |
31 |
+ |
|
32 |
+ |
if (*s && !strncmp(s, "all", strlen(s))) { |
33 |
+ |
r->l = r->d = 0; |
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) { |
39 |
+ |
if (dev->getcur == NULL) |
40 |
+ |
return(-1); |
41 |
+ |
(*dev->comout)("Pick first corner\n"); |
42 |
+ |
if ((*dev->getcur)(&x0, &y0) == ABORT) |
43 |
+ |
return(-1); |
44 |
+ |
(*dev->comout)("Pick second corner\n"); |
45 |
+ |
if ((*dev->getcur)(&x1, &y1) == ABORT) |
46 |
+ |
return(-1); |
47 |
+ |
} |
48 |
+ |
if (x0 < x1) { |
49 |
+ |
r->l = x0; |
50 |
+ |
r->r = x1; |
51 |
+ |
} else { |
52 |
+ |
r->l = x1; |
53 |
+ |
r->r = x0; |
54 |
+ |
} |
55 |
+ |
if (y0 < y1) { |
56 |
+ |
r->d = y0; |
57 |
+ |
r->u = y1; |
58 |
+ |
} else { |
59 |
+ |
r->d = y1; |
60 |
+ |
r->u = y0; |
61 |
+ |
} |
62 |
+ |
if (r->l < 0) r->l = 0; |
63 |
+ |
if (r->d < 0) r->d = 0; |
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); |
69 |
+ |
} |
70 |
+ |
|
71 |
+ |
|
72 |
+ |
getinterest(s, direc, vec, mp) /* get area of interest */ |
73 |
+ |
char *s; |
74 |
+ |
int direc; |
75 |
+ |
FVECT vec; |
76 |
+ |
double *mp; |
77 |
+ |
{ |
78 |
+ |
int x, y; |
79 |
+ |
RAY thisray; |
80 |
+ |
register int i; |
81 |
+ |
|
82 |
+ |
if (sscanf(s, "%lf", mp) != 1) |
83 |
+ |
*mp = 1.0; |
84 |
+ |
else if (*mp < -FTINY) /* negative zoom is reduction */ |
85 |
+ |
*mp = -1.0 / *mp; |
86 |
+ |
else if (*mp <= FTINY) { /* too small */ |
87 |
+ |
error(COMMAND, "illegal magnification"); |
88 |
+ |
return(-1); |
89 |
+ |
} |
90 |
+ |
if (sscanf(s, "%*lf %lf %lf %lf", &vec[0], &vec[1], &vec[2]) != 3) { |
91 |
+ |
if (dev->getcur == NULL) |
92 |
+ |
return(-1); |
93 |
+ |
(*dev->comout)("Pick view center\n"); |
94 |
+ |
if ((*dev->getcur)(&x, &y) == ABORT) |
95 |
+ |
return(-1); |
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)) { |
101 |
+ |
error(COMMAND, "not a local object"); |
102 |
+ |
return(-1); |
103 |
+ |
} |
104 |
+ |
} |
105 |
+ |
if (direc) |
106 |
+ |
if (ourview.type == VT_PAR) |
107 |
+ |
for (i = 0; i < 3; i++) |
108 |
+ |
vec[i] = thisray.rop[i] - ourview.vp[i]; |
109 |
+ |
else |
110 |
+ |
VCOPY(vec, thisray.rdir); |
111 |
+ |
else |
112 |
+ |
VCOPY(vec, thisray.rop); |
113 |
+ |
} else if (direc) |
114 |
+ |
for (i = 0; i < 3; i++) |
115 |
+ |
vec[i] -= ourview.vp[i]; |
116 |
+ |
return(0); |
117 |
+ |
} |
118 |
+ |
|
119 |
+ |
|
120 |
|
float * /* keep consistent with COLOR typedef */ |
121 |
|
greyof(col) /* convert color to greyscale */ |
122 |
|
register COLOR col; |
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; |
148 |
|
} |
149 |
|
/* jitter ray direction */ |
150 |
|
p->x = h = xmin + (xmax-xmin)*frandom(); |
151 |
+ |
h /= hresolu; |
152 |
|
p->y = v = ymin + (ymax-ymin)*frandom(); |
153 |
+ |
v /= vresolu; |
154 |
|
|
155 |
< |
rayview(thisray.rorg, thisray.rdir, &ourview, h, v); |
155 |
> |
viewray(thisray.rorg, thisray.rdir, &ourview, h, v); |
156 |
|
|
157 |
|
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
158 |
|
|
163 |
|
scalecolor(p->v, exposure); |
164 |
|
|
165 |
|
(*dev->paintr)(greyscale?greyof(p->v):p->v, xmin, ymin, xmax, ymax); |
166 |
+ |
|
167 |
+ |
if (dev->flush != NULL && nrays - lastflush >= WFLUSH) { |
168 |
+ |
lastflush = nrays; |
169 |
+ |
(*dev->flush)(); |
170 |
+ |
} |
171 |
|
} |
172 |
|
|
173 |
|
|
175 |
|
{ |
176 |
|
/* free old image */ |
177 |
|
freepkids(&ptrunk); |
178 |
< |
/* set up frame */ |
179 |
< |
if (ourview.hresolu > dev->xsiz || ourview.vresolu > dev->ysiz) |
180 |
< |
error(USER, "resolution mismatch"); |
178 |
> |
/* compute resolution */ |
179 |
> |
hresolu = dev->xsiz; |
180 |
> |
vresolu = dev->ysiz; |
181 |
> |
normaspect(viewaspect(&ourview), &dev->pixaspect, &hresolu, &vresolu); |
182 |
|
pframe.l = pframe.d = 0; |
183 |
< |
pframe.r = ourview.hresolu; pframe.u = ourview.vresolu; |
183 |
> |
pframe.r = hresolu; pframe.u = vresolu; |
184 |
|
pdepth = 0; |
185 |
|
/* clear device */ |
186 |
< |
(*dev->clear)(ourview.hresolu, ourview.vresolu); |
186 |
> |
(*dev->clear)(hresolu, vresolu); |
187 |
|
/* get first value */ |
188 |
< |
paint(&ptrunk, 0, 0, ourview.hresolu, ourview.vresolu); |
188 |
> |
paint(&ptrunk, 0, 0, hresolu, vresolu); |
189 |
|
} |
190 |
|
|
191 |
|
|
192 |
|
redraw() /* redraw the image */ |
193 |
|
{ |
194 |
< |
(*dev->clear)(ourview.hresolu, ourview.vresolu); |
194 |
> |
(*dev->clear)(hresolu, vresolu); |
195 |
|
(*dev->comout)("redrawing...\n"); |
196 |
< |
repaint(0, 0, ourview.hresolu, ourview.vresolu); |
196 |
> |
repaint(0, 0, hresolu, vresolu); |
197 |
|
(*dev->comout)("\n"); |
198 |
|
} |
199 |
|
|
206 |
|
reg.l = xmin; reg.r = xmax; |
207 |
|
reg.d = ymin; reg.u = ymax; |
208 |
|
|
209 |
< |
paintrect(&ptrunk, 0, 0, ourview.hresolu, ourview.vresolu, ®); |
209 |
> |
paintrect(&ptrunk, 0, 0, hresolu, vresolu, ®); |
210 |
|
} |
211 |
|
|
212 |
|
|
217 |
|
{ |
218 |
|
int mx, my; |
219 |
|
|
110 |
– |
if (dev->inpready) |
111 |
– |
return; /* break for input */ |
112 |
– |
|
220 |
|
if (xmax - xmin <= 0 || ymax - ymin <= 0) |
221 |
|
return; |
222 |
|
|
354 |
|
{ |
355 |
|
char *err; |
356 |
|
|
357 |
< |
if (vp->hresolu > dev->xsiz || vp->vresolu > dev->ysiz) { |
251 |
< |
error(COMMAND, "view not set - resolution mismatch"); |
252 |
< |
} else if ((err = setview(vp)) != NULL) { |
357 |
> |
if ((err = setview(vp)) != NULL) { |
358 |
|
sprintf(errmsg, "view not set - %s", err); |
359 |
|
error(COMMAND, errmsg); |
360 |
< |
} else if (bcmp(vp, &ourview, sizeof(VIEW))) { |
361 |
< |
bcopy(&ourview, &oldview, sizeof(VIEW)); |
362 |
< |
bcopy(vp, &ourview, sizeof(VIEW)); |
360 |
> |
} else if (bcmp((char *)vp, (char *)&ourview, sizeof(VIEW))) { |
361 |
> |
copystruct(&oldview, &ourview); |
362 |
> |
copystruct(&ourview, vp); |
363 |
|
newimage(); |
364 |
|
} |
365 |
|
} |
376 |
|
register int i; |
377 |
|
|
378 |
|
VCOPY(nv.vup, ourview.vup); |
379 |
< |
nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu; |
379 |
> |
nv.hoff = ourview.hoff; nv.voff = ourview.voff; |
380 |
|
spinvector(nv.vdir, ourview.vdir, ourview.vup, angle*(PI/180.)); |
381 |
|
if (elev != 0.0) { |
382 |
|
fcross(v1, ourview.vup, nv.vdir); |