ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/image.c
(Generate patch)

Comparing ray/src/common/image.c (file contents):
Revision 1.11 by greg, Fri Sep 21 17:06:31 1990 UTC vs.
Revision 1.12 by greg, Sat Oct 13 20:56:01 1990 UTC

# Line 21 | Line 21 | char *
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  
# Line 33 | Line 34 | register VIEW  *v;
34  
35          fcross(v->vvec, v->hvec, v->vdir);      /* compute vert dir */
36  
37 <        if (v->type == VT_PAR)
37 >        if (v->horiz <= FTINY)
38 >                return(ill_horiz);
39 >        if (v->vert <= FTINY)
40 >                return(ill_vert);
41 >
42 >        switch (v->type) {
43 >        case VT_PAR:                            /* parallel view */
44                  v->hn2 = v->horiz;
45 <        else if (v->type == VT_PER)
45 >                v->vn2 = v->vert;
46 >                break;
47 >        case VT_PER:                            /* perspective view */
48 >                if (v->horiz >= 180.0-FTINY)
49 >                        return(ill_horiz);
50 >                if (v->vert >= 180.0-FTINY)
51 >                        return(ill_vert);
52                  v->hn2 = 2.0 * tan(v->horiz*(PI/180.0/2.0));
53 <        else
53 >                v->vn2 = 2.0 * tan(v->vert*(PI/180.0/2.0));
54 >                break;
55 >        case VT_ANG:                            /* angular fisheye */
56 >                if (v->horiz > 360.0+FTINY)
57 >                        return(ill_horiz);
58 >                if (v->vert > 360.0+FTINY)
59 >                        return(ill_vert);
60 >                v->hn2 = v->horiz / 90.0;
61 >                v->vn2 = v->vert / 90.0;
62 >                break;
63 >        case VT_HEM:                            /* hemispherical fisheye */
64 >                if (v->horiz > 180.0+FTINY)
65 >                        return(ill_horiz);
66 >                if (v->vert > 180.0+FTINY)
67 >                        return(ill_vert);
68 >                v->hn2 = 2.0 * sin(v->horiz*(PI/180.0/2.0));
69 >                v->vn2 = 2.0 * sin(v->vert*(PI/180.0/2.0));
70 >                break;
71 >        default:
72                  return("unknown view type");
73 <
74 <        if (v->hn2 <= FTINY || v->hn2 >= FHUGE)
75 <                return("illegal horizontal view size");
76 <
77 <        v->hvec[0] *= v->hn2;
78 <        v->hvec[1] *= v->hn2;
79 <        v->hvec[2] *= v->hn2;
73 >        }
74 >        if (v->type == VT_PAR || v->type == VT_PER) {
75 >                v->hvec[0] *= v->hn2;
76 >                v->hvec[1] *= v->hn2;
77 >                v->hvec[2] *= v->hn2;
78 >                v->vvec[0] *= v->vn2;
79 >                v->vvec[1] *= v->vn2;
80 >                v->vvec[2] *= v->vn2;
81 >        }
82          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;
83          v->vn2 *= v->vn2;
84  
85          return(NULL);
# Line 84 | Line 105 | FVECT  orig, direc;
105   register VIEW  *v;
106   double  x, y;
107   {
108 +        double  d, z;
109 +        
110          x += v->hoff - 0.5;
111          y += v->voff - 0.5;
112  
113 <        if (v->type == VT_PAR) {        /* parallel view */
113 >        switch(v->type) {
114 >        case VT_PAR:                    /* parallel view */
115                  orig[0] = v->vp[0] + x*v->hvec[0] + y*v->vvec[0];
116                  orig[1] = v->vp[1] + x*v->hvec[1] + y*v->vvec[1];
117                  orig[2] = v->vp[2] + x*v->hvec[2] + y*v->vvec[2];
118                  VCOPY(direc, v->vdir);
119 <        } else {                        /* perspective view */
119 >                return(0);
120 >        case VT_PER:                    /* perspective view */
121                  VCOPY(orig, v->vp);
122                  direc[0] = v->vdir[0] + x*v->hvec[0] + y*v->vvec[0];
123                  direc[1] = v->vdir[1] + x*v->hvec[1] + y*v->vvec[1];
124                  direc[2] = v->vdir[2] + x*v->hvec[2] + y*v->vvec[2];
125                  normalize(direc);
126 +                return(0);
127 +        case VT_HEM:                    /* hemispherical fisheye */
128 +                x *= v->horiz/90.0;
129 +                y *= v->vert/90.0;
130 +                z = 1.0 - x*x - y*y;
131 +                if (z < 0.0)
132 +                        return(-1);
133 +                z = sqrt(z);
134 +                VCOPY(orig, v->vp);
135 +                direc[0] = z*v->vdir[0] + x*v->hvec[0] + y*v->vvec[0];
136 +                direc[1] = z*v->vdir[1] + x*v->hvec[1] + y*v->vvec[1];
137 +                direc[2] = z*v->vdir[2] + x*v->hvec[2] + y*v->vvec[2];
138 +                return(0);
139 +        case VT_ANG:                    /* angular fisheye */
140 +                x *= v->horiz/180.0;
141 +                y *= v->vert/180.0;
142 +                d = x*x + y*y;
143 +                if (d > 1.0)
144 +                        return(-1);
145 +                VCOPY(orig, v->vp);
146 +                if (d <= FTINY) {
147 +                        VCOPY(direc, v->vdir);
148 +                        return(0);
149 +                }
150 +                d = sqrt(d);
151 +                z = cos(PI*d);
152 +                d = sqrt(1 - z*z)/d;
153 +                x *= d;
154 +                y *= d;
155 +                direc[0] = z*v->vdir[0] + x*v->hvec[0] + y*v->vvec[0];
156 +                direc[1] = z*v->vdir[1] + x*v->hvec[1] + y*v->vvec[1];
157 +                direc[2] = z*v->vdir[2] + x*v->hvec[2] + y*v->vvec[2];
158 +                return(0);
159          }
160 +        return(-1);
161   }
162  
163  
# Line 107 | Line 166 | double  *xp, *yp, *zp;
166   register VIEW  *v;
167   FVECT  p;
168   {
110        extern double  sqrt();
169          double  d;
170          FVECT  disp;
171  
# Line 115 | Line 173 | FVECT  p;
173          disp[1] = p[1] - v->vp[1];
174          disp[2] = p[2] - v->vp[2];
175  
176 <        if (v->type == VT_PAR) {        /* parallel view */
176 >        switch (v->type) {
177 >        case VT_PAR:                    /* parallel view */
178                  if (zp != NULL)
179                          *zp = DOT(disp,v->vdir);
180 <        } else {                        /* perspective view */
180 >                *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;
183 >        case VT_PER:                    /* perspective view */
184                  d = DOT(disp,v->vdir);
185                  if (zp != NULL) {
186                          *zp = sqrt(DOT(disp,disp));
# Line 133 | Line 195 | FVECT  p;
195                          disp[1] *= d;
196                          disp[2] *= d;
197                  }
198 +                *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;
201 +        case VT_HEM:                    /* hemispherical fisheye */
202 +                d = normalize(disp);
203 +                if (zp != NULL) {
204 +                        if (DOT(disp,v->vdir) < 0.0)
205 +                                *zp = -d;
206 +                        else
207 +                                *zp = d;
208 +                }
209 +                *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;
212 +        case VT_ANG:                    /* angular fisheye */
213 +                d = normalize(disp);
214 +                if (zp != NULL)
215 +                        *zp = d;
216 +                *xp = 0.5 - v->hoff;
217 +                *yp = 0.5 - v->voff;
218 +                d = DOT(disp,v->vdir);
219 +                if (d >= 1.0-FTINY)
220 +                        return;
221 +                if (d <= -(1.0-FTINY)) {
222 +                        *xp += 180.0/v->horiz;
223 +                        *yp += 180.0/v->vert;
224 +                        return;
225 +                }
226 +                d = acos(d)/PI / sqrt(1.0 - d*d);
227 +                *xp += DOT(disp,v->hvec)*d*180.0/v->horiz;
228 +                *yp += DOT(disp,v->vvec)*d*180.0/v->vert;
229 +                return;
230          }
137        *xp = DOT(disp,v->hvec)/v->hn2 + 0.5 - v->hoff;
138        *yp = DOT(disp,v->vvec)/v->vn2 + 0.5 - v->voff;
231   }
232  
233  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines