1 |
– |
/* Copyright (c) 1987 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* rv3.c - miscellaneous routines for rview. |
6 |
|
* |
7 |
< |
* 5/11/87 |
7 |
> |
* External symbols declared in rpaint.h |
8 |
|
*/ |
9 |
|
|
10 |
< |
#include "ray.h" |
10 |
> |
#include "copyright.h" |
11 |
|
|
12 |
< |
#include "octree.h" |
12 |
> |
#include <string.h> |
13 |
|
|
14 |
+ |
#include "ray.h" |
15 |
|
#include "rpaint.h" |
18 |
– |
|
16 |
|
#include "random.h" |
17 |
|
|
18 |
|
#ifndef WFLUSH |
19 |
< |
#define WFLUSH 30 /* flush after this many rays */ |
19 |
> |
#define WFLUSH 64 /* flush after this many primary rays */ |
20 |
|
#endif |
21 |
+ |
#ifndef WFLUSH1 |
22 |
+ |
#define WFLUSH1 512 /* or this many total rays */ |
23 |
+ |
#endif |
24 |
|
|
25 |
+ |
|
26 |
|
#ifdef SMLFLT |
27 |
|
#define sscanvec(s,v) (sscanf(s,"%f %f %f",v,v+1,v+2)==3) |
28 |
|
#else |
29 |
|
#define sscanvec(s,v) (sscanf(s,"%lf %lf %lf",v,v+1,v+2)==3) |
30 |
|
#endif |
31 |
|
|
32 |
+ |
extern int ray_pnprocs; |
33 |
|
|
34 |
< |
getrect(s, r) /* get a box */ |
35 |
< |
char *s; |
36 |
< |
register RECT *r; |
34 |
> |
static RNUMBER niflush; /* flushes since newimage() */ |
35 |
> |
|
36 |
> |
int |
37 |
> |
getrect( /* get a box */ |
38 |
> |
char *s, |
39 |
> |
RECT *r |
40 |
> |
) |
41 |
|
{ |
42 |
|
int x0, y0, x1, y1; |
43 |
|
|
81 |
|
} |
82 |
|
|
83 |
|
|
84 |
< |
getinterest(s, direc, vec, mp) /* get area of interest */ |
85 |
< |
char *s; |
86 |
< |
int direc; |
87 |
< |
FVECT vec; |
88 |
< |
double *mp; |
84 |
> |
int |
85 |
> |
getinterest( /* get area of interest */ |
86 |
> |
char *s, |
87 |
> |
int direc, |
88 |
> |
FVECT vec, |
89 |
> |
double *mp |
90 |
> |
) |
91 |
|
{ |
92 |
|
int x, y; |
93 |
|
RAY thisray; |
94 |
< |
register int i; |
94 |
> |
int i; |
95 |
|
|
96 |
|
if (sscanf(s, "%lf", mp) != 1) |
97 |
|
*mp = 1.0; |
107 |
|
(*dev->comout)("Pick view center\n"); |
108 |
|
if ((*dev->getcur)(&x, &y) == ABORT) |
109 |
|
return(-1); |
110 |
< |
if (viewray(thisray.rorg, thisray.rdir, &ourview, |
111 |
< |
(x+.5)/hresolu, (y+.5)/vresolu) < 0) { |
110 |
> |
if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir, |
111 |
> |
&ourview, (x+.5)/hresolu, (y+.5)/vresolu)) < -FTINY) { |
112 |
|
error(COMMAND, "not on image"); |
113 |
|
return(-1); |
114 |
|
} |
115 |
|
if (!direc || ourview.type == VT_PAR) { |
116 |
< |
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
116 |
> |
rayorigin(&thisray, PRIMARY, NULL, NULL); |
117 |
|
if (!localhit(&thisray, &thescene)) { |
118 |
|
error(COMMAND, "not a local object"); |
119 |
|
return(-1); |
127 |
|
VCOPY(vec, thisray.rdir); |
128 |
|
else |
129 |
|
VCOPY(vec, thisray.rop); |
130 |
< |
} else if (direc) |
131 |
< |
for (i = 0; i < 3; i++) |
132 |
< |
vec[i] -= ourview.vp[i]; |
130 |
> |
} else if (direc) { |
131 |
> |
for (i = 0; i < 3; i++) |
132 |
> |
vec[i] -= ourview.vp[i]; |
133 |
> |
if (normalize(vec) == 0.0) { |
134 |
> |
error(COMMAND, "point at view origin"); |
135 |
> |
return(-1); |
136 |
> |
} |
137 |
> |
} |
138 |
|
return(0); |
139 |
|
} |
140 |
|
|
141 |
|
|
142 |
< |
float * /* keep consistent with COLOR typedef */ |
143 |
< |
greyof(col) /* convert color to greyscale */ |
144 |
< |
register COLOR col; |
142 |
> |
COLORV * |
143 |
> |
greyof( /* convert color to greyscale */ |
144 |
> |
COLOR col |
145 |
> |
) |
146 |
|
{ |
147 |
|
static COLOR gcol; |
148 |
|
double b; |
152 |
|
return(gcol); |
153 |
|
} |
154 |
|
|
155 |
+ |
static void |
156 |
+ |
recolor( /* recolor the given node */ |
157 |
+ |
PNODE *p |
158 |
+ |
) |
159 |
+ |
{ |
160 |
+ |
while (p->kid != NULL) { /* need to propogate down */ |
161 |
+ |
int mx = (p->xmin + p->xmax) >> 1; |
162 |
+ |
int my = (p->ymin + p->ymax) >> 1; |
163 |
+ |
int ki; |
164 |
+ |
if (p->x >= mx) |
165 |
+ |
ki = (p->y >= my) ? UR : DR; |
166 |
+ |
else |
167 |
+ |
ki = (p->y >= my) ? UL : DL; |
168 |
+ |
pcopy(p, p->kid+ki); |
169 |
+ |
p = p->kid + ki; |
170 |
+ |
} |
171 |
|
|
172 |
< |
paint(p, xmin, ymin, xmax, ymax) /* compute and paint a rectangle */ |
173 |
< |
register PNODE *p; |
174 |
< |
int xmin, ymin, xmax, ymax; |
172 |
> |
(*dev->paintr)(greyscale?greyof(p->v):p->v, |
173 |
> |
p->xmin, p->ymin, p->xmax, p->ymax); |
174 |
> |
} |
175 |
> |
|
176 |
> |
int |
177 |
> |
paint( /* compute and paint a rectangle */ |
178 |
> |
PNODE *p |
179 |
> |
) |
180 |
|
{ |
146 |
– |
extern long nrays; |
147 |
– |
static long lastflush = 0; |
181 |
|
static RAY thisray; |
182 |
|
double h, v; |
183 |
|
|
184 |
< |
if (xmax - xmin <= 0 || ymax - ymin <= 0) { /* empty */ |
185 |
< |
p->x = xmin; |
186 |
< |
p->y = ymin; |
184 |
> |
if ((p->xmax <= p->xmin) | (p->ymax <= p->ymin)) { /* empty */ |
185 |
> |
p->x = p->xmin; |
186 |
> |
p->y = p->ymin; |
187 |
|
setcolor(p->v, 0.0, 0.0, 0.0); |
188 |
< |
return; |
188 |
> |
return(0); |
189 |
|
} |
190 |
|
/* jitter ray direction */ |
191 |
< |
h = xmin + (xmax-xmin)*frandom(); |
192 |
< |
v = ymin + (ymax-ymin)*frandom(); |
191 |
> |
p->x = h = p->xmin + (p->xmax-p->xmin)*frandom(); |
192 |
> |
p->y = v = p->ymin + (p->ymax-p->ymin)*frandom(); |
193 |
|
|
194 |
< |
if (viewray(thisray.rorg, thisray.rdir, &ourview, |
195 |
< |
h/hresolu, v/vresolu) < 0) { |
194 |
> |
if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir, &ourview, |
195 |
> |
h/hresolu, v/vresolu)) < -FTINY) { |
196 |
|
setcolor(thisray.rcol, 0.0, 0.0, 0.0); |
197 |
< |
} else { |
198 |
< |
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
199 |
< |
samplendx++; |
200 |
< |
rayvalue(&thisray); |
197 |
> |
} else if (!ray_pnprocs) { /* immediate mode */ |
198 |
> |
ray_trace(&thisray); |
199 |
> |
} else { /* queuing mode */ |
200 |
> |
int rval; |
201 |
> |
rayorigin(&thisray, PRIMARY, NULL, NULL); |
202 |
> |
thisray.rno = (RNUMBER)p; |
203 |
> |
rval = ray_pqueue(&thisray); |
204 |
> |
if (!rval) |
205 |
> |
return(0); |
206 |
> |
if (rval < 0) |
207 |
> |
return(-1); |
208 |
> |
/* get node for returned ray */ |
209 |
> |
p = (PNODE *)thisray.rno; |
210 |
|
} |
211 |
|
|
170 |
– |
p->x = h; |
171 |
– |
p->y = v; |
212 |
|
copycolor(p->v, thisray.rcol); |
213 |
|
scalecolor(p->v, exposure); |
214 |
|
|
215 |
< |
(*dev->paintr)(greyscale?greyof(p->v):p->v, xmin, ymin, xmax, ymax); |
215 |
> |
recolor(p); /* paint it */ |
216 |
|
|
217 |
< |
if (dev->flush != NULL && nrays - lastflush >= WFLUSH) { |
218 |
< |
lastflush = nrays; |
219 |
< |
(*dev->flush)(); |
217 |
> |
if (dev->flush != NULL) { /* shall we check for input? */ |
218 |
> |
static RNUMBER lastflush = 0; |
219 |
> |
RNUMBER counter = raynum; |
220 |
> |
int flushintvl; |
221 |
> |
if (!ray_pnprocs) { |
222 |
> |
counter = nrays; |
223 |
> |
flushintvl = WFLUSH1; |
224 |
> |
} else if (ambounce == 0) |
225 |
> |
flushintvl = ray_pnprocs*WFLUSH; |
226 |
> |
else if (niflush < WFLUSH) |
227 |
> |
flushintvl = ray_pnprocs*niflush/(ambounce+1); |
228 |
> |
else |
229 |
> |
flushintvl = ray_pnprocs*WFLUSH/(ambounce+1); |
230 |
> |
if (lastflush > counter) |
231 |
> |
lastflush = 0; /* counter wrapped */ |
232 |
> |
|
233 |
> |
if (counter - lastflush >= flushintvl) { |
234 |
> |
lastflush = counter; |
235 |
> |
(*dev->flush)(); |
236 |
> |
niflush++; |
237 |
> |
} |
238 |
|
} |
239 |
+ |
return(1); |
240 |
|
} |
241 |
|
|
242 |
|
|
243 |
< |
newimage() /* start a new image */ |
243 |
> |
int |
244 |
> |
waitrays(void) /* finish up pending rays */ |
245 |
|
{ |
246 |
+ |
int nwaited = 0; |
247 |
+ |
int rval; |
248 |
+ |
RAY raydone; |
249 |
+ |
|
250 |
+ |
if (!ray_pnprocs) /* immediate mode? */ |
251 |
+ |
return(0); |
252 |
+ |
while ((rval = ray_presult(&raydone, 0)) > 0) { |
253 |
+ |
PNODE *p = (PNODE *)raydone.rno; |
254 |
+ |
copycolor(p->v, raydone.rcol); |
255 |
+ |
scalecolor(p->v, exposure); |
256 |
+ |
recolor(p); |
257 |
+ |
nwaited++; |
258 |
+ |
} |
259 |
+ |
if (rval < 0) |
260 |
+ |
return(-1); |
261 |
+ |
return(nwaited); |
262 |
+ |
} |
263 |
+ |
|
264 |
+ |
|
265 |
+ |
void |
266 |
+ |
newimage( /* start a new image */ |
267 |
+ |
char *s |
268 |
+ |
) |
269 |
+ |
{ |
270 |
+ |
int newnp = 0; |
271 |
+ |
/* # rendering procs arg? */ |
272 |
+ |
if (s != NULL) |
273 |
+ |
sscanf(s, "%d", &newnp); |
274 |
|
/* free old image */ |
275 |
|
freepkids(&ptrunk); |
188 |
– |
/* save reserve memory */ |
189 |
– |
fillreserves(); |
276 |
|
/* compute resolution */ |
277 |
|
hresolu = dev->xsiz; |
278 |
|
vresolu = dev->ysiz; |
279 |
|
normaspect(viewaspect(&ourview), &dev->pixaspect, &hresolu, &vresolu); |
280 |
< |
pframe.l = pframe.d = 0; |
281 |
< |
pframe.r = hresolu; pframe.u = vresolu; |
280 |
> |
ptrunk.xmin = ptrunk.ymin = pframe.l = pframe.d = 0; |
281 |
> |
ptrunk.xmax = pframe.r = hresolu; |
282 |
> |
ptrunk.ymax = pframe.u = vresolu; |
283 |
|
pdepth = 0; |
284 |
|
/* clear device */ |
285 |
|
(*dev->clear)(hresolu, vresolu); |
286 |
< |
/* get first value */ |
287 |
< |
paint(&ptrunk, 0, 0, hresolu, vresolu); |
286 |
> |
|
287 |
> |
if (newparam) { /* (re)start rendering procs */ |
288 |
> |
if (ray_pnprocs) |
289 |
> |
ray_pclose(0); /* should already be closed */ |
290 |
> |
if (newnp > 0) |
291 |
> |
nproc = newnp; |
292 |
> |
if (nproc > 1) |
293 |
> |
ray_popen(nproc); |
294 |
> |
newparam = 0; |
295 |
> |
} else if ((newnp > 0) & (newnp != nproc)) { |
296 |
> |
if (newnp == 1) /* change # rendering procs */ |
297 |
> |
ray_pclose(0); |
298 |
> |
else if (newnp < ray_pnprocs) |
299 |
> |
ray_pclose(ray_pnprocs - newnp); |
300 |
> |
else |
301 |
> |
ray_popen(newnp - ray_pnprocs); |
302 |
> |
nproc = newnp; |
303 |
> |
} |
304 |
> |
niflush = 0; /* get first value */ |
305 |
> |
paint(&ptrunk); |
306 |
|
} |
307 |
|
|
308 |
|
|
309 |
< |
redraw() /* redraw the image */ |
309 |
> |
void |
310 |
> |
redraw(void) /* redraw the image */ |
311 |
|
{ |
312 |
|
(*dev->clear)(hresolu, vresolu); |
313 |
|
(*dev->comout)("redrawing...\n"); |
316 |
|
} |
317 |
|
|
318 |
|
|
319 |
< |
repaint(xmin, ymin, xmax, ymax) /* repaint a region */ |
320 |
< |
int xmin, ymin, xmax, ymax; |
319 |
> |
void |
320 |
> |
repaint( /* repaint a region */ |
321 |
> |
int xmin, |
322 |
> |
int ymin, |
323 |
> |
int xmax, |
324 |
> |
int ymax |
325 |
> |
) |
326 |
|
{ |
327 |
|
RECT reg; |
328 |
|
|
329 |
|
reg.l = xmin; reg.r = xmax; |
330 |
|
reg.d = ymin; reg.u = ymax; |
331 |
|
|
332 |
< |
paintrect(&ptrunk, 0, 0, hresolu, vresolu, ®); |
332 |
> |
paintrect(&ptrunk, ®); |
333 |
|
} |
334 |
|
|
335 |
|
|
336 |
< |
paintrect(p, xmin, ymin, xmax, ymax, r) /* paint picture rectangle */ |
337 |
< |
register PNODE *p; |
338 |
< |
int xmin, ymin, xmax, ymax; |
339 |
< |
register RECT *r; |
336 |
> |
void |
337 |
> |
paintrect( /* paint picture rectangle */ |
338 |
> |
PNODE *p, |
339 |
> |
RECT *r |
340 |
> |
) |
341 |
|
{ |
342 |
|
int mx, my; |
343 |
|
|
344 |
< |
if (xmax - xmin <= 0 || ymax - ymin <= 0) |
344 |
> |
if (p->xmax - p->xmin <= 0 || p->ymax - p->ymin <= 0) |
345 |
|
return; |
346 |
|
|
347 |
|
if (p->kid == NULL) { |
348 |
|
(*dev->paintr)(greyscale?greyof(p->v):p->v, |
349 |
< |
xmin, ymin, xmax, ymax); /* do this */ |
349 |
> |
p->xmin, p->ymin, p->xmax, p->ymax); /* do this */ |
350 |
|
return; |
351 |
|
} |
352 |
< |
mx = (xmin + xmax) >> 1; /* do kids */ |
353 |
< |
my = (ymin + ymax) >> 1; |
352 |
> |
mx = (p->xmin + p->xmax) >> 1; /* do kids */ |
353 |
> |
my = (p->ymin + p->ymax) >> 1; |
354 |
|
if (mx > r->l) { |
355 |
|
if (my > r->d) |
356 |
< |
paintrect(p->kid+DL, xmin, ymin, mx, my, r); |
356 |
> |
paintrect(p->kid+DL, r); |
357 |
|
if (my < r->u) |
358 |
< |
paintrect(p->kid+UL, xmin, my, mx, ymax, r); |
358 |
> |
paintrect(p->kid+UL, r); |
359 |
|
} |
360 |
|
if (mx < r->r) { |
361 |
|
if (my > r->d) |
362 |
< |
paintrect(p->kid+DR, mx, ymin, xmax, my, r); |
362 |
> |
paintrect(p->kid+DR, r); |
363 |
|
if (my < r->u) |
364 |
< |
paintrect(p->kid+UR, mx, my, xmax, ymax, r); |
364 |
> |
paintrect(p->kid+UR, r); |
365 |
|
} |
366 |
|
} |
367 |
|
|
368 |
|
|
369 |
|
PNODE * |
370 |
< |
findrect(x, y, p, r, pd) /* find a rectangle */ |
371 |
< |
int x, y; |
372 |
< |
register PNODE *p; |
373 |
< |
register RECT *r; |
374 |
< |
int pd; |
370 |
> |
findrect( /* find a rectangle */ |
371 |
> |
int x, |
372 |
> |
int y, |
373 |
> |
PNODE *p, |
374 |
> |
int pd |
375 |
> |
) |
376 |
|
{ |
377 |
|
int mx, my; |
378 |
|
|
379 |
|
while (p->kid != NULL && pd--) { |
380 |
|
|
381 |
< |
mx = (r->l + r->r) >> 1; |
382 |
< |
my = (r->d + r->u) >> 1; |
381 |
> |
mx = (p->xmin + p->xmax) >> 1; |
382 |
> |
my = (p->ymin + p->ymax) >> 1; |
383 |
|
|
384 |
|
if (x < mx) { |
272 |
– |
r->r = mx; |
385 |
|
if (y < my) { |
274 |
– |
r->u = my; |
386 |
|
p = p->kid+DL; |
387 |
|
} else { |
277 |
– |
r->d = my; |
388 |
|
p = p->kid+UL; |
389 |
|
} |
390 |
|
} else { |
281 |
– |
r->l = mx; |
391 |
|
if (y < my) { |
283 |
– |
r->u = my; |
392 |
|
p = p->kid+DR; |
393 |
|
} else { |
286 |
– |
r->d = my; |
394 |
|
p = p->kid+UR; |
395 |
|
} |
396 |
|
} |
399 |
|
} |
400 |
|
|
401 |
|
|
402 |
< |
scalepict(p, sf) /* scale picture values */ |
403 |
< |
register PNODE *p; |
404 |
< |
double sf; |
402 |
> |
void |
403 |
> |
compavg( /* recompute averages */ |
404 |
> |
PNODE *p |
405 |
> |
) |
406 |
|
{ |
407 |
+ |
int i, navg; |
408 |
+ |
|
409 |
+ |
if (p->kid == NULL) |
410 |
+ |
return; |
411 |
+ |
|
412 |
+ |
setcolor(p->v, .0, .0, .0); |
413 |
+ |
navg = 0; |
414 |
+ |
for (i = 0; i < 4; i++) { |
415 |
+ |
if (p->kid[i].xmin >= p->kid[i].xmax) continue; |
416 |
+ |
if (p->kid[i].ymin >= p->kid[i].ymax) continue; |
417 |
+ |
compavg(p->kid+i); |
418 |
+ |
addcolor(p->v, p->kid[i].v); |
419 |
+ |
navg++; |
420 |
+ |
} |
421 |
+ |
if (navg > 1) |
422 |
+ |
scalecolor(p->v, 1./navg); |
423 |
+ |
} |
424 |
+ |
|
425 |
+ |
|
426 |
+ |
void |
427 |
+ |
scalepict( /* scale picture values */ |
428 |
+ |
PNODE *p, |
429 |
+ |
double sf |
430 |
+ |
) |
431 |
+ |
{ |
432 |
|
scalecolor(p->v, sf); /* do this node */ |
433 |
|
|
434 |
|
if (p->kid == NULL) |
441 |
|
} |
442 |
|
|
443 |
|
|
444 |
< |
getpictcolrs(yoff, scan, p, xsiz, ysiz) /* get scanline from picture */ |
445 |
< |
int yoff; |
446 |
< |
register COLR *scan; |
447 |
< |
register PNODE *p; |
448 |
< |
int xsiz, ysiz; |
444 |
> |
void |
445 |
> |
getpictcolrs( /* get scanline from picture */ |
446 |
> |
int yoff, |
447 |
> |
COLR *scan, |
448 |
> |
PNODE *p, |
449 |
> |
int xsiz, |
450 |
> |
int ysiz |
451 |
> |
) |
452 |
|
{ |
453 |
< |
register int mx; |
453 |
> |
int mx; |
454 |
|
int my; |
455 |
|
|
456 |
|
if (p->kid == NULL) { /* do this node */ |
474 |
|
} |
475 |
|
|
476 |
|
|
477 |
< |
pcopy(p1, p2) /* copy paint node p1 into p2 */ |
478 |
< |
register PNODE *p1, *p2; |
477 |
> |
void |
478 |
> |
freepkids( /* free pnode's children */ |
479 |
> |
PNODE *p |
480 |
> |
) |
481 |
|
{ |
344 |
– |
copycolor(p2->v, p1->v); |
345 |
– |
p2->x = p1->x; |
346 |
– |
p2->y = p1->y; |
347 |
– |
} |
348 |
– |
|
349 |
– |
|
350 |
– |
freepkids(p) /* free pnode's children */ |
351 |
– |
register PNODE *p; |
352 |
– |
{ |
482 |
|
if (p->kid == NULL) |
483 |
|
return; |
484 |
|
freepkids(p->kid+DL); |
485 |
|
freepkids(p->kid+DR); |
486 |
|
freepkids(p->kid+UL); |
487 |
|
freepkids(p->kid+UR); |
488 |
< |
free((char *)p->kid); |
488 |
> |
free((void *)p->kid); |
489 |
|
p->kid = NULL; |
490 |
|
} |
491 |
|
|
492 |
|
|
493 |
< |
newview(vp) /* change viewing parameters */ |
494 |
< |
register VIEW *vp; |
493 |
> |
void |
494 |
> |
newview( /* change viewing parameters */ |
495 |
> |
VIEW *vp |
496 |
> |
) |
497 |
|
{ |
498 |
|
char *err; |
499 |
|
|
500 |
|
if ((err = setview(vp)) != NULL) { |
501 |
|
sprintf(errmsg, "view not set - %s", err); |
502 |
|
error(COMMAND, errmsg); |
503 |
< |
} else if (bcmp((char *)vp, (char *)&ourview, sizeof(VIEW))) { |
504 |
< |
copystruct(&oldview, &ourview); |
505 |
< |
copystruct(&ourview, vp); |
506 |
< |
newimage(); |
503 |
> |
} else if (memcmp((char *)vp, (char *)&ourview, sizeof(VIEW))) { |
504 |
> |
oldview = ourview; |
505 |
> |
ourview = *vp; |
506 |
> |
newimage(NULL); |
507 |
|
} |
508 |
|
} |
509 |
|
|
510 |
|
|
511 |
< |
moveview(angle, elev, mag, vc) /* move viewpoint */ |
512 |
< |
double angle, elev, mag; |
513 |
< |
FVECT vc; |
511 |
> |
void |
512 |
> |
moveview( /* move viewpoint */ |
513 |
> |
double angle, |
514 |
> |
double elev, |
515 |
> |
double mag, |
516 |
> |
FVECT vc |
517 |
> |
) |
518 |
|
{ |
519 |
|
double d; |
520 |
< |
FVECT v1; |
521 |
< |
VIEW nv; |
387 |
< |
register int i; |
520 |
> |
VIEW nv = ourview; |
521 |
> |
int i; |
522 |
|
|
389 |
– |
VCOPY(nv.vup, ourview.vup); |
390 |
– |
nv.hoff = ourview.hoff; nv.voff = ourview.voff; |
523 |
|
spinvector(nv.vdir, ourview.vdir, ourview.vup, angle*(PI/180.)); |
524 |
< |
if (elev != 0.0) { |
525 |
< |
fcross(v1, ourview.vup, nv.vdir); |
526 |
< |
normalize(v1); |
527 |
< |
spinvector(nv.vdir, nv.vdir, v1, elev*(PI/180.)); |
528 |
< |
} |
529 |
< |
if ((nv.type = ourview.type) == VT_PAR) { |
398 |
< |
nv.horiz = ourview.horiz / mag; |
399 |
< |
nv.vert = ourview.vert / mag; |
524 |
> |
if (elev != 0.0) |
525 |
> |
geodesic(nv.vdir, nv.vdir, nv.vup, elev*(-PI/180.), GEOD_RAD); |
526 |
> |
|
527 |
> |
if (nv.type == VT_PAR) { |
528 |
> |
nv.horiz /= mag; |
529 |
> |
nv.vert /= mag; |
530 |
|
d = 0.0; /* don't move closer */ |
531 |
|
for (i = 0; i < 3; i++) |
532 |
|
d += (vc[i] - ourview.vp[i])*ourview.vdir[i]; |
533 |
|
} else { |
404 |
– |
nv.horiz = ourview.horiz; |
405 |
– |
nv.vert = ourview.vert; |
534 |
|
d = sqrt(dist2(ourview.vp, vc)) / mag; |
535 |
+ |
if (nv.vfore > FTINY) { |
536 |
+ |
nv.vfore += d - d*mag; |
537 |
+ |
if (nv.vfore < 0.0) nv.vfore = 0.0; |
538 |
+ |
} |
539 |
+ |
if (nv.vaft > FTINY) { |
540 |
+ |
nv.vaft += d - d*mag; |
541 |
+ |
if (nv.vaft <= nv.vfore) nv.vaft = 0.0; |
542 |
+ |
} |
543 |
+ |
nv.vdist /= mag; |
544 |
|
} |
545 |
|
for (i = 0; i < 3; i++) |
546 |
|
nv.vp[i] = vc[i] - d*nv.vdir[i]; |
548 |
|
} |
549 |
|
|
550 |
|
|
551 |
< |
zoomview(vp, zf) /* zoom in our out */ |
552 |
< |
register VIEW *vp; |
553 |
< |
double zf; |
551 |
> |
void |
552 |
> |
pcopy( /* copy paint node p1 into p2 */ |
553 |
> |
PNODE *p1, |
554 |
> |
PNODE *p2 |
555 |
> |
) |
556 |
|
{ |
557 |
+ |
copycolor(p2->v, p1->v); |
558 |
+ |
p2->x = p1->x; |
559 |
+ |
p2->y = p1->y; |
560 |
+ |
} |
561 |
+ |
|
562 |
+ |
|
563 |
+ |
void |
564 |
+ |
zoomview( /* zoom in or out */ |
565 |
+ |
VIEW *vp, |
566 |
+ |
double zf |
567 |
+ |
) |
568 |
+ |
{ |
569 |
|
switch (vp->type) { |
570 |
|
case VT_PAR: /* parallel view */ |
571 |
+ |
vp->horiz /= zf; |
572 |
+ |
vp->vert /= zf; |
573 |
+ |
return; |
574 |
|
case VT_ANG: /* angular fisheye */ |
575 |
|
vp->horiz /= zf; |
576 |
+ |
if (vp->horiz > 360.) |
577 |
+ |
vp->horiz = 360.; |
578 |
|
vp->vert /= zf; |
579 |
+ |
if (vp->vert > 360.) |
580 |
+ |
vp->vert = 360.; |
581 |
+ |
return; |
582 |
+ |
case VT_PLS: /* planisphere fisheye */ |
583 |
+ |
vp->horiz = sin((PI/180./2.)*vp->horiz) / |
584 |
+ |
(1.0 + cos((PI/180./2.)*vp->horiz)) / zf; |
585 |
+ |
vp->horiz *= vp->horiz; |
586 |
+ |
vp->horiz = (2.*180./PI)*acos((1. - vp->horiz) / |
587 |
+ |
(1. + vp->horiz)); |
588 |
+ |
vp->vert = sin((PI/180./2.)*vp->vert) / |
589 |
+ |
(1.0 + cos((PI/180./2.)*vp->vert)) / zf; |
590 |
+ |
vp->vert *= vp->vert; |
591 |
+ |
vp->vert = (2.*180./PI)*acos((1. - vp->vert) / |
592 |
+ |
(1. + vp->vert)); |
593 |
+ |
return; |
594 |
+ |
case VT_CYL: /* cylindrical panorama */ |
595 |
+ |
vp->horiz /= zf; |
596 |
+ |
if (vp->horiz > 360.) |
597 |
+ |
vp->horiz = 360.; |
598 |
+ |
vp->vert = atan(tan(vp->vert*(PI/180./2.))/zf) / (PI/180./2.); |
599 |
|
return; |
600 |
|
case VT_PER: /* perspective view */ |
601 |
|
vp->horiz = atan(tan(vp->horiz*(PI/180./2.))/zf) / |