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