21 |
|
setview(v) /* set hvec and vvec, return message on error */ |
22 |
|
register VIEW *v; |
23 |
|
{ |
24 |
< |
extern double tan(), normalize(); |
25 |
< |
|
24 |
> |
static char ill_horiz[] = "illegal horizontal view size"; |
25 |
> |
static char ill_vert[] = "illegal vertical view size"; |
26 |
> |
|
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 |
|
|
40 |
< |
if (v->type == VT_PAR) |
40 |
> |
if (v->horiz <= FTINY) |
41 |
> |
return(ill_horiz); |
42 |
> |
if (v->vert <= FTINY) |
43 |
> |
return(ill_vert); |
44 |
> |
|
45 |
> |
switch (v->type) { |
46 |
> |
case VT_PAR: /* parallel view */ |
47 |
|
v->hn2 = v->horiz; |
48 |
< |
else if (v->type == VT_PER) |
48 |
> |
v->vn2 = v->vert; |
49 |
> |
break; |
50 |
> |
case VT_PER: /* perspective view */ |
51 |
> |
if (v->horiz >= 180.0-FTINY) |
52 |
> |
return(ill_horiz); |
53 |
> |
if (v->vert >= 180.0-FTINY) |
54 |
> |
return(ill_vert); |
55 |
|
v->hn2 = 2.0 * tan(v->horiz*(PI/180.0/2.0)); |
56 |
< |
else |
56 |
> |
v->vn2 = 2.0 * tan(v->vert*(PI/180.0/2.0)); |
57 |
> |
break; |
58 |
> |
case VT_ANG: /* angular fisheye */ |
59 |
> |
if (v->horiz > 360.0+FTINY) |
60 |
> |
return(ill_horiz); |
61 |
> |
if (v->vert > 360.0+FTINY) |
62 |
> |
return(ill_vert); |
63 |
> |
v->hn2 = v->horiz / 90.0; |
64 |
> |
v->vn2 = v->vert / 90.0; |
65 |
> |
break; |
66 |
> |
case VT_HEM: /* hemispherical fisheye */ |
67 |
> |
if (v->horiz > 180.0+FTINY) |
68 |
> |
return(ill_horiz); |
69 |
> |
if (v->vert > 180.0+FTINY) |
70 |
> |
return(ill_vert); |
71 |
> |
v->hn2 = 2.0 * sin(v->horiz*(PI/180.0/2.0)); |
72 |
> |
v->vn2 = 2.0 * sin(v->vert*(PI/180.0/2.0)); |
73 |
> |
break; |
74 |
> |
default: |
75 |
|
return("unknown view type"); |
76 |
< |
|
77 |
< |
if (v->hn2 <= FTINY || v->hn2 >= FHUGE) |
78 |
< |
return("illegal horizontal view size"); |
79 |
< |
|
80 |
< |
v->hvec[0] *= v->hn2; |
81 |
< |
v->hvec[1] *= v->hn2; |
82 |
< |
v->hvec[2] *= v->hn2; |
76 |
> |
} |
77 |
> |
if (v->type != VT_ANG) { |
78 |
> |
v->hvec[0] *= v->hn2; |
79 |
> |
v->hvec[1] *= v->hn2; |
80 |
> |
v->hvec[2] *= v->hn2; |
81 |
> |
v->vvec[0] *= v->vn2; |
82 |
> |
v->vvec[1] *= v->vn2; |
83 |
> |
v->vvec[2] *= v->vn2; |
84 |
> |
} |
85 |
|
v->hn2 *= v->hn2; |
50 |
– |
|
51 |
– |
if (v->type == VT_PAR) |
52 |
– |
v->vn2 = v->vert; |
53 |
– |
else |
54 |
– |
v->vn2 = 2.0 * tan(v->vert*(PI/180.0/2.0)); |
55 |
– |
|
56 |
– |
if (v->vn2 <= FTINY || v->vn2 >= FHUGE) |
57 |
– |
return("illegal vertical view size"); |
58 |
– |
|
59 |
– |
v->vvec[0] *= v->vn2; |
60 |
– |
v->vvec[1] *= v->vn2; |
61 |
– |
v->vvec[2] *= v->vn2; |
86 |
|
v->vn2 *= v->vn2; |
87 |
|
|
88 |
|
return(NULL); |
108 |
|
register VIEW *v; |
109 |
|
double x, y; |
110 |
|
{ |
111 |
+ |
double d, z; |
112 |
+ |
|
113 |
|
x += v->hoff - 0.5; |
114 |
|
y += v->voff - 0.5; |
115 |
|
|
116 |
< |
if (v->type == VT_PAR) { /* parallel view */ |
116 |
> |
switch(v->type) { |
117 |
> |
case VT_PAR: /* parallel view */ |
118 |
|
orig[0] = v->vp[0] + x*v->hvec[0] + y*v->vvec[0]; |
119 |
|
orig[1] = v->vp[1] + x*v->hvec[1] + y*v->vvec[1]; |
120 |
|
orig[2] = v->vp[2] + x*v->hvec[2] + y*v->vvec[2]; |
121 |
|
VCOPY(direc, v->vdir); |
122 |
< |
} else { /* perspective view */ |
122 |
> |
return(0); |
123 |
> |
case VT_PER: /* perspective view */ |
124 |
|
VCOPY(orig, v->vp); |
125 |
|
direc[0] = v->vdir[0] + x*v->hvec[0] + y*v->vvec[0]; |
126 |
|
direc[1] = v->vdir[1] + x*v->hvec[1] + y*v->vvec[1]; |
127 |
|
direc[2] = v->vdir[2] + x*v->hvec[2] + y*v->vvec[2]; |
128 |
|
normalize(direc); |
129 |
+ |
return(0); |
130 |
+ |
case VT_HEM: /* hemispherical fisheye */ |
131 |
+ |
z = 1.0 - x*x*v->hn2 - y*y*v->vn2; |
132 |
+ |
if (z < 0.0) |
133 |
+ |
return(-1); |
134 |
+ |
z = sqrt(z); |
135 |
+ |
VCOPY(orig, v->vp); |
136 |
+ |
direc[0] = z*v->vdir[0] + x*v->hvec[0] + y*v->vvec[0]; |
137 |
+ |
direc[1] = z*v->vdir[1] + x*v->hvec[1] + y*v->vvec[1]; |
138 |
+ |
direc[2] = z*v->vdir[2] + x*v->hvec[2] + y*v->vvec[2]; |
139 |
+ |
return(0); |
140 |
+ |
case VT_ANG: /* angular fisheye */ |
141 |
+ |
x *= v->horiz/180.0; |
142 |
+ |
y *= v->vert/180.0; |
143 |
+ |
d = x*x + y*y; |
144 |
+ |
if (d > 1.0) |
145 |
+ |
return(-1); |
146 |
+ |
VCOPY(orig, v->vp); |
147 |
+ |
if (d <= FTINY) { |
148 |
+ |
VCOPY(direc, v->vdir); |
149 |
+ |
return(0); |
150 |
+ |
} |
151 |
+ |
d = sqrt(d); |
152 |
+ |
z = cos(PI*d); |
153 |
+ |
d = sqrt(1 - z*z)/d; |
154 |
+ |
x *= d; |
155 |
+ |
y *= d; |
156 |
+ |
direc[0] = z*v->vdir[0] + x*v->hvec[0] + y*v->vvec[0]; |
157 |
+ |
direc[1] = z*v->vdir[1] + x*v->hvec[1] + y*v->vvec[1]; |
158 |
+ |
direc[2] = z*v->vdir[2] + x*v->hvec[2] + y*v->vvec[2]; |
159 |
+ |
return(0); |
160 |
|
} |
161 |
+ |
return(-1); |
162 |
|
} |
163 |
|
|
164 |
|
|
167 |
|
register VIEW *v; |
168 |
|
FVECT p; |
169 |
|
{ |
110 |
– |
extern double sqrt(); |
170 |
|
double d; |
171 |
|
FVECT disp; |
172 |
|
|
174 |
|
disp[1] = p[1] - v->vp[1]; |
175 |
|
disp[2] = p[2] - v->vp[2]; |
176 |
|
|
177 |
< |
if (v->type == VT_PAR) { /* parallel view */ |
177 |
> |
switch (v->type) { |
178 |
> |
case VT_PAR: /* parallel view */ |
179 |
|
if (zp != NULL) |
180 |
|
*zp = DOT(disp,v->vdir); |
181 |
< |
} else { /* perspective view */ |
181 |
> |
break; |
182 |
> |
case VT_PER: /* perspective view */ |
183 |
|
d = DOT(disp,v->vdir); |
184 |
|
if (zp != NULL) { |
185 |
|
*zp = sqrt(DOT(disp,disp)); |
194 |
|
disp[1] *= d; |
195 |
|
disp[2] *= d; |
196 |
|
} |
197 |
+ |
break; |
198 |
+ |
case VT_HEM: /* hemispherical fisheye */ |
199 |
+ |
d = normalize(disp); |
200 |
+ |
if (zp != NULL) { |
201 |
+ |
if (DOT(disp,v->vdir) < 0.0) |
202 |
+ |
*zp = -d; |
203 |
+ |
else |
204 |
+ |
*zp = d; |
205 |
+ |
} |
206 |
+ |
break; |
207 |
+ |
case VT_ANG: /* angular fisheye */ |
208 |
+ |
d = normalize(disp); |
209 |
+ |
if (zp != NULL) |
210 |
+ |
*zp = d; |
211 |
+ |
*xp = 0.5 - v->hoff; |
212 |
+ |
*yp = 0.5 - v->voff; |
213 |
+ |
d = DOT(disp,v->vdir); |
214 |
+ |
if (d >= 1.0-FTINY) |
215 |
+ |
return; |
216 |
+ |
if (d <= -(1.0-FTINY)) { |
217 |
+ |
*xp += 180.0/v->horiz; |
218 |
+ |
*yp += 180.0/v->vert; |
219 |
+ |
return; |
220 |
+ |
} |
221 |
+ |
d = acos(d)/PI / sqrt(1.0 - d*d); |
222 |
+ |
*xp += DOT(disp,v->hvec)*d*180.0/v->horiz; |
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; |
332 |
|
} |
333 |
|
|
334 |
|
|
246 |
– |
static VIEW *hview; /* view from header */ |
247 |
– |
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 |
|
} |