]> git.mxchange.org Git - flightgear.git/blob - src/Main/views.cxx
Updated to support new weather subsystem (visibility variable determins
[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 }
72
73
74 // Initialize a view structure
75 void FGView::Init( void ) {
76     FG_LOG( FG_VIEW, FG_INFO, "Initializing View parameters" );
77
78     view_mode = FG_VIEW_FIRST_PERSON;
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 // Cycle view mode
135 void FGView::cycle_view_mode() {
136     if ( view_mode == FG_VIEW_FIRST_PERSON ) {
137         view_mode = FG_VIEW_FOLLOW;
138     } else if ( view_mode == FG_VIEW_FOLLOW ) {
139         view_mode = FG_VIEW_FIRST_PERSON;
140     }
141 }
142
143
144 // Update the view volume, position, and orientation
145 void FGView::UpdateViewParams( void ) {
146     FGInterface *f = current_aircraft.fdm_state;
147
148     UpdateViewMath(f);
149     
150     if ((current_options.get_panel_status() != panel_hist) &&                          (current_options.get_panel_status()))
151     {
152         FGPanel::OurPanel->ReInit( 0, 0, 1024, 768);
153     }
154
155     if ( ! current_options.get_panel_status() ) {
156         // xglViewport(0, 0 , (GLint)(winWidth), (GLint)(winHeight) );
157     } else {
158         // xglViewport(0, (GLint)((winHeight)*0.5768), (GLint)(winWidth), 
159         //             (GLint)((winHeight)*0.4232) );
160     }
161
162     panel_hist = current_options.get_panel_status();
163 }
164
165
166 void getRotMatrix(double* out, MAT3vec vec, double radians)
167 {
168     /* This function contributed by Erich Boleyn (erich@uruk.org) */
169     /* This function used from the Mesa OpenGL code (matrix.c)  */
170     double s, c; // mag,
171     double vx, vy, vz, xy, yz, zx, xs, ys, zs, one_c; //, xx, yy, zz
172   
173     MAT3identity(out);
174     s = sin(radians);
175     c = cos(radians);
176   
177     //  mag = getMagnitude();
178   
179     vx = vec[0];
180     vy = vec[1];
181     vz = vec[2];
182   
183 #define M(row,col)  out[row*4 + col]
184   
185     /*
186      *     Arbitrary axis rotation matrix.
187      *
188      *  This is composed of 5 matrices, Rz, Ry, T, Ry', Rz', multiplied
189      *  like so:  Rz * Ry * T * Ry' * Rz'.  T is the final rotation
190      *  (which is about the X-axis), and the two composite transforms
191      *  Ry' * Rz' and Rz * Ry are (respectively) the rotations necessary
192      *  from the arbitrary axis to the X-axis then back.  They are
193      *  all elementary rotations.
194      *
195      *  Rz' is a rotation about the Z-axis, to bring the axis vector
196      *  into the x-z plane.  Then Ry' is applied, rotating about the
197      *  Y-axis to bring the axis vector parallel with the X-axis.  The
198      *  rotation about the X-axis is then performed.  Ry and Rz are
199      *  simply the respective inverse transforms to bring the arbitrary
200      *  axis back to it's original orientation.  The first transforms
201      *  Rz' and Ry' are considered inverses, since the data from the
202      *  arbitrary axis gives you info on how to get to it, not how
203      *  to get away from it, and an inverse must be applied.
204      *
205      *  The basic calculation used is to recognize that the arbitrary
206      *  axis vector (x, y, z), since it is of unit length, actually
207      *  represents the sines and cosines of the angles to rotate the
208      *  X-axis to the same orientation, with theta being the angle about
209      *  Z and phi the angle about Y (in the order described above)
210      *  as follows:
211      *
212      *  cos ( theta ) = x / sqrt ( 1 - z^2 )
213      *  sin ( theta ) = y / sqrt ( 1 - z^2 )
214      *
215      *  cos ( phi ) = sqrt ( 1 - z^2 )
216      *  sin ( phi ) = z
217      *
218      *  Note that cos ( phi ) can further be inserted to the above
219      *  formulas:
220      *
221      *  cos ( theta ) = x / cos ( phi )
222      *  sin ( theta ) = y / cos ( phi )
223      *
224      *  ...etc.  Because of those relations and the standard trigonometric
225      *  relations, it is pssible to reduce the transforms down to what
226      *  is used below.  It may be that any primary axis chosen will give the
227      *  same results (modulo a sign convention) using thie method.
228      *
229      *  Particularly nice is to notice that all divisions that might
230      *  have caused trouble when parallel to certain planes or
231      *  axis go away with care paid to reducing the expressions.
232      *  After checking, it does perform correctly under all cases, since
233      *  in all the cases of division where the denominator would have
234      *  been zero, the numerator would have been zero as well, giving
235      *  the expected result.
236      */
237     
238     one_c = 1.0F - c;
239     
240     //  xx = vx * vx;
241     //  yy = vy * vy;
242     //  zz = vz * vz;
243   
244     //  xy = vx * vy;
245     //  yz = vy * vz;
246     //  zx = vz * vx;
247   
248   
249     M(0,0) = (one_c * vx * vx) + c;  
250     xs = vx * s;
251     yz = vy * vz * one_c;
252     M(1,2) = yz + xs;
253     M(2,1) = yz - xs;
254
255     M(1,1) = (one_c * vy * vy) + c;
256     ys = vy * s;
257     zx = vz * vx * one_c;
258     M(0,2) = zx - ys;
259     M(2,0) = zx + ys;
260   
261     M(2,2) = (one_c * vz *vz) + c;
262     zs = vz * s;
263     xy = vx * vy * one_c;
264     M(0,1) = xy + zs;
265     M(1,0) = xy - zs;
266   
267     //  M(0,0) = (one_c * xx) + c;
268     //  M(1,0) = (one_c * xy) - zs;
269     //  M(2,0) = (one_c * zx) + ys;
270   
271     //  M(0,1) = (one_c * xy) + zs;
272     //  M(1,1) = (one_c * yy) + c;
273     //  M(2,1) = (one_c * yz) - xs;
274   
275     //  M(0,2) = (one_c * zx) - ys;
276     //  M(1,2) = (one_c * yz) + xs;
277     //  M(2,2) = (one_c * zz) + c;
278   
279 #undef M
280 }
281
282
283 // Update the view parameters
284 void FGView::UpdateViewMath( FGInterface *f ) {
285     Point3D p;
286     MAT3vec vec, forward, v0, minus_z;
287     MAT3mat R, TMP, UP, LOCAL, VIEW;
288     double ntmp;
289
290     if ( update_fov ) {
291         // printf("Updating fov\n");
292         UpdateFOV( current_options );
293         update_fov = false;
294     }
295                 
296     scenery.center = scenery.next_center;
297
298 #if !defined(FG_VIEW_INLINE_OPTIMIZATIONS)
299     // printf("scenery center = %.2f %.2f %.2f\n", scenery.center.x,
300     //        scenery.center.y, scenery.center.z);
301
302     // calculate the cartesion coords of the current lat/lon/0 elev
303     p = Point3D( f->get_Longitude(), 
304                  f->get_Lat_geocentric(), 
305                  f->get_Sea_level_radius() * FEET_TO_METER );
306
307     cur_zero_elev = fgPolarToCart3d(p) - scenery.center;
308
309     // calculate view position in current FG view coordinate system
310     // p.lon & p.lat are already defined earlier, p.radius was set to
311     // the sea level radius, so now we add in our altitude.
312     if ( f->get_Altitude() * FEET_TO_METER > 
313          (scenery.cur_elev + 0.5 * METER_TO_FEET) ) {
314         p.setz( p.radius() + f->get_Altitude() * FEET_TO_METER );
315     } else {
316         p.setz( p.radius() + scenery.cur_elev + 0.5 * METER_TO_FEET );
317     }
318
319     abs_view_pos = fgPolarToCart3d(p);
320         
321 #else // FG_VIEW_INLINE_OPTIMIZATIONS
322         
323     double tmp_radius = f->get_Sea_level_radius() * FEET_TO_METER;
324     double tmp = f->get_cos_lat_geocentric() * tmp_radius;
325         
326     cur_zero_elev.setx(f->get_cos_longitude()*tmp - scenery.center.x());
327     cur_zero_elev.sety(f->get_sin_longitude()*tmp - scenery.center.y());
328     cur_zero_elev.setz(f->get_sin_lat_geocentric()*tmp_radius - scenery.center.z());
329
330     // calculate view position in current FG view coordinate system
331     // p.lon & p.lat are already defined earlier, p.radius was set to
332     // the sea level radius, so now we add in our altitude.
333     if ( f->get_Altitude() * FEET_TO_METER > 
334          (scenery.cur_elev + 0.5 * METER_TO_FEET) ) {
335         tmp_radius += f->get_Altitude() * FEET_TO_METER;
336     } else {
337         tmp_radius += scenery.cur_elev + 0.5 * METER_TO_FEET ;
338     }
339     tmp = f->get_cos_lat_geocentric() * tmp_radius;
340     abs_view_pos.setx(f->get_cos_longitude()*tmp);
341     abs_view_pos.sety(f->get_sin_longitude()*tmp);
342     abs_view_pos.setz(f->get_sin_lat_geocentric()*tmp_radius);
343         
344 #endif // FG_VIEW_INLINE_OPTIMIZATIONS
345         
346     view_pos = abs_view_pos - scenery.center;
347
348     FG_LOG( FG_VIEW, FG_DEBUG, "Polar view pos = " << p );
349     FG_LOG( FG_VIEW, FG_DEBUG, "Absolute view pos = " << abs_view_pos );
350     FG_LOG( FG_VIEW, FG_DEBUG, "Relative view pos = " << view_pos );
351
352     // Derive the LOCAL aircraft rotation matrix (roll, pitch, yaw)
353     // from FG_T_local_to_body[3][3]
354
355     if ( use_larcsim_local_to_body ) {
356
357         // Question: Why is the LaRCsim matrix arranged so differently
358         // than the one we need???
359
360         // Answer (I think): The LaRCsim matrix is generated in a
361         // different reference frame than we've set up for our world
362
363         LOCAL[0][0] = f->get_T_local_to_body_33();
364         LOCAL[0][1] = -f->get_T_local_to_body_32();
365         LOCAL[0][2] = -f->get_T_local_to_body_31();
366         LOCAL[0][3] = 0.0;
367         LOCAL[1][0] = -f->get_T_local_to_body_23();
368         LOCAL[1][1] = f->get_T_local_to_body_22();
369         LOCAL[1][2] = f->get_T_local_to_body_21();
370         LOCAL[1][3] = 0.0;
371         LOCAL[2][0] = -f->get_T_local_to_body_13();
372         LOCAL[2][1] = f->get_T_local_to_body_12();
373         LOCAL[2][2] = f->get_T_local_to_body_11();
374         LOCAL[2][3] = 0.0;
375         LOCAL[3][0] = LOCAL[3][1] = LOCAL[3][2] = LOCAL[3][3] = 0.0;
376         LOCAL[3][3] = 1.0;
377
378         // printf("LaRCsim LOCAL matrix\n");
379         // MAT3print(LOCAL, stdout);
380
381     } else {
382
383         // calculate the transformation matrix to go from LaRCsim to ssg
384         sgVec3 vec1;
385         sgSetVec3( vec1, 0.0, 1.0, 0.0 );
386         sgMat4 mat1;
387         sgMakeRotMat4( mat1, 90, vec1 );
388
389         sgVec3 vec2;
390         sgSetVec3( vec2, 1.0, 0.0, 0.0 );
391         sgMat4 mat2;
392         sgMakeRotMat4( mat2, 90, vec2 );
393
394         sgMultMat4( sgLARC_TO_SSG, mat1, mat2 );
395
396         /*
397         cout << "LaRCsim to SSG:" << endl;
398         MAT3mat print;
399         int i;
400         int j;
401         for ( i = 0; i < 4; i++ ) {
402             for ( j = 0; j < 4; j++ ) {
403                 print[i][j] = sgLARC_TO_SSG[i][j];
404             }
405         }
406         MAT3print( print, stdout);
407         */
408
409         // code to calculate LOCAL matrix calculated from Phi, Theta, and
410         // Psi (roll, pitch, yaw) in case we aren't running LaRCsim as our
411         // flight model
412
413         MAT3_SET_VEC(vec, 0.0, 0.0, 1.0);
414         MAT3rotate(R, vec, f->get_Phi());
415         // cout << "Roll matrix" << endl;
416         // MAT3print(R, stdout);
417
418         sgVec3 sgrollvec;
419         sgSetVec3( sgrollvec, 0.0, 0.0, 1.0 );
420         sgMat4 sgPHI;           // roll
421         sgMakeRotMat4( sgPHI, f->get_Phi() * RAD_TO_DEG, sgrollvec );
422
423
424         MAT3_SET_VEC(vec, 0.0, 1.0, 0.0);
425         MAT3rotate(TMP, vec, f->get_Theta());
426         // cout << "Pitch matrix" << endl;;
427         // MAT3print(TMP, stdout);
428         MAT3mult(R, R, TMP);
429         // cout << "tmp rotation matrix, R:" << endl;;
430         // MAT3print(R, stdout);
431
432         sgVec3 sgpitchvec;
433         sgSetVec3( sgpitchvec, 0.0, 1.0, 0.0 );
434         sgMat4 sgTHETA;         // pitch
435         sgMakeRotMat4( sgTHETA, f->get_Theta() * RAD_TO_DEG,
436                        sgpitchvec );
437
438         sgMat4 sgROT;
439         sgMultMat4( sgROT, sgPHI, sgTHETA );
440
441
442         MAT3_SET_VEC(vec, 1.0, 0.0, 0.0);
443         MAT3rotate(TMP, vec, -f->get_Psi());
444         // cout << "Yaw matrix" << endl;
445         // MAT3print(TMP, stdout);
446         MAT3mult(LOCAL, R, TMP);
447         // cout << "LOCAL matrix:" << endl;
448         // MAT3print(LOCAL, stdout);
449
450         sgVec3 sgyawvec;
451         sgSetVec3( sgyawvec, 1.0, 0.0, 0.0 );
452         sgMat4 sgPSI;           // pitch
453         sgMakeRotMat4( sgPSI, -f->get_Psi() * RAD_TO_DEG, sgyawvec );
454
455         sgMultMat4( sgLOCAL, sgROT, sgPSI );
456
457         /*
458         MAT3mat print;
459         int i;
460         int j;
461         for ( i = 0; i < 4; i++ ) {
462             for ( j = 0; j < 4; j++ ) {
463                 print[i][j] = sgLOCAL[i][j];
464             }
465         }
466         MAT3print( print, stdout);
467         */
468     } // if ( use_larcsim_local_to_body ) 
469
470 #if !defined(FG_VIEW_INLINE_OPTIMIZATIONS)
471         
472     // Derive the local UP transformation matrix based on *geodetic*
473     // coordinates
474     MAT3_SET_VEC(vec, 0.0, 0.0, 1.0);
475     MAT3rotate(R, vec, f->get_Longitude());     // R = rotate about Z axis
476     // printf("Longitude matrix\n");
477     // MAT3print(R, stdout);
478
479     MAT3_SET_VEC(vec, 0.0, 1.0, 0.0);
480     MAT3mult_vec(vec, vec, R);
481     MAT3rotate(TMP, vec, -f->get_Latitude());  // TMP = rotate about X axis
482     // printf("Latitude matrix\n");
483     // MAT3print(TMP, stdout);
484
485     MAT3mult(UP, R, TMP);
486     // cout << "Local up matrix" << endl;;
487     // MAT3print(UP, stdout);
488
489     sgMakeRotMat4( sgUP, 
490                    f->get_Longitude() * RAD_TO_DEG,
491                    0.0,
492                    -f->get_Latitude() * RAD_TO_DEG );
493     /*
494     cout << "FG derived UP matrix using sg routines" << endl;
495     MAT3mat print;
496     int i;
497     int j;
498     for ( i = 0; i < 4; i++ ) {
499         for ( j = 0; j < 4; j++ ) {
500             print[i][j] = sgUP[i][j];
501         }
502     }
503     MAT3print( print, stdout);
504     */
505
506     MAT3_SET_VEC(local_up, 1.0, 0.0, 0.0);
507     MAT3mult_vec(local_up, local_up, UP);
508
509     // printf( "Local Up = (%.4f, %.4f, %.4f)\n",
510     //         local_up[0], local_up[1], local_up[2]);
511     
512     // Alternative method to Derive local up vector based on
513     // *geodetic* coordinates
514     // alt_up = fgPolarToCart(FG_Longitude, FG_Latitude, 1.0);
515     // printf( "    Alt Up = (%.4f, %.4f, %.4f)\n", 
516     //         alt_up.x, alt_up.y, alt_up.z);
517
518     // Calculate the VIEW matrix
519     MAT3mult(VIEW, LOCAL, UP);
520     // cout << "VIEW matrix" << endl;;
521     // MAT3print(VIEW, stdout);
522
523     sgMat4 sgTMP, sgTMP2;
524     sgMultMat4( sgTMP, sgLOCAL, sgUP );
525
526     // generate the sg view up vector
527     sgVec3 vec1;
528     sgSetVec3( vec1, 1.0, 0.0, 0.0 );
529     sgXformVec3( sgview_up, vec1, sgTMP );
530
531     // generate the view offset matrix
532     sgMakeRotMat4( sgVIEW_OFFSET, view_offset * RAD_TO_DEG, sgview_up );
533
534     /*
535     cout << "sg VIEW_OFFSET matrix" << endl;
536     MAT3mat print;
537     int i;
538     int j;
539     for ( i = 0; i < 4; i++ ) {
540         for ( j = 0; j < 4; j++ ) {
541             print[i][j] = sgVIEW_OFFSET[i][j];
542         }
543     }
544     MAT3print( print, stdout);
545     */
546
547     sgMultMat4( sgTMP2, sgTMP, sgVIEW_OFFSET );
548     sgMultMat4( sgVIEW_ROT, sgLARC_TO_SSG, sgTMP2 );
549
550     sgMakeTransMat4( sgTRANS, view_pos.x(), view_pos.y(), view_pos.z() );
551
552     sgMultMat4( sgVIEW, sgVIEW_ROT, sgTRANS );
553
554     FGMat4Wrapper tmp;
555     sgCopyMat4( tmp.m, sgVIEW );
556     follow.push_back( tmp );
557
558     // generate the current up, forward, and fwrd-view vectors
559     MAT3_SET_VEC(vec, 1.0, 0.0, 0.0);
560     MAT3mult_vec(view_up, vec, VIEW);
561
562     /*
563     cout << "FG derived VIEW matrix using sg routines" << endl;
564     MAT3mat print;
565     int i;
566     int j;
567     for ( i = 0; i < 4; i++ ) {
568         for ( j = 0; j < 4; j++ ) {
569             print[i][j] = sgVIEW[i][j];
570         }
571     }
572     MAT3print( print, stdout);
573     */
574
575     MAT3_SET_VEC(vec, 0.0, 0.0, 1.0);
576     MAT3mult_vec(forward, vec, VIEW);
577     // printf( "Forward vector is (%.2f,%.2f,%.2f)\n", forward[0], forward[1], 
578     //         forward[2]);
579
580     MAT3rotate(TMP, view_up, view_offset);
581     MAT3mult_vec(view_forward, forward, TMP);
582
583     // make a vector to the current view position
584     MAT3_SET_VEC(v0, view_pos.x(), view_pos.y(), view_pos.z());
585
586     // Given a vector pointing straight down (-Z), map into onto the
587     // local plane representing "horizontal".  This should give us the
588     // local direction for moving "south".
589     MAT3_SET_VEC(minus_z, 0.0, 0.0, -1.0);
590     map_vec_onto_cur_surface_plane(local_up, v0, minus_z, surface_south);
591     MAT3_NORMALIZE_VEC(surface_south, ntmp);
592     // printf( "Surface direction directly south %.2f %.2f %.2f\n",
593     //         surface_south[0], surface_south[1], surface_south[2]);
594
595     // now calculate the surface east vector
596     MAT3rotate(TMP, view_up, FG_PI_2);
597     MAT3mult_vec(surface_east, surface_south, TMP);
598     // printf( "Surface direction directly east %.2f %.2f %.2f\n",
599     //         surface_east[0], surface_east[1], surface_east[2]);
600     // printf( "Should be close to zero = %.2f\n", 
601     //         MAT3_DOT_PRODUCT(surface_south, surface_east));
602         
603 #else // FG_VIEW_INLINE_OPTIMIZATIONS
604          
605     //  // Build spherical to cartesian transform matrix directly
606     double cos_lat = f->get_cos_latitude(); // cos(-f->get_Latitude());
607     double sin_lat = -f->get_sin_latitude(); // sin(-f->get_Latitude());
608     double cos_lon = f->get_cos_longitude(); //cos(f->get_Longitude());
609     double sin_lon = f->get_sin_longitude(); //sin(f->get_Longitude());
610
611     double *mat = (double *)UP;
612         
613     mat[0] =  cos_lat*cos_lon;
614     mat[1] =  cos_lat*sin_lon;
615     mat[2] = -sin_lat;
616     mat[3] =  0.0;
617     mat[4] =  -sin_lon;
618     mat[5] =  cos_lon;
619     mat[6] =  0.0;
620     mat[7] =  0.0;
621     mat[8]  =  sin_lat*cos_lon;
622     mat[9]  =  sin_lat*sin_lon;
623     mat[10] =  cos_lat;
624     mat[11] =  mat[12] = mat[13] = mat[14] = 0.0;
625     mat[15] =  1.0;
626
627     MAT3mult(VIEW, LOCAL, UP);
628         
629     // THESE COULD JUST BE POINTERS !!!
630     MAT3_SET_VEC(local_up, mat[0],     mat[1],     mat[2]);
631     MAT3_SET_VEC(view_up,  VIEW[0][0], VIEW[0][1], VIEW[0][2]);
632     MAT3_SET_VEC(forward,  VIEW[2][0], VIEW[2][1], VIEW[2][2]);
633
634     getRotMatrix((double *)TMP, view_up, view_offset);
635     MAT3mult_vec(view_forward, forward, TMP);
636
637     // make a vector to the current view position
638     MAT3_SET_VEC(v0, view_pos.x(), view_pos.y(), view_pos.z());
639
640     // Given a vector pointing straight down (-Z), map into onto the
641     // local plane representing "horizontal".  This should give us the
642     // local direction for moving "south".
643     MAT3_SET_VEC(minus_z, 0.0, 0.0, -1.0);
644     map_vec_onto_cur_surface_plane(local_up, v0, minus_z, surface_south);
645
646     MAT3_NORMALIZE_VEC(surface_south, ntmp);
647     // printf( "Surface direction directly south %.6f %.6f %.6f\n",
648     //         surface_south[0], surface_south[1], surface_south[2]);
649
650     // now calculate the surface east vector
651     getRotMatrix((double *)TMP, view_up, FG_PI_2);
652     MAT3mult_vec(surface_east, surface_south, TMP);
653     // printf( "Surface direction directly east %.6f %.6f %.6f\n",
654     //         surface_east[0], surface_east[1], surface_east[2]);
655     // printf( "Should be close to zero = %.6f\n", 
656     //         MAT3_DOT_PRODUCT(surface_south, surface_east));
657 #endif // !defined(FG_VIEW_INLINE_OPTIMIZATIONS)
658 }
659
660
661 // Destructor
662 FGView::~FGView( void ) {
663 }