| 9 |
|
|
| 10 |
|
#include "copyright.h" |
| 11 |
|
|
| 12 |
+ |
#include <ctype.h> |
| 13 |
|
#include "rtio.h" |
| 14 |
|
#include "rtmath.h" |
| 15 |
|
#include "paths.h" |
| 35 |
|
if (v->vaft < -FTINY || (v->vaft > FTINY && v->vaft <= v->vfore)) |
| 36 |
|
return("illegal fore/aft clipping plane"); |
| 37 |
|
|
| 38 |
+ |
if (v->vdist <= FTINY) |
| 39 |
+ |
return("illegal view distance"); |
| 40 |
|
v->vdist *= normalize(v->vdir); /* normalize direction */ |
| 41 |
|
if (v->vdist == 0.0) |
| 42 |
|
return("zero view direction"); |
| 93 |
|
v->hn2 = 2.0 * sin(v->horiz*(PI/180.0/2.0)); |
| 94 |
|
v->vn2 = 2.0 * sin(v->vert*(PI/180.0/2.0)); |
| 95 |
|
break; |
| 96 |
+ |
case VT_PLS: /* planispheric fisheye */ |
| 97 |
+ |
if (v->horiz >= 360.0-FTINY) |
| 98 |
+ |
return(ill_horiz); |
| 99 |
+ |
if (v->vert >= 360.0-FTINY) |
| 100 |
+ |
return(ill_vert); |
| 101 |
+ |
v->hn2 = 2.*sin(v->horiz*(PI/180.0/2.0)) / |
| 102 |
+ |
(1.0 + cos(v->horiz*(PI/180.0/2.0))); |
| 103 |
+ |
v->vn2 = 2.*sin(v->vert*(PI/180.0/2.0)) / |
| 104 |
+ |
(1.0 + cos(v->vert*(PI/180.0/2.0))); |
| 105 |
+ |
break; |
| 106 |
|
default: |
| 107 |
|
return("unknown view type"); |
| 108 |
|
} |
| 109 |
< |
if (v->type != VT_ANG) { |
| 109 |
> |
if (v->type != VT_ANG && v->type != VT_PLS) { |
| 110 |
|
if (v->type != VT_CYL) { |
| 111 |
|
v->hvec[0] *= v->hn2; |
| 112 |
|
v->hvec[1] *= v->hn2; |
| 193 |
|
d = normalize(direc); |
| 194 |
|
return(v->vaft > FTINY ? (v->vaft - v->vfore)*d : 0.0); |
| 195 |
|
case VT_ANG: /* angular fisheye */ |
| 196 |
< |
x *= v->horiz/180.0; |
| 197 |
< |
y *= v->vert/180.0; |
| 196 |
> |
x *= (1.0/180.0)*v->horiz; |
| 197 |
> |
y *= (1.0/180.0)*v->vert; |
| 198 |
|
d = x*x + y*y; |
| 199 |
|
if (d > 1.0) |
| 200 |
|
return(-1.0); |
| 201 |
|
d = sqrt(d); |
| 202 |
|
z = cos(PI*d); |
| 203 |
< |
d = d <= FTINY ? PI : sqrt(1 - z*z)/d; |
| 203 |
> |
d = d <= FTINY ? PI : sqrt(1.0 - z*z)/d; |
| 204 |
|
x *= d; |
| 205 |
|
y *= d; |
| 206 |
|
direc[0] = z*v->vdir[0] + x*v->hvec[0] + y*v->vvec[0]; |
| 210 |
|
orig[1] = v->vp[1] + v->vfore*direc[1]; |
| 211 |
|
orig[2] = v->vp[2] + v->vfore*direc[2]; |
| 212 |
|
return(v->vaft > FTINY ? v->vaft - v->vfore : 0.0); |
| 213 |
+ |
case VT_PLS: /* planispheric fisheye */ |
| 214 |
+ |
x *= sqrt(v->hn2); |
| 215 |
+ |
y *= sqrt(v->vn2); |
| 216 |
+ |
d = x*x + y*y; |
| 217 |
+ |
z = (1. - d)/(1. + d); |
| 218 |
+ |
d = d <= FTINY*FTINY ? PI : sqrt((1.0 - z*z)/d); |
| 219 |
+ |
x *= d; |
| 220 |
+ |
y *= d; |
| 221 |
+ |
direc[0] = z*v->vdir[0] + x*v->hvec[0] + y*v->vvec[0]; |
| 222 |
+ |
direc[1] = z*v->vdir[1] + x*v->hvec[1] + y*v->vvec[1]; |
| 223 |
+ |
direc[2] = z*v->vdir[2] + x*v->hvec[2] + y*v->vvec[2]; |
| 224 |
+ |
orig[0] = v->vp[0] + v->vfore*direc[0]; |
| 225 |
+ |
orig[1] = v->vp[1] + v->vfore*direc[1]; |
| 226 |
+ |
orig[2] = v->vp[2] + v->vfore*direc[2]; |
| 227 |
+ |
return(v->vaft > FTINY ? v->vaft - v->vfore : 0.0); |
| 228 |
|
} |
| 229 |
|
return(-1.0); |
| 230 |
|
} |
| 239 |
|
double d, d2; |
| 240 |
|
FVECT disp; |
| 241 |
|
|
| 242 |
< |
disp[0] = p[0] - v->vp[0]; |
| 215 |
< |
disp[1] = p[1] - v->vp[1]; |
| 216 |
< |
disp[2] = p[2] - v->vp[2]; |
| 242 |
> |
VSUB(disp, p, v->vp); |
| 243 |
|
|
| 244 |
|
switch (v->type) { |
| 245 |
|
case VT_PAR: /* parallel view */ |
| 288 |
|
ip[0] += 180.0/v->horiz; |
| 289 |
|
return; |
| 290 |
|
} |
| 291 |
< |
d = acos(d)/PI / sqrt(1.0 - d*d); |
| 292 |
< |
ip[0] += DOT(disp,v->hvec)*d*180.0/v->horiz; |
| 293 |
< |
ip[1] += DOT(disp,v->vvec)*d*180.0/v->vert; |
| 291 |
> |
d = (180.0/PI)*acos(d) / sqrt(1.0 - d*d); |
| 292 |
> |
ip[0] += DOT(disp,v->hvec)*d/v->horiz; |
| 293 |
> |
ip[1] += DOT(disp,v->vvec)*d/v->vert; |
| 294 |
|
return; |
| 295 |
+ |
case VT_PLS: /* planispheric fisheye */ |
| 296 |
+ |
ip[0] = 0.5 - v->hoff; |
| 297 |
+ |
ip[1] = 0.5 - v->voff; |
| 298 |
+ |
ip[2] = normalize(disp) - v->vfore; |
| 299 |
+ |
d = DOT(disp,v->vdir); |
| 300 |
+ |
if (d >= 1.0-FTINY) |
| 301 |
+ |
return; |
| 302 |
+ |
if (d <= -(1.0-FTINY)) |
| 303 |
+ |
return; /* really an error */ |
| 304 |
+ |
d = sqrt(1.0 - d*d) / (1.0 + d); |
| 305 |
+ |
ip[0] += DOT(disp,v->hvec)*d/sqrt(v->hn2); |
| 306 |
+ |
ip[1] += DOT(disp,v->vvec)*d/sqrt(v->vn2); |
| 307 |
+ |
return; |
| 308 |
|
} |
| 309 |
|
ip[0] = DOT(disp,v->hvec)/v->hn2 + 0.5 - v->hoff; |
| 310 |
|
ip[1] = DOT(disp,v->vvec)/v->vn2 + 0.5 - v->voff; |
| 437 |
|
int na; |
| 438 |
|
int nvopts = 0; |
| 439 |
|
|
| 440 |
< |
while (*s == ' ') |
| 441 |
< |
s++; |
| 442 |
< |
if (*s != '-') |
| 404 |
< |
s = sskip2(s,1); |
| 440 |
> |
while (isspace(*s)) |
| 441 |
> |
if (!*s++) |
| 442 |
> |
return(0); |
| 443 |
|
while (*s) { |
| 444 |
|
ac = 0; |
| 445 |
|
do { |
| 446 |
|
if (ac || *s == '-') |
| 447 |
|
av[ac++] = s; |
| 448 |
< |
while (*s && *s != ' ') |
| 448 |
> |
while (*s && !isspace(*s)) |
| 449 |
|
s++; |
| 450 |
< |
while (*s == ' ') |
| 450 |
> |
while (isspace(*s)) |
| 451 |
|
s++; |
| 452 |
|
} while (*s && ac < 4); |
| 453 |
|
if ((na = getviewopt(vp, ac, av)) >= 0) { |
| 485 |
|
static char vwstr[128]; |
| 486 |
|
register char *cp = vwstr; |
| 487 |
|
|
| 488 |
+ |
*cp = '\0'; |
| 489 |
|
if (vp->type != stdview.type) { |
| 490 |
|
sprintf(cp, " -vt%c", vp->type); |
| 491 |
|
cp += strlen(cp); |