| 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 int 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 |
< |
if (viewray(thisray.rorg, thisray.rdir, &ourview, |
| 105 |
< |
(x+.5)/hresolu, (y+.5)/vresolu) < 0) { |
| 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; |
| 147 |
|
} |
| 148 |
|
|
| 149 |
|
|
| 150 |
< |
paint(p, xmin, ymin, xmax, ymax) /* compute and paint a rectangle */ |
| 151 |
< |
register PNODE *p; |
| 152 |
< |
int xmin, ymin, xmax, ymax; |
| 150 |
> |
int |
| 151 |
> |
paint( /* compute and paint a rectangle */ |
| 152 |
> |
PNODE *p |
| 153 |
> |
) |
| 154 |
|
{ |
| 155 |
< |
extern long nrays; |
| 156 |
< |
static long lastflush = 0; |
| 155 |
> |
extern int ray_pnprocs; |
| 156 |
> |
static unsigned long lastflush = 0; |
| 157 |
|
static RAY thisray; |
| 158 |
|
double h, v; |
| 159 |
|
|
| 160 |
< |
if (xmax - xmin <= 0 || ymax - ymin <= 0) { /* empty */ |
| 161 |
< |
p->x = xmin; |
| 162 |
< |
p->y = ymin; |
| 160 |
> |
if (p->xmax - p->xmin <= 0 || p->ymax - p->ymin <= 0) { /* empty */ |
| 161 |
> |
p->x = p->xmin; |
| 162 |
> |
p->y = p->ymin; |
| 163 |
|
setcolor(p->v, 0.0, 0.0, 0.0); |
| 164 |
< |
return; |
| 164 |
> |
return(0); |
| 165 |
|
} |
| 166 |
|
/* jitter ray direction */ |
| 167 |
< |
h = xmin + (xmax-xmin)*frandom(); |
| 168 |
< |
v = ymin + (ymax-ymin)*frandom(); |
| 167 |
> |
p->x = h = p->xmin + (p->xmax-p->xmin)*frandom(); |
| 168 |
> |
p->y = v = p->ymin + (p->ymax-p->ymin)*frandom(); |
| 169 |
|
|
| 170 |
< |
if (viewray(thisray.rorg, thisray.rdir, &ourview, |
| 171 |
< |
h/hresolu, v/vresolu) < 0) { |
| 170 |
> |
if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir, &ourview, |
| 171 |
> |
h/hresolu, v/vresolu)) < -FTINY) { |
| 172 |
|
setcolor(thisray.rcol, 0.0, 0.0, 0.0); |
| 173 |
|
} else { |
| 174 |
< |
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
| 175 |
< |
samplendx++; |
| 176 |
< |
rayvalue(&thisray); |
| 174 |
> |
int rval; |
| 175 |
> |
rayorigin(&thisray, PRIMARY, NULL, NULL); |
| 176 |
> |
thisray.rno = (unsigned long)p; |
| 177 |
> |
rval = ray_pqueue(&thisray); |
| 178 |
> |
if (!rval) |
| 179 |
> |
return(0); |
| 180 |
> |
if (rval < 0) |
| 181 |
> |
return(-1); |
| 182 |
> |
p = (PNODE *)thisray.rno; |
| 183 |
|
} |
| 184 |
|
|
| 164 |
– |
p->x = h; |
| 165 |
– |
p->y = v; |
| 185 |
|
copycolor(p->v, thisray.rcol); |
| 186 |
|
scalecolor(p->v, exposure); |
| 187 |
|
|
| 188 |
< |
(*dev->paintr)(greyscale?greyof(p->v):p->v, xmin, ymin, xmax, ymax); |
| 188 |
> |
(*dev->paintr)(greyscale?greyof(p->v):p->v, |
| 189 |
> |
p->xmin, p->ymin, p->xmax, p->ymax); |
| 190 |
|
|
| 191 |
< |
if (dev->flush != NULL && nrays - lastflush >= WFLUSH) { |
| 192 |
< |
lastflush = nrays; |
| 191 |
> |
if (dev->flush != NULL && raynum - lastflush >= ray_pnprocs * |
| 192 |
> |
(ambounce > 0 && niflush < WFLUSH ? niflush : WFLUSH)) { |
| 193 |
> |
lastflush = raynum; |
| 194 |
|
(*dev->flush)(); |
| 195 |
+ |
niflush++; |
| 196 |
|
} |
| 197 |
+ |
return(1); |
| 198 |
|
} |
| 199 |
|
|
| 200 |
|
|
| 201 |
< |
newimage() /* start a new image */ |
| 201 |
> |
int |
| 202 |
> |
waitrays(void) /* finish up pending rays */ |
| 203 |
|
{ |
| 204 |
+ |
int nwaited = 0; |
| 205 |
+ |
int rval; |
| 206 |
+ |
RAY raydone; |
| 207 |
+ |
|
| 208 |
+ |
while ((rval = ray_presult(&raydone, 0)) > 0) { |
| 209 |
+ |
PNODE *p = (PNODE *)raydone.rno; |
| 210 |
+ |
copycolor(p->v, raydone.rcol); |
| 211 |
+ |
scalecolor(p->v, exposure); |
| 212 |
+ |
(*dev->paintr)(greyscale?greyof(p->v):p->v, |
| 213 |
+ |
p->xmin, p->ymin, p->xmax, p->ymax); |
| 214 |
+ |
nwaited++; |
| 215 |
+ |
} |
| 216 |
+ |
if (rval < 0) |
| 217 |
+ |
return(-1); |
| 218 |
+ |
return(nwaited); |
| 219 |
+ |
} |
| 220 |
+ |
|
| 221 |
+ |
|
| 222 |
+ |
void |
| 223 |
+ |
newimage( /* start a new image */ |
| 224 |
+ |
char *s |
| 225 |
+ |
) |
| 226 |
+ |
{ |
| 227 |
+ |
int newnp; |
| 228 |
+ |
/* change in nproc? */ |
| 229 |
+ |
if (s != NULL && sscanf(s, "%d", &newnp) == 1 && newnp > 0) { |
| 230 |
+ |
if (!newparam) { |
| 231 |
+ |
if (newnp < nproc) |
| 232 |
+ |
ray_pclose(nproc - newnp); |
| 233 |
+ |
else |
| 234 |
+ |
ray_popen(newnp - nproc); |
| 235 |
+ |
} |
| 236 |
+ |
nproc = newnp; |
| 237 |
+ |
} |
| 238 |
|
/* free old image */ |
| 239 |
|
freepkids(&ptrunk); |
| 182 |
– |
/* save reserve memory */ |
| 183 |
– |
fillreserves(); |
| 240 |
|
/* compute resolution */ |
| 241 |
|
hresolu = dev->xsiz; |
| 242 |
|
vresolu = dev->ysiz; |
| 243 |
|
normaspect(viewaspect(&ourview), &dev->pixaspect, &hresolu, &vresolu); |
| 244 |
< |
pframe.l = pframe.d = 0; |
| 245 |
< |
pframe.r = hresolu; pframe.u = vresolu; |
| 244 |
> |
ptrunk.xmin = ptrunk.ymin = pframe.l = pframe.d = 0; |
| 245 |
> |
ptrunk.xmax = pframe.r = hresolu; |
| 246 |
> |
ptrunk.ymax = pframe.u = vresolu; |
| 247 |
|
pdepth = 0; |
| 248 |
|
/* clear device */ |
| 249 |
|
(*dev->clear)(hresolu, vresolu); |
| 250 |
< |
/* get first value */ |
| 251 |
< |
paint(&ptrunk, 0, 0, hresolu, vresolu); |
| 250 |
> |
|
| 251 |
> |
if (newparam) { /* (re)start rendering procs */ |
| 252 |
> |
ray_pclose(0); |
| 253 |
> |
ray_popen(nproc); |
| 254 |
> |
newparam = 0; |
| 255 |
> |
} |
| 256 |
> |
niflush = 0; /* get first value */ |
| 257 |
> |
paint(&ptrunk); |
| 258 |
|
} |
| 259 |
|
|
| 260 |
|
|
| 261 |
< |
redraw() /* redraw the image */ |
| 261 |
> |
void |
| 262 |
> |
redraw(void) /* redraw the image */ |
| 263 |
|
{ |
| 264 |
|
(*dev->clear)(hresolu, vresolu); |
| 265 |
|
(*dev->comout)("redrawing...\n"); |
| 268 |
|
} |
| 269 |
|
|
| 270 |
|
|
| 271 |
< |
repaint(xmin, ymin, xmax, ymax) /* repaint a region */ |
| 272 |
< |
int xmin, ymin, xmax, ymax; |
| 271 |
> |
void |
| 272 |
> |
repaint( /* repaint a region */ |
| 273 |
> |
int xmin, |
| 274 |
> |
int ymin, |
| 275 |
> |
int xmax, |
| 276 |
> |
int ymax |
| 277 |
> |
) |
| 278 |
|
{ |
| 279 |
|
RECT reg; |
| 280 |
|
|
| 281 |
|
reg.l = xmin; reg.r = xmax; |
| 282 |
|
reg.d = ymin; reg.u = ymax; |
| 283 |
|
|
| 284 |
< |
paintrect(&ptrunk, 0, 0, hresolu, vresolu, ®); |
| 284 |
> |
paintrect(&ptrunk, ®); |
| 285 |
|
} |
| 286 |
|
|
| 287 |
|
|
| 288 |
< |
paintrect(p, xmin, ymin, xmax, ymax, r) /* paint picture rectangle */ |
| 289 |
< |
register PNODE *p; |
| 290 |
< |
int xmin, ymin, xmax, ymax; |
| 291 |
< |
register RECT *r; |
| 288 |
> |
void |
| 289 |
> |
paintrect( /* paint picture rectangle */ |
| 290 |
> |
PNODE *p, |
| 291 |
> |
RECT *r |
| 292 |
> |
) |
| 293 |
|
{ |
| 294 |
|
int mx, my; |
| 295 |
|
|
| 296 |
< |
if (xmax - xmin <= 0 || ymax - ymin <= 0) |
| 296 |
> |
if (p->xmax - p->xmin <= 0 || p->ymax - p->ymin <= 0) |
| 297 |
|
return; |
| 298 |
|
|
| 299 |
|
if (p->kid == NULL) { |
| 300 |
|
(*dev->paintr)(greyscale?greyof(p->v):p->v, |
| 301 |
< |
xmin, ymin, xmax, ymax); /* do this */ |
| 301 |
> |
p->xmin, p->ymin, p->xmax, p->ymax); /* do this */ |
| 302 |
|
return; |
| 303 |
|
} |
| 304 |
< |
mx = (xmin + xmax) >> 1; /* do kids */ |
| 305 |
< |
my = (ymin + ymax) >> 1; |
| 304 |
> |
mx = (p->xmin + p->xmax) >> 1; /* do kids */ |
| 305 |
> |
my = (p->ymin + p->ymax) >> 1; |
| 306 |
|
if (mx > r->l) { |
| 307 |
|
if (my > r->d) |
| 308 |
< |
paintrect(p->kid+DL, xmin, ymin, mx, my, r); |
| 308 |
> |
paintrect(p->kid+DL, r); |
| 309 |
|
if (my < r->u) |
| 310 |
< |
paintrect(p->kid+UL, xmin, my, mx, ymax, r); |
| 310 |
> |
paintrect(p->kid+UL, r); |
| 311 |
|
} |
| 312 |
|
if (mx < r->r) { |
| 313 |
|
if (my > r->d) |
| 314 |
< |
paintrect(p->kid+DR, mx, ymin, xmax, my, r); |
| 314 |
> |
paintrect(p->kid+DR, r); |
| 315 |
|
if (my < r->u) |
| 316 |
< |
paintrect(p->kid+UR, mx, my, xmax, ymax, r); |
| 316 |
> |
paintrect(p->kid+UR, r); |
| 317 |
|
} |
| 318 |
|
} |
| 319 |
|
|
| 320 |
|
|
| 321 |
|
PNODE * |
| 322 |
< |
findrect(x, y, p, r, pd) /* find a rectangle */ |
| 323 |
< |
int x, y; |
| 324 |
< |
register PNODE *p; |
| 325 |
< |
register RECT *r; |
| 326 |
< |
int pd; |
| 322 |
> |
findrect( /* find a rectangle */ |
| 323 |
> |
int x, |
| 324 |
> |
int y, |
| 325 |
> |
PNODE *p, |
| 326 |
> |
int pd |
| 327 |
> |
) |
| 328 |
|
{ |
| 329 |
|
int mx, my; |
| 330 |
|
|
| 331 |
|
while (p->kid != NULL && pd--) { |
| 332 |
|
|
| 333 |
< |
mx = (r->l + r->r) >> 1; |
| 334 |
< |
my = (r->d + r->u) >> 1; |
| 333 |
> |
mx = (p->xmin + p->xmax) >> 1; |
| 334 |
> |
my = (p->ymin + p->ymax) >> 1; |
| 335 |
|
|
| 336 |
|
if (x < mx) { |
| 266 |
– |
r->r = mx; |
| 337 |
|
if (y < my) { |
| 268 |
– |
r->u = my; |
| 338 |
|
p = p->kid+DL; |
| 339 |
|
} else { |
| 271 |
– |
r->d = my; |
| 340 |
|
p = p->kid+UL; |
| 341 |
|
} |
| 342 |
|
} else { |
| 275 |
– |
r->l = mx; |
| 343 |
|
if (y < my) { |
| 277 |
– |
r->u = my; |
| 344 |
|
p = p->kid+DR; |
| 345 |
|
} else { |
| 280 |
– |
r->d = my; |
| 346 |
|
p = p->kid+UR; |
| 347 |
|
} |
| 348 |
|
} |
| 351 |
|
} |
| 352 |
|
|
| 353 |
|
|
| 354 |
< |
scalepict(p, sf) /* scale picture values */ |
| 355 |
< |
register PNODE *p; |
| 356 |
< |
double sf; |
| 354 |
> |
void |
| 355 |
> |
scalepict( /* scale picture values */ |
| 356 |
> |
PNODE *p, |
| 357 |
> |
double sf |
| 358 |
> |
) |
| 359 |
|
{ |
| 360 |
|
scalecolor(p->v, sf); /* do this node */ |
| 361 |
|
|
| 369 |
|
} |
| 370 |
|
|
| 371 |
|
|
| 372 |
< |
getpictcolrs(yoff, scan, p, xsiz, ysiz) /* get scanline from picture */ |
| 373 |
< |
int yoff; |
| 374 |
< |
register COLR *scan; |
| 375 |
< |
register PNODE *p; |
| 376 |
< |
int xsiz, ysiz; |
| 372 |
> |
void |
| 373 |
> |
getpictcolrs( /* get scanline from picture */ |
| 374 |
> |
int yoff, |
| 375 |
> |
COLR *scan, |
| 376 |
> |
PNODE *p, |
| 377 |
> |
int xsiz, |
| 378 |
> |
int ysiz |
| 379 |
> |
) |
| 380 |
|
{ |
| 381 |
< |
register int mx; |
| 381 |
> |
int mx; |
| 382 |
|
int my; |
| 383 |
|
|
| 384 |
|
if (p->kid == NULL) { /* do this node */ |
| 402 |
|
} |
| 403 |
|
|
| 404 |
|
|
| 405 |
< |
pcopy(p1, p2) /* copy paint node p1 into p2 */ |
| 406 |
< |
register PNODE *p1, *p2; |
| 405 |
> |
void |
| 406 |
> |
freepkids( /* free pnode's children */ |
| 407 |
> |
PNODE *p |
| 408 |
> |
) |
| 409 |
|
{ |
| 338 |
– |
copycolor(p2->v, p1->v); |
| 339 |
– |
p2->x = p1->x; |
| 340 |
– |
p2->y = p1->y; |
| 341 |
– |
} |
| 342 |
– |
|
| 343 |
– |
|
| 344 |
– |
freepkids(p) /* free pnode's children */ |
| 345 |
– |
register PNODE *p; |
| 346 |
– |
{ |
| 410 |
|
if (p->kid == NULL) |
| 411 |
|
return; |
| 412 |
|
freepkids(p->kid+DL); |
| 413 |
|
freepkids(p->kid+DR); |
| 414 |
|
freepkids(p->kid+UL); |
| 415 |
|
freepkids(p->kid+UR); |
| 416 |
< |
free((char *)p->kid); |
| 416 |
> |
free((void *)p->kid); |
| 417 |
|
p->kid = NULL; |
| 418 |
|
} |
| 419 |
|
|
| 420 |
|
|
| 421 |
< |
newview(vp) /* change viewing parameters */ |
| 422 |
< |
register VIEW *vp; |
| 421 |
> |
void |
| 422 |
> |
newview( /* change viewing parameters */ |
| 423 |
> |
VIEW *vp |
| 424 |
> |
) |
| 425 |
|
{ |
| 426 |
|
char *err; |
| 427 |
|
|
| 428 |
|
if ((err = setview(vp)) != NULL) { |
| 429 |
|
sprintf(errmsg, "view not set - %s", err); |
| 430 |
|
error(COMMAND, errmsg); |
| 431 |
< |
} else if (bcmp((char *)vp, (char *)&ourview, sizeof(VIEW))) { |
| 432 |
< |
copystruct(&oldview, &ourview); |
| 433 |
< |
copystruct(&ourview, vp); |
| 434 |
< |
newimage(); |
| 431 |
> |
} else if (memcmp((char *)vp, (char *)&ourview, sizeof(VIEW))) { |
| 432 |
> |
oldview = ourview; |
| 433 |
> |
ourview = *vp; |
| 434 |
> |
newimage(NULL); |
| 435 |
|
} |
| 436 |
|
} |
| 437 |
|
|
| 438 |
|
|
| 439 |
< |
moveview(angle, elev, mag, vc) /* move viewpoint */ |
| 440 |
< |
double angle, elev, mag; |
| 441 |
< |
FVECT vc; |
| 439 |
> |
void |
| 440 |
> |
moveview( /* move viewpoint */ |
| 441 |
> |
double angle, |
| 442 |
> |
double elev, |
| 443 |
> |
double mag, |
| 444 |
> |
FVECT vc |
| 445 |
> |
) |
| 446 |
|
{ |
| 378 |
– |
extern double sqrt(), dist2(); |
| 447 |
|
double d; |
| 448 |
|
FVECT v1; |
| 449 |
< |
VIEW nv; |
| 450 |
< |
register int i; |
| 449 |
> |
VIEW nv = ourview; |
| 450 |
> |
int i; |
| 451 |
|
|
| 384 |
– |
VCOPY(nv.vup, ourview.vup); |
| 385 |
– |
nv.hoff = ourview.hoff; nv.voff = ourview.voff; |
| 452 |
|
spinvector(nv.vdir, ourview.vdir, ourview.vup, angle*(PI/180.)); |
| 453 |
|
if (elev != 0.0) { |
| 454 |
|
fcross(v1, ourview.vup, nv.vdir); |
| 455 |
|
normalize(v1); |
| 456 |
|
spinvector(nv.vdir, nv.vdir, v1, elev*(PI/180.)); |
| 457 |
|
} |
| 458 |
< |
if ((nv.type = ourview.type) == VT_PAR) { |
| 459 |
< |
nv.horiz = ourview.horiz / mag; |
| 460 |
< |
nv.vert = ourview.vert / mag; |
| 458 |
> |
if (nv.type == VT_PAR) { |
| 459 |
> |
nv.horiz /= mag; |
| 460 |
> |
nv.vert /= mag; |
| 461 |
|
d = 0.0; /* don't move closer */ |
| 462 |
|
for (i = 0; i < 3; i++) |
| 463 |
|
d += (vc[i] - ourview.vp[i])*ourview.vdir[i]; |
| 464 |
|
} else { |
| 399 |
– |
nv.horiz = ourview.horiz; |
| 400 |
– |
nv.vert = ourview.vert; |
| 465 |
|
d = sqrt(dist2(ourview.vp, vc)) / mag; |
| 466 |
+ |
if (nv.vfore > FTINY) { |
| 467 |
+ |
nv.vfore += d - d*mag; |
| 468 |
+ |
if (nv.vfore < 0.0) nv.vfore = 0.0; |
| 469 |
+ |
} |
| 470 |
+ |
if (nv.vaft > FTINY) { |
| 471 |
+ |
nv.vaft += d - d*mag; |
| 472 |
+ |
if (nv.vaft <= nv.vfore) nv.vaft = 0.0; |
| 473 |
+ |
} |
| 474 |
+ |
nv.vdist /= mag; |
| 475 |
|
} |
| 476 |
|
for (i = 0; i < 3; i++) |
| 477 |
|
nv.vp[i] = vc[i] - d*nv.vdir[i]; |
| 479 |
|
} |
| 480 |
|
|
| 481 |
|
|
| 482 |
< |
zoomview(vp, zf) /* zoom in our out */ |
| 483 |
< |
register VIEW *vp; |
| 484 |
< |
double zf; |
| 482 |
> |
void |
| 483 |
> |
pcopy( /* copy paint node p1 into p2 */ |
| 484 |
> |
PNODE *p1, |
| 485 |
> |
PNODE *p2 |
| 486 |
> |
) |
| 487 |
|
{ |
| 488 |
+ |
copycolor(p2->v, p1->v); |
| 489 |
+ |
p2->x = p1->x; |
| 490 |
+ |
p2->y = p1->y; |
| 491 |
+ |
} |
| 492 |
+ |
|
| 493 |
+ |
|
| 494 |
+ |
void |
| 495 |
+ |
zoomview( /* zoom in or out */ |
| 496 |
+ |
VIEW *vp, |
| 497 |
+ |
double zf |
| 498 |
+ |
) |
| 499 |
+ |
{ |
| 500 |
|
switch (vp->type) { |
| 501 |
|
case VT_PAR: /* parallel view */ |
| 502 |
+ |
vp->horiz /= zf; |
| 503 |
+ |
vp->vert /= zf; |
| 504 |
+ |
return; |
| 505 |
|
case VT_ANG: /* angular fisheye */ |
| 506 |
|
vp->horiz /= zf; |
| 507 |
+ |
if (vp->horiz > 360.) |
| 508 |
+ |
vp->horiz = 360.; |
| 509 |
|
vp->vert /= zf; |
| 510 |
+ |
if (vp->vert > 360.) |
| 511 |
+ |
vp->vert = 360.; |
| 512 |
+ |
return; |
| 513 |
+ |
case VT_PLS: /* planisphere fisheye */ |
| 514 |
+ |
vp->horiz = sin((PI/180./2.)*vp->horiz) / |
| 515 |
+ |
(1.0 + cos((PI/180./2.)*vp->horiz)) / zf; |
| 516 |
+ |
vp->horiz *= vp->horiz; |
| 517 |
+ |
vp->horiz = (2.*180./PI)*acos((1. - vp->horiz) / |
| 518 |
+ |
(1. + vp->horiz)); |
| 519 |
+ |
vp->vert = sin((PI/180./2.)*vp->vert) / |
| 520 |
+ |
(1.0 + cos((PI/180./2.)*vp->vert)) / zf; |
| 521 |
+ |
vp->vert *= vp->vert; |
| 522 |
+ |
vp->vert = (2.*180./PI)*acos((1. - vp->vert) / |
| 523 |
+ |
(1. + vp->vert)); |
| 524 |
+ |
return; |
| 525 |
+ |
case VT_CYL: /* cylindrical panorama */ |
| 526 |
+ |
vp->horiz /= zf; |
| 527 |
+ |
if (vp->horiz > 360.) |
| 528 |
+ |
vp->horiz = 360.; |
| 529 |
+ |
vp->vert = atan(tan(vp->vert*(PI/180./2.))/zf) / (PI/180./2.); |
| 530 |
|
return; |
| 531 |
|
case VT_PER: /* perspective view */ |
| 532 |
|
vp->horiz = atan(tan(vp->horiz*(PI/180./2.))/zf) / |