27 |
|
if (normalize(v->vdir) == 0.0) /* normalize direction */ |
28 |
|
return("zero view direction"); |
29 |
|
|
30 |
+ |
if (normalize(v->vup) == 0.0) /* normalize view up */ |
31 |
+ |
return("zero view up vector"); |
32 |
+ |
|
33 |
|
fcross(v->hvec, v->vdir, v->vup); /* compute horiz dir */ |
34 |
|
|
35 |
|
if (normalize(v->hvec) == 0.0) |
36 |
< |
return("illegal view up vector"); |
36 |
> |
return("view up parallel to view direction"); |
37 |
|
|
38 |
|
fcross(v->vvec, v->hvec, v->vdir); /* compute vert dir */ |
39 |
|
|
74 |
|
default: |
75 |
|
return("unknown view type"); |
76 |
|
} |
77 |
< |
if (v->type == VT_PAR || v->type == VT_PER) { |
77 |
> |
if (v->type != VT_ANG) { |
78 |
|
v->hvec[0] *= v->hn2; |
79 |
|
v->hvec[1] *= v->hn2; |
80 |
|
v->hvec[2] *= v->hn2; |
128 |
|
normalize(direc); |
129 |
|
return(0); |
130 |
|
case VT_HEM: /* hemispherical fisheye */ |
131 |
< |
x *= v->horiz/90.0; |
129 |
< |
y *= v->vert/90.0; |
130 |
< |
z = 1.0 - x*x - y*y; |
131 |
> |
z = 1.0 - x*x*v->hn2 - y*y*v->vn2; |
132 |
|
if (z < 0.0) |
133 |
|
return(-1); |
134 |
|
z = sqrt(z); |
178 |
|
case VT_PAR: /* parallel view */ |
179 |
|
if (zp != NULL) |
180 |
|
*zp = DOT(disp,v->vdir); |
181 |
< |
*xp = DOT(disp,v->hvec)/v->hn2 + 0.5 - v->hoff; |
181 |
< |
*yp = DOT(disp,v->vvec)/v->vn2 + 0.5 - v->voff; |
182 |
< |
return; |
181 |
> |
break; |
182 |
|
case VT_PER: /* perspective view */ |
183 |
|
d = DOT(disp,v->vdir); |
184 |
|
if (zp != NULL) { |
194 |
|
disp[1] *= d; |
195 |
|
disp[2] *= d; |
196 |
|
} |
197 |
< |
*xp = DOT(disp,v->hvec)/v->hn2 + 0.5 - v->hoff; |
199 |
< |
*yp = DOT(disp,v->vvec)/v->vn2 + 0.5 - v->voff; |
200 |
< |
return; |
197 |
> |
break; |
198 |
|
case VT_HEM: /* hemispherical fisheye */ |
199 |
|
d = normalize(disp); |
200 |
|
if (zp != NULL) { |
203 |
|
else |
204 |
|
*zp = d; |
205 |
|
} |
206 |
< |
*xp = DOT(disp,v->hvec)*90.0/v->horiz + 0.5 - v->hoff; |
210 |
< |
*yp = DOT(disp,v->vvec)*90.0/v->vert + 0.5 - v->voff; |
211 |
< |
return; |
206 |
> |
break; |
207 |
|
case VT_ANG: /* angular fisheye */ |
208 |
|
d = normalize(disp); |
209 |
|
if (zp != NULL) |
223 |
|
*yp += DOT(disp,v->vvec)*d*180.0/v->vert; |
224 |
|
return; |
225 |
|
} |
226 |
+ |
*xp = DOT(disp,v->hvec)/v->hn2 + 0.5 - v->hoff; |
227 |
+ |
*yp = DOT(disp,v->vvec)/v->vn2 + 0.5 - v->voff; |
228 |
|
} |
229 |
|
|
230 |
|
|
332 |
|
} |
333 |
|
|
334 |
|
|
338 |
– |
static VIEW *hview; /* view from header */ |
339 |
– |
static int gothview; /* success indicator */ |
335 |
|
static char *altname[] = {NULL,"rpict","rview","pinterp",VIEWSTR,NULL}; |
336 |
|
|
337 |
+ |
struct myview { |
338 |
+ |
VIEW *hv; |
339 |
+ |
int ok; |
340 |
+ |
}; |
341 |
|
|
342 |
+ |
|
343 |
|
static |
344 |
< |
gethview(s) /* get view from header */ |
344 |
> |
gethview(s, v) /* get view from header */ |
345 |
|
char *s; |
346 |
+ |
register struct myview *v; |
347 |
|
{ |
348 |
|
register char **an; |
349 |
|
|
350 |
|
for (an = altname; *an != NULL; an++) |
351 |
|
if (!strncmp(*an, s, strlen(*an))) { |
352 |
< |
if (sscanview(hview, s+strlen(*an)) > 0) |
353 |
< |
gothview++; |
352 |
> |
if (sscanview(v->hv, s+strlen(*an)) > 0) |
353 |
> |
v->ok++; |
354 |
|
return; |
355 |
|
} |
356 |
|
} |
363 |
|
int *xp, *yp; |
364 |
|
{ |
365 |
|
extern char *progname; |
366 |
+ |
struct myview mvs; |
367 |
|
FILE *fp; |
368 |
|
|
369 |
|
if ((fp = fopen(fname, "r")) == NULL) |
370 |
|
return(-1); |
371 |
|
|
372 |
|
altname[0] = progname; |
373 |
< |
hview = vp; |
374 |
< |
gothview = 0; |
373 |
> |
mvs.hv = vp; |
374 |
> |
mvs.ok = 0; |
375 |
|
|
376 |
< |
getheader(fp, gethview); |
376 |
> |
getheader(fp, gethview, &mvs); |
377 |
|
|
378 |
|
if (xp != NULL && yp != NULL |
379 |
|
&& fgetresolu(xp, yp, fp) == -1) |
380 |
< |
gothview = 0; |
380 |
> |
mvs.ok = 0; |
381 |
|
|
382 |
|
fclose(fp); |
383 |
|
|
384 |
< |
return(gothview); |
384 |
> |
return(mvs.ok); |
385 |
|
} |