]> git.mxchange.org Git - flightgear.git/blob - src/Main/views.cxx
More ssg tweaks.
[flightgear.git] / src / Main / views.cxx
1 // views.cxx -- data structures and routines for managing and view
2 //               parameters.
3 //
4 // Written by Curtis Olson, started August 1997.
5 //
6 // Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
7 //
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 // General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 //
22 // $Id$
23
24
25 #ifdef HAVE_CONFIG_H
26 #  include <config.h>
27 #endif
28
29 #include <ssg.h>                // plib include
30
31 #include <Aircraft/aircraft.hxx>
32 #include <Cockpit/panel.hxx>
33 #include <Debug/logstream.hxx>
34 #include <Include/fg_constants.h>
35 #include <Math/mat3.h>
36 #include <Math/point3d.hxx>
37 #include <Math/polar3d.hxx>
38 #include <Math/vector.hxx>
39 #include <Scenery/scenery.hxx>
40 #include <Time/fg_time.hxx>
41
42 #include "options.hxx"
43 #include "views.hxx"
44
45
46 // Define following to extract various vectors directly
47 // from matrices we have allready computed
48 // rather then performing 'textbook algebra' to rederive them
49 // Norman Vine -- nhv@yahoo.com
50 // #define FG_VIEW_INLINE_OPTIMIZATIONS
51
52 // temporary (hopefully) hack
53 static int panel_hist = 0;
54
55
56 // specify code paths ... these are done as variable rather than
57 // #define's because down the road we may want to choose between them
58 // on the fly for different flight models ... this way magic carpet
59 // and external modes wouldn't need to recreate the LaRCsim matrices
60 // themselves.
61
62 static const bool use_larcsim_local_to_body = false;
63
64
65 // This is a record containing current view parameters
66 FGView current_view;
67
68
69 // Constructor
70 FGView::FGView( void ) {
71     MAT3identity(WORLD);
72 }
73
74
75 // Initialize a view structure
76 void FGView::Init( void ) {
77     FG_LOG( FG_VIEW, FG_INFO, "Initializing View parameters" );
78
79     view_offset = 0.0;
80     goal_view_offset = 0.0;
81
82     winWidth = current_options.get_xsize();
83     winHeight = current_options.get_ysize();
84
85     if ( ! current_options.get_panel_status() ) {
86         current_view.set_win_ratio( (GLfloat) winWidth / (GLfloat) winHeight );
87     } else {
88         current_view.set_win_ratio( (GLfloat) winWidth / 
89                                     ((GLfloat) (winHeight)*0.4232) );
90     }
91
92     force_update_fov_math();
93 }
94
95
96 // Update the field of view coefficients
97 void FGView::UpdateFOV( const fgOPTIONS& o ) {
98     ssgSetFOV( o.get_fov(), 0.0 );
99
100     double fov, theta_x, theta_y;
101
102     fov = o.get_fov();
103         
104     // printf("win_ratio = %.2f\n", win_ratio);
105     // calculate sin() and cos() of fov / 2 in X direction;
106     theta_x = (fov * win_ratio * DEG_TO_RAD) / 2.0;
107     // printf("theta_x = %.2f\n", theta_x);
108     sin_fov_x = sin(theta_x);
109     cos_fov_x = cos(theta_x);
110     slope_x =  -cos_fov_x / sin_fov_x;
111     // printf("slope_x = %.2f\n", slope_x);
112
113     // fov_x_clip and fov_y_clip convoluted algebraic simplification
114     // see code executed in tilemgr.cxx when USE_FAST_FOV_CLIP not
115     // defined Norman Vine -- nhv@yahoo.com
116 #if defined( USE_FAST_FOV_CLIP )
117     fov_x_clip = slope_x*cos_fov_x - sin_fov_x;
118 #endif // defined( USE_FAST_FOV_CLIP )
119
120     // calculate sin() and cos() of fov / 2 in Y direction;
121     theta_y = (fov * DEG_TO_RAD) / 2.0;
122     // printf("theta_y = %.2f\n", theta_y);
123     sin_fov_y = sin(theta_y);
124     cos_fov_y = cos(theta_y);
125     slope_y = cos_fov_y / sin_fov_y;
126     // printf("slope_y = %.2f\n", slope_y);
127
128 #if defined( USE_FAST_FOV_CLIP )
129     fov_y_clip = -(slope_y*cos_fov_y + sin_fov_y);      
130 #endif // defined( USE_FAST_FOV_CLIP )
131 }
132
133
134 // Basically, this is a modified version of the Mesa gluLookAt()
135 // function that's been modified slightly so we can capture the
136 // result before sending it off to OpenGL land.
137 void FGView::LookAt( GLdouble eyex, GLdouble eyey, GLdouble eyez,
138                      GLdouble centerx, GLdouble centery, GLdouble centerz,
139                      GLdouble upx, GLdouble upy, GLdouble upz ) {
140     GLfloat *m;
141     GLdouble x[3], y[3], z[3];
142     GLdouble mag;
143
144     m = current_view.MODEL_VIEW;
145
146     /* Make rotation matrix */
147
148     /* Z vector */
149     z[0] = eyex - centerx;
150     z[1] = eyey - centery;
151     z[2] = eyez - centerz;
152     mag = sqrt( z[0]*z[0] + z[1]*z[1] + z[2]*z[2] );
153     if (mag) {  /* mpichler, 19950515 */
154         z[0] /= mag;
155         z[1] /= mag;
156         z[2] /= mag;
157     }
158
159     /* Y vector */
160     y[0] = upx;
161     y[1] = upy;
162     y[2] = upz;
163
164     /* X vector = Y cross Z */
165     x[0] =  y[1]*z[2] - y[2]*z[1];
166     x[1] = -y[0]*z[2] + y[2]*z[0];
167     x[2] =  y[0]*z[1] - y[1]*z[0];
168     
169     /* Recompute Y = Z cross X */
170     y[0] =  z[1]*x[2] - z[2]*x[1];
171     y[1] = -z[0]*x[2] + z[2]*x[0];
172     y[2] =  z[0]*x[1] - z[1]*x[0];
173
174     /* mpichler, 19950515 */
175     /* cross product gives area of parallelogram, which is < 1.0 for
176      * non-perpendicular unit-length vectors; so normalize x, y here
177      */
178
179     mag = sqrt( x[0]*x[0] + x[1]*x[1] + x[2]*x[2] );
180     if (mag) {
181         x[0] /= mag;
182         x[1] /= mag;
183         x[2] /= mag;
184     }
185
186     mag = sqrt( y[0]*y[0] + y[1]*y[1] + y[2]*y[2] );
187     if (mag) {
188         y[0] /= mag;
189         y[1] /= mag;
190         y[2] /= mag;
191     }
192
193 #define M(row,col)  m[col*4+row]
194     M(0,0) = x[0];  M(0,1) = x[1];  M(0,2) = x[2];  M(0,3) = 0.0;
195     M(1,0) = y[0];  M(1,1) = y[1];  M(1,2) = y[2];  M(1,3) = 0.0;
196     M(2,0) = z[0];  M(2,1) = z[1];  M(2,2) = z[2];  M(2,3) = 0.0;
197     // the following is part of the original gluLookAt(), but we are
198     // commenting it out because we know we are going to be doing a
199     // translation below which will set these values anyways
200     // M(3,0) = 0.0;   M(3,1) = 0.0;   M(3,2) = 0.0;   M(3,3) = 1.0;
201 #undef M
202
203     // Translate Eye to Origin
204     // replaces: glTranslated( -eyex, -eyey, -eyez );
205
206     // this has been slightly modified from the original glTranslate()
207     // code because we know that coming into this m[12] = m[13] =
208     // m[14] = 0.0, and m[15] = 1.0;
209     m[12] = m[0] * -eyex + m[4] * -eyey + m[8]  * -eyez /* + m[12] */;
210     m[13] = m[1] * -eyex + m[5] * -eyey + m[9]  * -eyez /* + m[13] */;
211     m[14] = m[2] * -eyex + m[6] * -eyey + m[10] * -eyez /* + m[14] */;
212     m[15] = 1.0 /* m[3] * -eyex + m[7] * -eyey + m[11] * -eyez + m[15] */;
213
214     // xglMultMatrixd( m );
215     xglLoadMatrixf( m );
216 }
217
218
219 // Update the view volume, position, and orientation
220 void FGView::UpdateViewParams( void ) {
221     FGInterface *f = current_aircraft.fdm_state;
222
223     UpdateViewMath(f);
224     UpdateWorldToEye(f);
225     
226     if ((current_options.get_panel_status() != panel_hist) &&                          (current_options.get_panel_status()))
227     {
228         FGPanel::OurPanel->ReInit( 0, 0, 1024, 768);
229     }
230
231     if ( ! current_options.get_panel_status() ) {
232         xglViewport(0, 0 , (GLint)(winWidth), (GLint)(winHeight) );
233     } else {
234         xglViewport(0, (GLint)((winHeight)*0.5768), (GLint)(winWidth), 
235                     (GLint)((winHeight)*0.4232) );
236     }
237
238     // Tell GL we are about to modify the projection parameters
239     xglMatrixMode(GL_PROJECTION);
240     xglLoadIdentity();
241     if ( f->get_Altitude() * FEET_TO_METER - scenery.cur_elev > 10.0 ) {
242         // ssgSetNearFar( 10.0, 100000.0 );
243         gluPerspective(current_options.get_fov(), win_ratio, 10.0, 100000.0);
244     } else {
245         // ssgSetNearFar( 0.5, 100000.0 );
246         gluPerspective(current_options.get_fov(), win_ratio, 0.5, 100000.0);
247         // printf("Near ground, minimizing near clip plane\n");
248     }
249     // }
250
251     xglMatrixMode(GL_MODELVIEW);
252     xglLoadIdentity();
253
254     // set up our view volume (default)
255 #if !defined(FG_VIEW_INLINE_OPTIMIZATIONS)
256     LookAt(view_pos.x(), view_pos.y(), view_pos.z(),
257            view_pos.x() + view_forward[0], 
258            view_pos.y() + view_forward[1], 
259            view_pos.z() + view_forward[2],
260            view_up[0], view_up[1], view_up[2]);
261
262     // look almost straight up (testing and eclipse watching)
263     /* LookAt(view_pos.x(), view_pos.y(), view_pos.z(),
264        view_pos.x() + view_up[0] + .001, 
265        view_pos.y() + view_up[1] + .001, 
266        view_pos.z() + view_up[2] + .001,
267        view_up[0], view_up[1], view_up[2]); */
268
269     // lock view horizontally towards sun (testing)
270     /* LookAt(view_pos.x(), view_pos.y(), view_pos.z(),
271        view_pos.x() + surface_to_sun[0], 
272        view_pos.y() + surface_to_sun[1], 
273        view_pos.z() + surface_to_sun[2],
274        view_up[0], view_up[1], view_up[2]); */
275
276     // lock view horizontally towards south (testing)
277     /* LookAt(view_pos.x(), view_pos.y(), view_pos.z(),
278        view_pos.x() + surface_south[0], 
279        view_pos.y() + surface_south[1], 
280        view_pos.z() + surface_south[2],
281        view_up[0], view_up[1], view_up[2]); */
282
283 #else // defined(FG_VIEW_INLINE_OPTIMIZATIONS)
284     //void FGView::LookAt( GLdouble eyex, GLdouble eyey, GLdouble eyez,
285     //               GLdouble centerx, GLdouble centery, GLdouble centerz,
286     //               GLdouble upx, GLdouble upy, GLdouble upz )
287     {
288         GLfloat *m;
289         GLdouble x[3], y[3], z[3];
290         //    GLdouble mag;
291
292         m = current_view.MODEL_VIEW;
293
294         /* Make rotation matrix */
295
296         /* Z vector */
297         z[0] = -view_forward[0]; //eyex - centerx;
298         z[1] = -view_forward[1]; //eyey - centery;
299         z[2] = -view_forward[2]; //eyez - centerz;
300         
301         // In our case this is a unit vector  NHV
302         
303         //    mag = sqrt( z[0]*z[0] + z[1]*z[1] + z[2]*z[2] );
304         //    if (mag) {  /* mpichler, 19950515 */
305         //              mag = 1.0/mag;
306         //              printf("mag(%f)  ", mag);
307         //      z[0] *= mag;
308         //      z[1] *= mag;
309         //      z[2] *= mag;
310         //    }
311
312         /* Y vector */
313         y[0] = view_up[0]; //upx;
314         y[1] = view_up[1]; //upy;
315         y[2] = view_up[2]; //upz;
316
317         /* X vector = Y cross Z */
318         x[0] =  y[1]*z[2] - y[2]*z[1];
319         x[1] = -y[0]*z[2] + y[2]*z[0];
320         x[2] =  y[0]*z[1] - y[1]*z[0];
321
322         //      printf(" %f %f %f  ", y[0], y[1], y[2]);
323     
324         /* Recompute Y = Z cross X */
325         //    y[0] =  z[1]*x[2] - z[2]*x[1];
326         //    y[1] = -z[0]*x[2] + z[2]*x[0];
327         //    y[2] =  z[0]*x[1] - z[1]*x[0];
328
329         //      printf(" %f %f %f\n", y[0], y[1], y[2]);
330         
331         // In our case these are unit vectors  NHV
332
333         /* mpichler, 19950515 */
334         /* cross product gives area of parallelogram, which is < 1.0 for
335          * non-perpendicular unit-length vectors; so normalize x, y here
336          */
337
338         //    mag = sqrt( x[0]*x[0] + x[1]*x[1] + x[2]*x[2] );
339         //    if (mag) {
340         //              mag = 1.0/mag;
341         //              printf("mag2(%f) ", mag);
342         //      x[0] *= mag;
343         //      x[1] *= mag;
344         //      x[2] *= mag;
345         //    }
346
347         //    mag = sqrt( y[0]*y[0] + y[1]*y[1] + y[2]*y[2] );
348         //    if (mag) {
349         //              mag = 1.0/mag;
350         //              printf("mag3(%f)\n", mag);
351         //      y[0] *= mag;
352         //      y[1] *= mag;
353         //      y[2] *= mag;
354         //    }
355
356 #define M(row,col)  m[col*4+row]
357         M(0,0) = x[0];  M(0,1) = x[1];  M(0,2) = x[2];  M(0,3) = 0.0;
358         M(1,0) = y[0];  M(1,1) = y[1];  M(1,2) = y[2];  M(1,3) = 0.0;
359         M(2,0) = z[0];  M(2,1) = z[1];  M(2,2) = z[2];  M(2,3) = 0.0;
360         // the following is part of the original gluLookAt(), but we are
361         // commenting it out because we know we are going to be doing a
362         // translation below which will set these values anyways
363         // M(3,0) = 0.0;   M(3,1) = 0.0;   M(3,2) = 0.0;   M(3,3) = 1.0;
364 #undef M
365
366         // Translate Eye to Origin
367         // replaces: glTranslated( -eyex, -eyey, -eyez );
368
369         // this has been slightly modified from the original glTranslate()
370         // code because we know that coming into this m[12] = m[13] =
371         // m[14] = 0.0, and m[15] = 1.0;
372         m[12] = m[0] * -view_pos.x() + m[4] * -view_pos.y() + m[8]  * -view_pos.z() /* + m[12] */;
373         m[13] = m[1] * -view_pos.x() + m[5] * -view_pos.y() + m[9]  * -view_pos.z() /* + m[13] */;
374         m[14] = m[2] * -view_pos.x() + m[6] * -view_pos.y() + m[10] * -view_pos.z() /* + m[14] */;
375         m[15] = 1.0 /* m[3] * -view_pos.x() + m[7] * -view_pos.y() + m[11] * -view_pos.z() + m[15] */;
376
377         // xglMultMatrixd( m );
378         xglLoadMatrixf( m );
379     }
380 #endif // FG_VIEW_INLINE_OPTIMIZATIONS
381
382     panel_hist = current_options.get_panel_status();
383 }
384
385
386 void getRotMatrix(double* out, MAT3vec vec, double radians)
387 {
388     /* This function contributed by Erich Boleyn (erich@uruk.org) */
389     /* This function used from the Mesa OpenGL code (matrix.c)  */
390     double s, c; // mag,
391     double vx, vy, vz, xy, yz, zx, xs, ys, zs, one_c; //, xx, yy, zz
392   
393     MAT3identity(out);
394     s = sin(radians);
395     c = cos(radians);
396   
397     //  mag = getMagnitude();
398   
399     vx = vec[0];
400     vy = vec[1];
401     vz = vec[2];
402   
403 #define M(row,col)  out[row*4 + col]
404   
405     /*
406      *     Arbitrary axis rotation matrix.
407      *
408      *  This is composed of 5 matrices, Rz, Ry, T, Ry', Rz', multiplied
409      *  like so:  Rz * Ry * T * Ry' * Rz'.  T is the final rotation
410      *  (which is about the X-axis), and the two composite transforms
411      *  Ry' * Rz' and Rz * Ry are (respectively) the rotations necessary
412      *  from the arbitrary axis to the X-axis then back.  They are
413      *  all elementary rotations.
414      *
415      *  Rz' is a rotation about the Z-axis, to bring the axis vector
416      *  into the x-z plane.  Then Ry' is applied, rotating about the
417      *  Y-axis to bring the axis vector parallel with the X-axis.  The
418      *  rotation about the X-axis is then performed.  Ry and Rz are
419      *  simply the respective inverse transforms to bring the arbitrary
420      *  axis back to it's original orientation.  The first transforms
421      *  Rz' and Ry' are considered inverses, since the data from the
422      *  arbitrary axis gives you info on how to get to it, not how
423      *  to get away from it, and an inverse must be applied.
424      *
425      *  The basic calculation used is to recognize that the arbitrary
426      *  axis vector (x, y, z), since it is of unit length, actually
427      *  represents the sines and cosines of the angles to rotate the
428      *  X-axis to the same orientation, with theta being the angle about
429      *  Z and phi the angle about Y (in the order described above)
430      *  as follows:
431      *
432      *  cos ( theta ) = x / sqrt ( 1 - z^2 )
433      *  sin ( theta ) = y / sqrt ( 1 - z^2 )
434      *
435      *  cos ( phi ) = sqrt ( 1 - z^2 )
436      *  sin ( phi ) = z
437      *
438      *  Note that cos ( phi ) can further be inserted to the above
439      *  formulas:
440      *
441      *  cos ( theta ) = x / cos ( phi )
442      *  sin ( theta ) = y / cos ( phi )
443      *
444      *  ...etc.  Because of those relations and the standard trigonometric
445      *  relations, it is pssible to reduce the transforms down to what
446      *  is used below.  It may be that any primary axis chosen will give the
447      *  same results (modulo a sign convention) using thie method.
448      *
449      *  Particularly nice is to notice that all divisions that might
450      *  have caused trouble when parallel to certain planes or
451      *  axis go away with care paid to reducing the expressions.
452      *  After checking, it does perform correctly under all cases, since
453      *  in all the cases of division where the denominator would have
454      *  been zero, the numerator would have been zero as well, giving
455      *  the expected result.
456      */
457     
458     one_c = 1.0F - c;
459     
460     //  xx = vx * vx;
461     //  yy = vy * vy;
462     //  zz = vz * vz;
463   
464     //  xy = vx * vy;
465     //  yz = vy * vz;
466     //  zx = vz * vx;
467   
468   
469     M(0,0) = (one_c * vx * vx) + c;  
470     xs = vx * s;
471     yz = vy * vz * one_c;
472     M(1,2) = yz + xs;
473     M(2,1) = yz - xs;
474
475     M(1,1) = (one_c * vy * vy) + c;
476     ys = vy * s;
477     zx = vz * vx * one_c;
478     M(0,2) = zx - ys;
479     M(2,0) = zx + ys;
480   
481     M(2,2) = (one_c * vz *vz) + c;
482     zs = vz * s;
483     xy = vx * vy * one_c;
484     M(0,1) = xy + zs;
485     M(1,0) = xy - zs;
486   
487     //  M(0,0) = (one_c * xx) + c;
488     //  M(1,0) = (one_c * xy) - zs;
489     //  M(2,0) = (one_c * zx) + ys;
490   
491     //  M(0,1) = (one_c * xy) + zs;
492     //  M(1,1) = (one_c * yy) + c;
493     //  M(2,1) = (one_c * yz) - xs;
494   
495     //  M(0,2) = (one_c * zx) - ys;
496     //  M(1,2) = (one_c * yz) + xs;
497     //  M(2,2) = (one_c * zz) + c;
498   
499 #undef M
500 }
501
502
503 // Update the view parameters
504 void FGView::UpdateViewMath( FGInterface *f ) {
505     Point3D p;
506     MAT3vec vec, forward, v0, minus_z;
507     MAT3mat R, TMP, UP, LOCAL, VIEW;
508     double ntmp;
509
510     if ( update_fov ) {
511         // printf("Updating fov\n");
512         UpdateFOV( current_options );
513         update_fov = false;
514     }
515                 
516     scenery.center = scenery.next_center;
517
518 #if !defined(FG_VIEW_INLINE_OPTIMIZATIONS)
519     // printf("scenery center = %.2f %.2f %.2f\n", scenery.center.x,
520     //        scenery.center.y, scenery.center.z);
521
522     // calculate the cartesion coords of the current lat/lon/0 elev
523     p = Point3D( f->get_Longitude(), 
524                  f->get_Lat_geocentric(), 
525                  f->get_Sea_level_radius() * FEET_TO_METER );
526
527     cur_zero_elev = fgPolarToCart3d(p) - scenery.center;
528
529     // calculate view position in current FG view coordinate system
530     // p.lon & p.lat are already defined earlier, p.radius was set to
531     // the sea level radius, so now we add in our altitude.
532     if ( f->get_Altitude() * FEET_TO_METER > 
533          (scenery.cur_elev + 0.5 * METER_TO_FEET) ) {
534         p.setz( p.radius() + f->get_Altitude() * FEET_TO_METER );
535     } else {
536         p.setz( p.radius() + scenery.cur_elev + 0.5 * METER_TO_FEET );
537     }
538
539     abs_view_pos = fgPolarToCart3d(p);
540         
541 #else // FG_VIEW_INLINE_OPTIMIZATIONS
542         
543     double tmp_radius = f->get_Sea_level_radius() * FEET_TO_METER;
544     double tmp = f->get_cos_lat_geocentric() * tmp_radius;
545         
546     cur_zero_elev.setx(f->get_cos_longitude()*tmp - scenery.center.x());
547     cur_zero_elev.sety(f->get_sin_longitude()*tmp - scenery.center.y());
548     cur_zero_elev.setz(f->get_sin_lat_geocentric()*tmp_radius - scenery.center.z());
549
550     // calculate view position in current FG view coordinate system
551     // p.lon & p.lat are already defined earlier, p.radius was set to
552     // the sea level radius, so now we add in our altitude.
553     if ( f->get_Altitude() * FEET_TO_METER > 
554          (scenery.cur_elev + 0.5 * METER_TO_FEET) ) {
555         tmp_radius += f->get_Altitude() * FEET_TO_METER;
556     } else {
557         tmp_radius += scenery.cur_elev + 0.5 * METER_TO_FEET ;
558     }
559     tmp = f->get_cos_lat_geocentric() * tmp_radius;
560     abs_view_pos.setx(f->get_cos_longitude()*tmp);
561     abs_view_pos.sety(f->get_sin_longitude()*tmp);
562     abs_view_pos.setz(f->get_sin_lat_geocentric()*tmp_radius);
563         
564 #endif // FG_VIEW_INLINE_OPTIMIZATIONS
565         
566     view_pos = abs_view_pos - scenery.center;
567
568     FG_LOG( FG_VIEW, FG_DEBUG, "Polar view pos = " << p );
569     FG_LOG( FG_VIEW, FG_DEBUG, "Absolute view pos = " << abs_view_pos );
570     FG_LOG( FG_VIEW, FG_DEBUG, "Relative view pos = " << view_pos );
571
572     // Derive the LOCAL aircraft rotation matrix (roll, pitch, yaw)
573     // from FG_T_local_to_body[3][3]
574
575     if ( use_larcsim_local_to_body ) {
576
577         // Question: Why is the LaRCsim matrix arranged so differently
578         // than the one we need???
579
580         // Answer (I think): The LaRCsim matrix is generated in a
581         // different reference frame than we've set up for our world
582
583         LOCAL[0][0] = f->get_T_local_to_body_33();
584         LOCAL[0][1] = -f->get_T_local_to_body_32();
585         LOCAL[0][2] = -f->get_T_local_to_body_31();
586         LOCAL[0][3] = 0.0;
587         LOCAL[1][0] = -f->get_T_local_to_body_23();
588         LOCAL[1][1] = f->get_T_local_to_body_22();
589         LOCAL[1][2] = f->get_T_local_to_body_21();
590         LOCAL[1][3] = 0.0;
591         LOCAL[2][0] = -f->get_T_local_to_body_13();
592         LOCAL[2][1] = f->get_T_local_to_body_12();
593         LOCAL[2][2] = f->get_T_local_to_body_11();
594         LOCAL[2][3] = 0.0;
595         LOCAL[3][0] = LOCAL[3][1] = LOCAL[3][2] = LOCAL[3][3] = 0.0;
596         LOCAL[3][3] = 1.0;
597
598         // printf("LaRCsim LOCAL matrix\n");
599         // MAT3print(LOCAL, stdout);
600
601     } else {
602
603         // calculate the transformation matrix to go from LaRCsim to ssg
604         sgVec3 vec1;
605         sgSetVec3( vec1, 0.0, 1.0, 0.0 );
606         sgMat4 mat1;
607         sgMakeRotMat4( mat1, 90, vec1 );
608
609         sgVec3 vec2;
610         sgSetVec3( vec2, 1.0, 0.0, 0.0 );
611         sgMat4 mat2;
612         sgMakeRotMat4( mat2, 90, vec2 );
613
614         sgMultMat4( sgLARC_TO_SSG, mat1, mat2 );
615
616         /*
617         cout << "LaRCsim to SSG:" << endl;
618         MAT3mat print;
619         int i;
620         int j;
621         for ( i = 0; i < 4; i++ ) {
622             for ( j = 0; j < 4; j++ ) {
623                 print[i][j] = sgLARC_TO_SSG[i][j];
624             }
625         }
626         MAT3print( print, stdout);
627         */
628
629         // code to calculate LOCAL matrix calculated from Phi, Theta, and
630         // Psi (roll, pitch, yaw) in case we aren't running LaRCsim as our
631         // flight model
632
633         MAT3_SET_VEC(vec, 0.0, 0.0, 1.0);
634         MAT3rotate(R, vec, f->get_Phi());
635         // cout << "Roll matrix" << endl;
636         // MAT3print(R, stdout);
637
638         sgVec3 sgrollvec;
639         sgSetVec3( sgrollvec, 0.0, 0.0, 1.0 );
640         sgMat4 sgPHI;           // roll
641         sgMakeRotMat4( sgPHI, f->get_Phi() * RAD_TO_DEG, sgrollvec );
642
643
644         MAT3_SET_VEC(vec, 0.0, 1.0, 0.0);
645         MAT3rotate(TMP, vec, f->get_Theta());
646         // cout << "Pitch matrix" << endl;;
647         // MAT3print(TMP, stdout);
648         MAT3mult(R, R, TMP);
649         // cout << "tmp rotation matrix, R:" << endl;;
650         // MAT3print(R, stdout);
651
652         sgVec3 sgpitchvec;
653         sgSetVec3( sgpitchvec, 0.0, 1.0, 0.0 );
654         sgMat4 sgTHETA;         // pitch
655         sgMakeRotMat4( sgTHETA, f->get_Theta() * RAD_TO_DEG,
656                        sgpitchvec );
657
658         sgMat4 sgROT;
659         sgMultMat4( sgROT, sgPHI, sgTHETA );
660
661
662         MAT3_SET_VEC(vec, 1.0, 0.0, 0.0);
663         MAT3rotate(TMP, vec, -f->get_Psi());
664         // cout << "Yaw matrix" << endl;
665         // MAT3print(TMP, stdout);
666         MAT3mult(LOCAL, R, TMP);
667         // cout << "LOCAL matrix:" << endl;
668         // MAT3print(LOCAL, stdout);
669
670         sgVec3 sgyawvec;
671         sgSetVec3( sgyawvec, 1.0, 0.0, 0.0 );
672         sgMat4 sgPSI;           // pitch
673         sgMakeRotMat4( sgPSI, -f->get_Psi() * RAD_TO_DEG, sgyawvec );
674
675         sgMultMat4( sgLOCAL, sgROT, sgPSI );
676
677         /*
678         MAT3mat print;
679         int i;
680         int j;
681         for ( i = 0; i < 4; i++ ) {
682             for ( j = 0; j < 4; j++ ) {
683                 print[i][j] = sgLOCAL[i][j];
684             }
685         }
686         MAT3print( print, stdout);
687         */
688     } // if ( use_larcsim_local_to_body ) 
689
690 #if !defined(FG_VIEW_INLINE_OPTIMIZATIONS)
691         
692     // Derive the local UP transformation matrix based on *geodetic*
693     // coordinates
694     MAT3_SET_VEC(vec, 0.0, 0.0, 1.0);
695     MAT3rotate(R, vec, f->get_Longitude());     // R = rotate about Z axis
696     // printf("Longitude matrix\n");
697     // MAT3print(R, stdout);
698
699     MAT3_SET_VEC(vec, 0.0, 1.0, 0.0);
700     MAT3mult_vec(vec, vec, R);
701     MAT3rotate(TMP, vec, -f->get_Latitude());  // TMP = rotate about X axis
702     // printf("Latitude matrix\n");
703     // MAT3print(TMP, stdout);
704
705     MAT3mult(UP, R, TMP);
706     // cout << "Local up matrix" << endl;;
707     // MAT3print(UP, stdout);
708
709     sgMakeRotMat4( sgUP, 
710                    f->get_Longitude() * RAD_TO_DEG,
711                    0.0,
712                    -f->get_Latitude() * RAD_TO_DEG );
713     /*
714     cout << "FG derived UP matrix using sg routines" << endl;
715     MAT3mat print;
716     int i;
717     int j;
718     for ( i = 0; i < 4; i++ ) {
719         for ( j = 0; j < 4; j++ ) {
720             print[i][j] = sgUP[i][j];
721         }
722     }
723     MAT3print( print, stdout);
724     */
725
726     MAT3_SET_VEC(local_up, 1.0, 0.0, 0.0);
727     MAT3mult_vec(local_up, local_up, UP);
728
729     // printf( "Local Up = (%.4f, %.4f, %.4f)\n",
730     //         local_up[0], local_up[1], local_up[2]);
731     
732     // Alternative method to Derive local up vector based on
733     // *geodetic* coordinates
734     // alt_up = fgPolarToCart(FG_Longitude, FG_Latitude, 1.0);
735     // printf( "    Alt Up = (%.4f, %.4f, %.4f)\n", 
736     //         alt_up.x, alt_up.y, alt_up.z);
737
738     // Calculate the VIEW matrix
739     MAT3mult(VIEW, LOCAL, UP);
740     // cout << "VIEW matrix" << endl;;
741     // MAT3print(VIEW, stdout);
742
743     sgMat4 sgTMP;
744     sgMultMat4( sgTMP, sgLOCAL, sgUP );
745     sgMultMat4( sgVIEW, sgLARC_TO_SSG, sgTMP );
746
747     /*
748     cout << "FG derived VIEW matrix using sg routines" << endl;
749     MAT3mat print;
750     int i;
751     int j;
752     for ( i = 0; i < 4; i++ ) {
753         for ( j = 0; j < 4; j++ ) {
754             print[i][j] = sgVIEW[i][j];
755         }
756     }
757     MAT3print( print, stdout);
758     */
759
760
761     // generate the current up, forward, and fwrd-view vectors
762     MAT3_SET_VEC(vec, 1.0, 0.0, 0.0);
763     MAT3mult_vec(view_up, vec, VIEW);
764
765     MAT3_SET_VEC(vec, 0.0, 0.0, 1.0);
766     MAT3mult_vec(forward, vec, VIEW);
767     // printf( "Forward vector is (%.2f,%.2f,%.2f)\n", forward[0], forward[1], 
768     //         forward[2]);
769
770     MAT3rotate(TMP, view_up, view_offset);
771     MAT3mult_vec(view_forward, forward, TMP);
772
773     // make a vector to the current view position
774     MAT3_SET_VEC(v0, view_pos.x(), view_pos.y(), view_pos.z());
775
776     // Given a vector pointing straight down (-Z), map into onto the
777     // local plane representing "horizontal".  This should give us the
778     // local direction for moving "south".
779     MAT3_SET_VEC(minus_z, 0.0, 0.0, -1.0);
780     map_vec_onto_cur_surface_plane(local_up, v0, minus_z, surface_south);
781     MAT3_NORMALIZE_VEC(surface_south, ntmp);
782     // printf( "Surface direction directly south %.2f %.2f %.2f\n",
783     //         surface_south[0], surface_south[1], surface_south[2]);
784
785     // now calculate the surface east vector
786     MAT3rotate(TMP, view_up, FG_PI_2);
787     MAT3mult_vec(surface_east, surface_south, TMP);
788     // printf( "Surface direction directly east %.2f %.2f %.2f\n",
789     //         surface_east[0], surface_east[1], surface_east[2]);
790     // printf( "Should be close to zero = %.2f\n", 
791     //         MAT3_DOT_PRODUCT(surface_south, surface_east));
792         
793 #else // FG_VIEW_INLINE_OPTIMIZATIONS
794          
795     //  // Build spherical to cartesian transform matrix directly
796     double cos_lat = f->get_cos_latitude(); // cos(-f->get_Latitude());
797     double sin_lat = -f->get_sin_latitude(); // sin(-f->get_Latitude());
798     double cos_lon = f->get_cos_longitude(); //cos(f->get_Longitude());
799     double sin_lon = f->get_sin_longitude(); //sin(f->get_Longitude());
800
801     double *mat = (double *)UP;
802         
803     mat[0] =  cos_lat*cos_lon;
804     mat[1] =  cos_lat*sin_lon;
805     mat[2] = -sin_lat;
806     mat[3] =  0.0;
807     mat[4] =  -sin_lon;
808     mat[5] =  cos_lon;
809     mat[6] =  0.0;
810     mat[7] =  0.0;
811     mat[8]  =  sin_lat*cos_lon;
812     mat[9]  =  sin_lat*sin_lon;
813     mat[10] =  cos_lat;
814     mat[11] =  mat[12] = mat[13] = mat[14] = 0.0;
815     mat[15] =  1.0;
816
817     MAT3mult(VIEW, LOCAL, UP);
818         
819     // THESE COULD JUST BE POINTERS !!!
820     MAT3_SET_VEC(local_up, mat[0],     mat[1],     mat[2]);
821     MAT3_SET_VEC(view_up,  VIEW[0][0], VIEW[0][1], VIEW[0][2]);
822     MAT3_SET_VEC(forward,  VIEW[2][0], VIEW[2][1], VIEW[2][2]);
823
824     getRotMatrix((double *)TMP, view_up, view_offset);
825     MAT3mult_vec(view_forward, forward, TMP);
826
827     // make a vector to the current view position
828     MAT3_SET_VEC(v0, view_pos.x(), view_pos.y(), view_pos.z());
829
830     // Given a vector pointing straight down (-Z), map into onto the
831     // local plane representing "horizontal".  This should give us the
832     // local direction for moving "south".
833     MAT3_SET_VEC(minus_z, 0.0, 0.0, -1.0);
834     map_vec_onto_cur_surface_plane(local_up, v0, minus_z, surface_south);
835
836     MAT3_NORMALIZE_VEC(surface_south, ntmp);
837     // printf( "Surface direction directly south %.6f %.6f %.6f\n",
838     //         surface_south[0], surface_south[1], surface_south[2]);
839
840     // now calculate the surface east vector
841     getRotMatrix((double *)TMP, view_up, FG_PI_2);
842     MAT3mult_vec(surface_east, surface_south, TMP);
843     // printf( "Surface direction directly east %.6f %.6f %.6f\n",
844     //         surface_east[0], surface_east[1], surface_east[2]);
845     // printf( "Should be close to zero = %.6f\n", 
846     //         MAT3_DOT_PRODUCT(surface_south, surface_east));
847 #endif // !defined(FG_VIEW_INLINE_OPTIMIZATIONS)
848 }
849
850
851 // Update the "World to Eye" transformation matrix
852 // This is most useful for view frustum culling
853 void FGView::UpdateWorldToEye( FGInterface *f ) {
854     MAT3mat R_Phi, R_Theta, R_Psi, R_Lat, R_Lon, T_view;
855     MAT3mat TMP;
856     MAT3hvec vec;
857
858     if ( use_larcsim_local_to_body ) {
859
860         // Question: hey this is even different then LOCAL[][] above??
861         // Answer: yet another coordinate system, this time the
862         // coordinate system in which we do our view frustum culling.
863
864         AIRCRAFT[0][0] = -f->get_T_local_to_body_22();
865         AIRCRAFT[0][1] = -f->get_T_local_to_body_23();
866         AIRCRAFT[0][2] = f->get_T_local_to_body_21();
867         AIRCRAFT[0][3] = 0.0;
868         AIRCRAFT[1][0] = f->get_T_local_to_body_32();
869         AIRCRAFT[1][1] = f->get_T_local_to_body_33();
870         AIRCRAFT[1][2] = -f->get_T_local_to_body_31();
871         AIRCRAFT[1][3] = 0.0;
872         AIRCRAFT[2][0] = f->get_T_local_to_body_12();
873         AIRCRAFT[2][1] = f->get_T_local_to_body_13();
874         AIRCRAFT[2][2] = -f->get_T_local_to_body_11();
875         AIRCRAFT[2][3] = 0.0;
876         AIRCRAFT[3][0] = AIRCRAFT[3][1] = AIRCRAFT[3][2] = AIRCRAFT[3][3] = 0.0;
877         AIRCRAFT[3][3] = 1.0;
878
879     } else {
880
881         // Roll Matrix
882         MAT3_SET_HVEC(vec, 0.0, 0.0, -1.0, 1.0);
883         MAT3rotate(R_Phi, vec, f->get_Phi());
884         // printf("Roll matrix (Phi)\n");
885         // MAT3print(R_Phi, stdout);
886
887         // Pitch Matrix
888         MAT3_SET_HVEC(vec, 1.0, 0.0, 0.0, 1.0);
889         MAT3rotate(R_Theta, vec, f->get_Theta());
890         // printf("\nPitch matrix (Theta)\n");
891         // MAT3print(R_Theta, stdout);
892
893         // Yaw Matrix
894         MAT3_SET_HVEC(vec, 0.0, -1.0, 0.0, 1.0);
895         MAT3rotate(R_Psi, vec, f->get_Psi() + FG_PI /* - view_offset */ );
896         // MAT3rotate(R_Psi, vec, f->get_Psi() + FG_PI - view_offset );
897         // printf("\nYaw matrix (Psi)\n");
898         // MAT3print(R_Psi, stdout);
899
900         // aircraft roll/pitch/yaw
901         MAT3mult(TMP, R_Phi, R_Theta);
902         MAT3mult(AIRCRAFT, TMP, R_Psi);
903
904     } // if ( use_larcsim_local_to_body )
905
906 #if !defined(FG_VIEW_INLINE_OPTIMIZATIONS)
907         
908     // printf("AIRCRAFT matrix\n");
909     // MAT3print(AIRCRAFT, stdout);
910
911     // View rotation matrix relative to current aircraft orientation
912     MAT3_SET_HVEC(vec, 0.0, -1.0, 0.0, 1.0);
913     MAT3mult_vec(vec, vec, AIRCRAFT);
914     // printf("aircraft up vector = %.2f %.2f %.2f\n", 
915     //        vec[0], vec[1], vec[2]);
916     MAT3rotate(TMP, vec, -view_offset );
917     MAT3mult(VIEW_OFFSET, AIRCRAFT, TMP);
918     // printf("VIEW_OFFSET matrix\n");
919     // MAT3print(VIEW_OFFSET, stdout);
920
921     // View position in scenery centered coordinates
922     MAT3_SET_HVEC(vec, view_pos.x(), view_pos.y(), view_pos.z(), 1.0);
923     MAT3translate(T_view, vec);
924     // printf("\nTranslation matrix\n");
925     // MAT3print(T_view, stdout);
926
927     // Latitude
928     MAT3_SET_HVEC(vec, 1.0, 0.0, 0.0, 1.0);
929     // R_Lat = rotate about X axis
930     MAT3rotate(R_Lat, vec, f->get_Latitude());
931     // printf("\nLatitude matrix\n");
932     // MAT3print(R_Lat, stdout);
933
934     // Longitude
935     MAT3_SET_HVEC(vec, 0.0, 0.0, 1.0, 1.0);
936     // R_Lon = rotate about Z axis
937     MAT3rotate(R_Lon, vec, f->get_Longitude() - FG_PI_2 );
938     // printf("\nLongitude matrix\n");
939     // MAT3print(R_Lon, stdout);
940
941     // lon/lat
942     MAT3mult(WORLD, R_Lat, R_Lon);
943     // printf("\nworld\n");
944     // MAT3print(WORLD, stdout);
945
946     MAT3mult(EYE_TO_WORLD, VIEW_OFFSET, WORLD);
947     MAT3mult(EYE_TO_WORLD, EYE_TO_WORLD, T_view);
948     // printf("\nEye to world\n");
949     // MAT3print(EYE_TO_WORLD, stdout);
950
951     MAT3invert(WORLD_TO_EYE, EYE_TO_WORLD);
952     // printf("\nWorld to eye\n");
953     // MAT3print(WORLD_TO_EYE, stdout);
954
955     // printf( "\nview_pos = %.2f %.2f %.2f\n", 
956     //         view_pos.x, view_pos.y, view_pos.z );
957
958     // MAT3_SET_HVEC(eye, 0.0, 0.0, 0.0, 1.0);
959     // MAT3mult_vec(vec, eye, EYE_TO_WORLD);
960     // printf("\neye -> world = %.2f %.2f %.2f\n", vec[0], vec[1], vec[2]);
961
962     // MAT3_SET_HVEC(vec1, view_pos.x, view_pos.y, view_pos.z, 1.0);
963     // MAT3mult_vec(vec, vec1, WORLD_TO_EYE);
964     // printf( "\nabs_view_pos -> eye = %.2f %.2f %.2f\n", 
965     //         vec[0], vec[1], vec[2]);
966 #else  // FG_VIEW_INLINE_OPTIMIZATIONS
967         
968     MAT3_SET_HVEC(vec, -AIRCRAFT[1][0], -AIRCRAFT[1][1], -AIRCRAFT[1][2], -AIRCRAFT[1][3]);
969     getRotMatrix((double *)TMP, vec, -view_offset );
970     MAT3mult(VIEW_OFFSET, AIRCRAFT, TMP);
971     // MAT3print_formatted(VIEW_OFFSET, stdout, "VIEW_OFFSET matrix:\n",
972     //                                   NULL, "%#8.6f  ", "\n");
973
974     // Build spherical to cartesian transform matrix directly
975     double *mat = (double *)WORLD; //T_view; //WORLD;
976     double cos_lat = f->get_cos_latitude(); //cos(f->get_Latitude());
977     double sin_lat = f->get_sin_latitude(); //sin(f->get_Latitude());
978     // using trig identities  this:
979     //  mat[0]  =  cos(f->get_Longitude() - FG_PI_2);//cos_lon;
980     //  mat[1]  =  sin(f->get_Longitude() - FG_PI_2);//sin_lon;
981     // becomes this: :-)
982     mat[0]  =  f->get_sin_longitude(); //cos_lon;
983     mat[1]  = -f->get_cos_longitude(); //sin_lon;
984     mat[4]  = -cos_lat*mat[1]; //mat[1]=sin_lon;
985     mat[5]  =  cos_lat*mat[0]; //mat[0]=cos_lon;
986     mat[6]  =  sin_lat;
987     mat[8]  =  sin_lat*mat[1]; //mat[1]=sin_lon;
988     mat[9]  = -sin_lat*mat[0]; //mat[0]=cos_lon;
989     mat[10] =  cos_lat;
990
991     // BUILD EYE_TO_WORLD = AIRCRAFT * WORLD
992     // and WORLD_TO_EYE = Inverse( EYE_TO_WORLD) concurrently
993     // by Transposing the 3x3 rotation sub-matrix
994     WORLD_TO_EYE[0][0] = EYE_TO_WORLD[0][0] =
995         VIEW_OFFSET[0][0]*mat[0] + VIEW_OFFSET[0][1]*mat[4] + VIEW_OFFSET[0][2]*mat[8];
996         
997     WORLD_TO_EYE[1][0] = EYE_TO_WORLD[0][1] =
998         VIEW_OFFSET[0][0]*mat[1] + VIEW_OFFSET[0][1]*mat[5] + VIEW_OFFSET[0][2]*mat[9];
999         
1000     WORLD_TO_EYE[2][0] = EYE_TO_WORLD[0][2] =
1001         VIEW_OFFSET[0][1]*mat[6] + VIEW_OFFSET[0][2]*mat[10];
1002         
1003     WORLD_TO_EYE[0][1] = EYE_TO_WORLD[1][0] =
1004         VIEW_OFFSET[1][0]*mat[0] + VIEW_OFFSET[1][1]*mat[4] + VIEW_OFFSET[1][2]*mat[8];
1005         
1006     WORLD_TO_EYE[1][1] = EYE_TO_WORLD[1][1] =
1007         VIEW_OFFSET[1][0]*mat[1] + VIEW_OFFSET[1][1]*mat[5] + VIEW_OFFSET[1][2]*mat[9];
1008         
1009     WORLD_TO_EYE[2][1] = EYE_TO_WORLD[1][2] =
1010         VIEW_OFFSET[1][1]*mat[6] + VIEW_OFFSET[1][2]*mat[10];
1011         
1012     WORLD_TO_EYE[0][2] = EYE_TO_WORLD[2][0] =
1013         VIEW_OFFSET[2][0]*mat[0] + VIEW_OFFSET[2][1]*mat[4] + VIEW_OFFSET[2][2]*mat[8];
1014         
1015     WORLD_TO_EYE[1][2] = EYE_TO_WORLD[2][1] =
1016         VIEW_OFFSET[2][0]*mat[1] + VIEW_OFFSET[2][1]*mat[5] + VIEW_OFFSET[2][2]*mat[9];
1017         
1018     WORLD_TO_EYE[2][2] = EYE_TO_WORLD[2][2] =
1019         VIEW_OFFSET[2][1]*mat[6] + VIEW_OFFSET[2][2]*mat[10];
1020         
1021     // TRANSLATE TO VIEW POSITION
1022     EYE_TO_WORLD[3][0] = view_pos.x();
1023     EYE_TO_WORLD[3][1] = view_pos.y();
1024     EYE_TO_WORLD[3][2] = view_pos.z();
1025         
1026     // FILL 0 ENTRIES
1027     WORLD_TO_EYE[0][3] = WORLD_TO_EYE[1][3] = WORLD_TO_EYE[2][3] = 
1028         EYE_TO_WORLD[0][3] = EYE_TO_WORLD[1][3] = EYE_TO_WORLD[2][3] = 0.0;
1029
1030     // FILL UNITY ENTRIES
1031     WORLD_TO_EYE[3][3] = EYE_TO_WORLD[3][3] = 1.0;
1032         
1033     /* MAKE THE INVERTED TRANSLATIONS */
1034     mat = (double *)EYE_TO_WORLD;
1035     WORLD_TO_EYE[3][0] = -mat[12]*mat[0]
1036         -mat[13]*mat[1]
1037         -mat[14]*mat[2];
1038         
1039     WORLD_TO_EYE[3][1] = -mat[12]*mat[4]
1040         -mat[13]*mat[5]
1041         -mat[14]*mat[6];
1042         
1043     WORLD_TO_EYE[3][2] = -mat[12]*mat[8]
1044         -mat[13]*mat[9]
1045         -mat[14]*mat[10];
1046         
1047     // MAT3print_formatted(EYE_TO_WORLD, stdout, "EYE_TO_WORLD matrix:\n",
1048     //                                   NULL, "%#8.6f  ", "\n");
1049
1050     // MAT3print_formatted(WORLD_TO_EYE, stdout, "WORLD_TO_EYE matrix:\n",
1051     //                                   NULL, "%#8.6f  ", "\n");
1052
1053 #endif // defined(FG_VIEW_INLINE_OPTIMIZATIONS)
1054 }
1055
1056
1057 #if 0
1058 // Reject non viewable spheres from current View Frustrum by Curt
1059 // Olson curt@me.umn.edu and Norman Vine nhv@yahoo.com with 'gentle
1060 // guidance' from Steve Baker sbaker@link.com
1061 int
1062 FGView::SphereClip( const Point3D& cp, const double radius )
1063 {
1064     double x1, y1;
1065
1066     MAT3vec eye;        
1067     double *mat;
1068     double x, y, z;
1069
1070     x = cp->x;
1071     y = cp->y;
1072     z = cp->z;
1073         
1074     mat = (double *)(WORLD_TO_EYE);
1075         
1076     eye[2] =  x*mat[2] + y*mat[6] + z*mat[10] + mat[14];
1077         
1078     // Check near and far clip plane
1079     if( ( eye[2] > radius ) ||
1080         ( eye[2] + radius + current_weather.visibility < 0) )
1081         // ( eye[2] + radius + far_plane < 0) )
1082     {
1083         return 1;
1084     }
1085         
1086     // check right and left clip plane (from eye perspective)
1087     x1 = radius * fov_x_clip;
1088     eye[0] = (x*mat[0] + y*mat[4] + z*mat[8] + mat[12]) * slope_x;
1089     if( (eye[2] > -(eye[0]+x1)) || (eye[2] > (eye[0]-x1)) ) {
1090         return(1);
1091     }
1092         
1093     // check bottom and top clip plane (from eye perspective)
1094     y1 = radius * fov_y_clip;
1095     eye[1] = (x*mat[1] + y*mat[5] + z*mat[9] + mat[13]) * slope_y; 
1096     if( (eye[2] > -(eye[1]+y1)) || (eye[2] > (eye[1]-y1)) ) {
1097         return 1;
1098     }
1099
1100     return 0;
1101 }
1102 #endif
1103
1104
1105 // Destructor
1106 FGView::~FGView( void ) {
1107 }