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