1998-05-16 13:08:34 +00:00
|
|
|
// views.cxx -- data structures and routines for managing and view
|
|
|
|
// parameters.
|
1998-04-25 20:24:00 +00:00
|
|
|
//
|
|
|
|
// Written by Curtis Olson, started August 1997.
|
|
|
|
//
|
1999-10-14 17:32:34 +00:00
|
|
|
// Copyright (C) 1997 Curtis L. Olson - curt@flightgear.org
|
1998-04-25 20:24:00 +00:00
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
//
|
|
|
|
// $Id$
|
|
|
|
|
2000-10-02 21:49:04 +00:00
|
|
|
#include <simgear/compiler.h>
|
1997-08-27 21:31:17 +00:00
|
|
|
|
1998-04-24 00:49:17 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
1997-08-27 21:31:17 +00:00
|
|
|
|
2000-02-04 22:50:04 +00:00
|
|
|
#include <plib/ssg.h> // plib include
|
1999-06-18 03:42:54 +00:00
|
|
|
|
2000-02-15 03:30:01 +00:00
|
|
|
#include <simgear/constants.h>
|
2000-02-16 23:01:03 +00:00
|
|
|
#include <simgear/debug/logstream.hxx>
|
|
|
|
#include <simgear/math/point3d.hxx>
|
|
|
|
#include <simgear/math/polar3d.hxx>
|
|
|
|
#include <simgear/math/vector.hxx>
|
2000-02-15 03:30:01 +00:00
|
|
|
|
1998-10-17 01:33:52 +00:00
|
|
|
#include <Aircraft/aircraft.hxx>
|
1998-11-09 23:39:22 +00:00
|
|
|
#include <Cockpit/panel.hxx>
|
1998-04-30 12:34:17 +00:00
|
|
|
#include <Scenery/scenery.hxx>
|
1997-08-27 21:31:17 +00:00
|
|
|
|
1998-05-16 13:08:34 +00:00
|
|
|
#include "options.hxx"
|
1998-04-22 13:25:39 +00:00
|
|
|
#include "views.hxx"
|
|
|
|
|
|
|
|
|
1999-09-09 00:16:28 +00:00
|
|
|
// This is a record containing current view parameters for the current
|
|
|
|
// aircraft position
|
|
|
|
FGView pilot_view;
|
|
|
|
|
|
|
|
// This is a record containing current view parameters for the current
|
|
|
|
// view position
|
1998-12-09 18:50:12 +00:00
|
|
|
FGView current_view;
|
1997-12-10 22:37:34 +00:00
|
|
|
|
|
|
|
|
1998-05-16 13:08:34 +00:00
|
|
|
// Constructor
|
1998-12-09 18:50:12 +00:00
|
|
|
FGView::FGView( void ) {
|
1998-05-16 13:08:34 +00:00
|
|
|
}
|
|
|
|
|
2000-08-09 21:35:17 +00:00
|
|
|
#define USE_FAST_VIEWROT
|
|
|
|
#ifdef USE_FAST_VIEWROT
|
|
|
|
// VIEW_ROT = LARC_TO_SSG * ( VIEWo * VIEW_OFFSET )
|
|
|
|
// This takes advantage of the fact that VIEWo and VIEW_OFFSET
|
|
|
|
// only have entries in the upper 3x3 block
|
|
|
|
// and that LARC_TO_SSG is just a shift of rows NHV
|
|
|
|
inline static void fgMakeViewRot( sgMat4 dst, const sgMat4 m1, const sgMat4 m2 )
|
|
|
|
{
|
|
|
|
for ( int j = 0 ; j < 3 ; j++ ) {
|
|
|
|
dst[2][j] = m2[0][0] * m1[0][j] +
|
|
|
|
m2[0][1] * m1[1][j] +
|
|
|
|
m2[0][2] * m1[2][j];
|
|
|
|
|
|
|
|
dst[0][j] = m2[1][0] * m1[0][j] +
|
|
|
|
m2[1][1] * m1[1][j] +
|
|
|
|
m2[1][2] * m1[2][j];
|
|
|
|
|
|
|
|
dst[1][j] = m2[2][0] * m1[0][j] +
|
|
|
|
m2[2][1] * m1[1][j] +
|
|
|
|
m2[2][2] * m1[2][j];
|
|
|
|
}
|
|
|
|
dst[0][3] =
|
|
|
|
dst[1][3] =
|
|
|
|
dst[2][3] =
|
|
|
|
dst[3][0] =
|
|
|
|
dst[3][1] =
|
|
|
|
dst[3][2] = SG_ZERO;
|
|
|
|
dst[3][3] = SG_ONE;
|
|
|
|
}
|
|
|
|
#endif
|
1998-05-16 13:08:34 +00:00
|
|
|
|
1998-04-25 20:24:00 +00:00
|
|
|
// Initialize a view structure
|
1998-12-09 18:50:12 +00:00
|
|
|
void FGView::Init( void ) {
|
1998-11-06 21:17:31 +00:00
|
|
|
FG_LOG( FG_VIEW, FG_INFO, "Initializing View parameters" );
|
1997-12-30 20:47:34 +00:00
|
|
|
|
1998-05-16 13:08:34 +00:00
|
|
|
view_offset = 0.0;
|
|
|
|
goal_view_offset = 0.0;
|
1999-10-04 04:43:09 +00:00
|
|
|
sgSetVec3( pilot_offset, 0.0, 0.0, 0.0 );
|
1998-05-27 02:24:05 +00:00
|
|
|
|
1998-11-16 13:59:58 +00:00
|
|
|
winWidth = current_options.get_xsize();
|
|
|
|
winHeight = current_options.get_ysize();
|
1999-03-08 21:56:37 +00:00
|
|
|
|
David Megginson writes:
I have a scrollable panel working (it didn't take long in the end). A
panel can now be much wider or higher than the available area, and the
user can scroll around using [Shift]F5, [Shift]F6, [Shift]F7, and
[Shift]F8. The user can also scroll the panel down to get a bigger
external view. Mouse clicks seem still to be working correctly.
To set the panel's (virtual) height and width, use the panel file's /w
and /h properties in a panel XML file; to set the initial x- and y-
offsets (untested), use the panel file's /x-offset and /y-offset
properties; to set the initial height of the external view (untested
and optional), use the panel file's /view-height property. Note that
none of these show up in the regular FGFS property manager.
Unfortunately, these patches will not affect your initialization
problems with the property manager -- I'm having a hard time tracking
them down because I cannot reproduce them.
I have also made some patches to main.cxx and views.cxx to do two
things:
1. Expand or shrink the external view as the panel moves up and down.
2. Set the window ratio correctly, so that we don't get an oval sun
and flat clouds when the panel is visible (the problem before was
integer division, so I added casts).
Unfortunately, the window ratio is not set properly at start-up --
there are too many dependencies, and I haven't figured that part out
yet. As soon as you hide and redisplay the panel or move it
vertically (i.e. force fgReshape to be called), you'll see the correct
ratio.
2000-10-06 21:16:01 +00:00
|
|
|
set_win_ratio( winHeight / winWidth );
|
1999-03-08 21:56:37 +00:00
|
|
|
|
2000-08-09 21:35:17 +00:00
|
|
|
#ifndef USE_FAST_VIEWROT
|
1999-09-28 22:43:52 +00:00
|
|
|
// This never changes -- NHV
|
1999-10-04 04:02:10 +00:00
|
|
|
LARC_TO_SSG[0][0] = 0.0;
|
|
|
|
LARC_TO_SSG[0][1] = 1.0;
|
|
|
|
LARC_TO_SSG[0][2] = -0.0;
|
|
|
|
LARC_TO_SSG[0][3] = 0.0;
|
|
|
|
|
|
|
|
LARC_TO_SSG[1][0] = 0.0;
|
|
|
|
LARC_TO_SSG[1][1] = 0.0;
|
|
|
|
LARC_TO_SSG[1][2] = 1.0;
|
|
|
|
LARC_TO_SSG[1][3] = 0.0;
|
1998-05-27 02:24:05 +00:00
|
|
|
|
1999-10-04 04:02:10 +00:00
|
|
|
LARC_TO_SSG[2][0] = 1.0;
|
|
|
|
LARC_TO_SSG[2][1] = -0.0;
|
|
|
|
LARC_TO_SSG[2][2] = 0.0;
|
|
|
|
LARC_TO_SSG[2][3] = 0.0;
|
1999-09-28 22:43:52 +00:00
|
|
|
|
1999-10-04 04:02:10 +00:00
|
|
|
LARC_TO_SSG[3][0] = 0.0;
|
|
|
|
LARC_TO_SSG[3][1] = 0.0;
|
|
|
|
LARC_TO_SSG[3][2] = 0.0;
|
|
|
|
LARC_TO_SSG[3][3] = 1.0;
|
2000-08-09 21:35:17 +00:00
|
|
|
#endif // USE_FAST_VIEWROT
|
|
|
|
|
1999-09-28 22:43:52 +00:00
|
|
|
force_update_fov_math();
|
1997-08-27 21:31:17 +00:00
|
|
|
}
|
|
|
|
|
2000-06-15 22:31:20 +00:00
|
|
|
|
|
|
|
#define USE_FAST_LOCAL
|
|
|
|
#ifdef USE_FAST_LOCAL
|
|
|
|
inline static void fgMakeLOCAL( sgMat4 dst, const double Theta,
|
|
|
|
const double Phi, const double Psi)
|
|
|
|
{
|
|
|
|
SGfloat cosTheta = (SGfloat) cos(Theta);
|
|
|
|
SGfloat sinTheta = (SGfloat) sin(Theta);
|
|
|
|
SGfloat cosPhi = (SGfloat) cos(Phi);
|
|
|
|
SGfloat sinPhi = (SGfloat) sin(Phi);
|
|
|
|
SGfloat sinPsi = (SGfloat) sin(Psi) ;
|
|
|
|
SGfloat cosPsi = (SGfloat) cos(Psi) ;
|
|
|
|
|
|
|
|
dst[0][0] = cosPhi * cosTheta;
|
|
|
|
dst[0][1] = sinPhi * cosPsi + cosPhi * -sinTheta * -sinPsi;
|
|
|
|
dst[0][2] = sinPhi * sinPsi + cosPhi * -sinTheta * cosPsi;
|
|
|
|
dst[0][3] = SG_ZERO;
|
|
|
|
|
|
|
|
dst[1][0] = -sinPhi * cosTheta;
|
|
|
|
dst[1][1] = cosPhi * cosPsi + -sinPhi * -sinTheta * -sinPsi;
|
|
|
|
dst[1][2] = cosPhi * sinPsi + -sinPhi * -sinTheta * cosPsi;
|
|
|
|
dst[1][3] = SG_ZERO ;
|
|
|
|
|
|
|
|
dst[2][0] = sinTheta;
|
|
|
|
dst[2][1] = cosTheta * -sinPsi;
|
|
|
|
dst[2][2] = cosTheta * cosPsi;
|
|
|
|
dst[2][3] = SG_ZERO;
|
|
|
|
|
|
|
|
dst[3][0] = SG_ZERO;
|
|
|
|
dst[3][1] = SG_ZERO;
|
|
|
|
dst[3][2] = SG_ZERO;
|
|
|
|
dst[3][3] = SG_ONE ;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2000-07-22 23:25:49 +00:00
|
|
|
|
1998-08-20 20:32:31 +00:00
|
|
|
// Update the view volume, position, and orientation
|
1999-09-09 00:16:28 +00:00
|
|
|
void FGView::UpdateViewParams( const FGInterface& f ) {
|
1998-08-20 20:32:31 +00:00
|
|
|
UpdateViewMath(f);
|
1998-11-09 23:39:22 +00:00
|
|
|
|
|
|
|
if ( ! current_options.get_panel_status() ) {
|
1999-09-03 00:27:48 +00:00
|
|
|
xglViewport(0, 0 , (GLint)(winWidth), (GLint)(winHeight) );
|
1998-11-09 23:39:22 +00:00
|
|
|
} else {
|
David Megginson writes:
I have a scrollable panel working (it didn't take long in the end). A
panel can now be much wider or higher than the available area, and the
user can scroll around using [Shift]F5, [Shift]F6, [Shift]F7, and
[Shift]F8. The user can also scroll the panel down to get a bigger
external view. Mouse clicks seem still to be working correctly.
To set the panel's (virtual) height and width, use the panel file's /w
and /h properties in a panel XML file; to set the initial x- and y-
offsets (untested), use the panel file's /x-offset and /y-offset
properties; to set the initial height of the external view (untested
and optional), use the panel file's /view-height property. Note that
none of these show up in the regular FGFS property manager.
Unfortunately, these patches will not affect your initialization
problems with the property manager -- I'm having a hard time tracking
them down because I cannot reproduce them.
I have also made some patches to main.cxx and views.cxx to do two
things:
1. Expand or shrink the external view as the panel moves up and down.
2. Set the window ratio correctly, so that we don't get an oval sun
and flat clouds when the panel is visible (the problem before was
integer division, so I added casts).
Unfortunately, the window ratio is not set properly at start-up --
there are too many dependencies, and I haven't figured that part out
yet. As soon as you hide and redisplay the panel or move it
vertically (i.e. force fgReshape to be called), you'll see the correct
ratio.
2000-10-06 21:16:01 +00:00
|
|
|
int view_h =
|
|
|
|
int((current_panel->getViewHeight() - current_panel->getYOffset())
|
|
|
|
* (winHeight / 768.0));
|
|
|
|
glViewport(0, (GLint)(winHeight - view_h),
|
|
|
|
(GLint)(winWidth), (GLint)(view_h) );
|
1998-11-09 23:39:22 +00:00
|
|
|
}
|
1998-08-20 20:32:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-09-28 22:43:52 +00:00
|
|
|
// convert sgMat4 to MAT3 and print
|
|
|
|
static void print_sgMat4( sgMat4 &in) {
|
1999-10-04 04:02:10 +00:00
|
|
|
int i, j;
|
1999-09-28 22:43:52 +00:00
|
|
|
for ( i = 0; i < 4; i++ ) {
|
|
|
|
for ( j = 0; j < 4; j++ ) {
|
1999-10-04 04:02:10 +00:00
|
|
|
printf("%10.4f ", in[i][j]);
|
1999-09-28 22:43:52 +00:00
|
|
|
}
|
1999-10-04 04:02:10 +00:00
|
|
|
cout << endl;
|
1999-09-28 22:43:52 +00:00
|
|
|
}
|
1999-04-03 04:21:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-04-25 20:24:00 +00:00
|
|
|
// Update the view parameters
|
1999-09-09 00:16:28 +00:00
|
|
|
void FGView::UpdateViewMath( const FGInterface& f ) {
|
1999-10-15 20:43:02 +00:00
|
|
|
|
1998-10-16 00:51:46 +00:00
|
|
|
Point3D p;
|
1999-10-04 04:02:10 +00:00
|
|
|
sgVec3 v0, minus_z, sgvec, forward;
|
|
|
|
sgMat4 VIEWo, TMP;
|
1998-05-16 13:08:34 +00:00
|
|
|
|
1998-12-11 20:26:25 +00:00
|
|
|
if ( update_fov ) {
|
1999-09-28 22:43:52 +00:00
|
|
|
ssgSetFOV( current_options.get_fov(),
|
|
|
|
current_options.get_fov() * win_ratio );
|
1998-09-08 15:04:33 +00:00
|
|
|
update_fov = false;
|
1998-05-27 02:24:05 +00:00
|
|
|
}
|
|
|
|
|
1998-10-16 00:51:46 +00:00
|
|
|
scenery.center = scenery.next_center;
|
1998-02-20 00:16:14 +00:00
|
|
|
|
1998-07-12 03:14:42 +00:00
|
|
|
// printf("scenery center = %.2f %.2f %.2f\n", scenery.center.x,
|
|
|
|
// scenery.center.y, scenery.center.z);
|
|
|
|
|
1998-04-25 20:24:00 +00:00
|
|
|
// calculate the cartesion coords of the current lat/lon/0 elev
|
1999-09-09 00:16:28 +00:00
|
|
|
p = Point3D( f.get_Longitude(),
|
|
|
|
f.get_Lat_geocentric(),
|
|
|
|
f.get_Sea_level_radius() * FEET_TO_METER );
|
1998-05-02 01:51:01 +00:00
|
|
|
|
2000-09-27 20:16:22 +00:00
|
|
|
cur_zero_elev = sgPolarToCart3d(p) - scenery.center;
|
1997-12-17 23:13:34 +00:00
|
|
|
|
1998-04-25 20:24:00 +00:00
|
|
|
// calculate view position in current FG view coordinate system
|
1998-07-12 03:14:42 +00:00
|
|
|
// p.lon & p.lat are already defined earlier, p.radius was set to
|
|
|
|
// the sea level radius, so now we add in our altitude.
|
1999-09-09 00:16:28 +00:00
|
|
|
if ( f.get_Altitude() * FEET_TO_METER >
|
1998-07-24 21:56:59 +00:00
|
|
|
(scenery.cur_elev + 0.5 * METER_TO_FEET) ) {
|
1999-09-09 00:16:28 +00:00
|
|
|
p.setz( p.radius() + f.get_Altitude() * FEET_TO_METER );
|
1998-07-12 03:14:42 +00:00
|
|
|
} else {
|
1998-10-16 00:51:46 +00:00
|
|
|
p.setz( p.radius() + scenery.cur_elev + 0.5 * METER_TO_FEET );
|
1998-07-12 03:14:42 +00:00
|
|
|
}
|
1998-05-02 01:51:01 +00:00
|
|
|
|
2000-09-27 20:16:22 +00:00
|
|
|
abs_view_pos = sgPolarToCart3d(p);
|
1999-04-03 04:21:01 +00:00
|
|
|
|
1998-10-16 00:51:46 +00:00
|
|
|
view_pos = abs_view_pos - scenery.center;
|
1997-08-27 21:31:17 +00:00
|
|
|
|
1999-02-05 21:28:09 +00:00
|
|
|
FG_LOG( FG_VIEW, FG_DEBUG, "Polar view pos = " << p );
|
|
|
|
FG_LOG( FG_VIEW, FG_DEBUG, "Absolute view pos = " << abs_view_pos );
|
|
|
|
FG_LOG( FG_VIEW, FG_DEBUG, "Relative view pos = " << view_pos );
|
1997-08-27 21:31:17 +00:00
|
|
|
|
1999-09-28 22:43:52 +00:00
|
|
|
// code to calculate LOCAL matrix calculated from Phi, Theta, and
|
|
|
|
// Psi (roll, pitch, yaw) in case we aren't running LaRCsim as our
|
|
|
|
// flight model
|
2000-06-15 22:31:20 +00:00
|
|
|
|
|
|
|
#ifdef USE_FAST_LOCAL
|
|
|
|
|
|
|
|
fgMakeLOCAL( LOCAL, f.get_Theta(), f.get_Phi(), -f.get_Psi() );
|
|
|
|
|
|
|
|
#else // USE_TEXT_BOOK_METHOD
|
|
|
|
|
1999-10-04 04:02:10 +00:00
|
|
|
sgVec3 rollvec;
|
|
|
|
sgSetVec3( rollvec, 0.0, 0.0, 1.0 );
|
|
|
|
sgMat4 PHI; // roll
|
|
|
|
sgMakeRotMat4( PHI, f.get_Phi() * RAD_TO_DEG, rollvec );
|
|
|
|
|
|
|
|
sgVec3 pitchvec;
|
|
|
|
sgSetVec3( pitchvec, 0.0, 1.0, 0.0 );
|
|
|
|
sgMat4 THETA; // pitch
|
|
|
|
sgMakeRotMat4( THETA, f.get_Theta() * RAD_TO_DEG, pitchvec );
|
|
|
|
|
2000-04-04 05:46:37 +00:00
|
|
|
// ROT = PHI * THETA
|
1999-10-04 04:02:10 +00:00
|
|
|
sgMat4 ROT;
|
2000-04-04 05:46:37 +00:00
|
|
|
// sgMultMat4( ROT, PHI, THETA );
|
|
|
|
sgCopyMat4( ROT, PHI );
|
|
|
|
sgPostMultMat4( ROT, THETA );
|
1999-10-04 04:02:10 +00:00
|
|
|
|
|
|
|
sgVec3 yawvec;
|
|
|
|
sgSetVec3( yawvec, 1.0, 0.0, 0.0 );
|
|
|
|
sgMat4 PSI; // pitch
|
|
|
|
sgMakeRotMat4( PSI, -f.get_Psi() * RAD_TO_DEG, yawvec );
|
|
|
|
|
2000-04-04 05:46:37 +00:00
|
|
|
// LOCAL = ROT * PSI
|
|
|
|
// sgMultMat4( LOCAL, ROT, PSI );
|
|
|
|
sgCopyMat4( LOCAL, ROT );
|
|
|
|
sgPostMultMat4( LOCAL, PSI );
|
2000-06-15 22:31:20 +00:00
|
|
|
|
|
|
|
#endif // YIKES
|
|
|
|
|
1999-10-04 04:02:10 +00:00
|
|
|
// cout << "LOCAL matrix" << endl;
|
|
|
|
// print_sgMat4( LOCAL );
|
1999-04-03 04:21:01 +00:00
|
|
|
|
1999-10-04 04:02:10 +00:00
|
|
|
sgMakeRotMat4( UP,
|
1999-09-09 00:16:28 +00:00
|
|
|
f.get_Longitude() * RAD_TO_DEG,
|
1999-06-18 16:12:17 +00:00
|
|
|
0.0,
|
1999-09-09 00:16:28 +00:00
|
|
|
-f.get_Latitude() * RAD_TO_DEG );
|
1999-06-18 16:12:17 +00:00
|
|
|
|
2000-06-15 22:31:20 +00:00
|
|
|
sgSetVec3( local_up, UP[0][0], UP[0][1], UP[0][2] );
|
2000-08-09 21:35:17 +00:00
|
|
|
// sgXformVec3( local_up, UP );
|
1999-10-03 18:49:39 +00:00
|
|
|
// cout << "Local Up = " << local_up[0] << "," << local_up[1] << ","
|
|
|
|
// << local_up[2] << endl;
|
1997-08-27 21:31:17 +00:00
|
|
|
|
1998-04-25 20:24:00 +00:00
|
|
|
// Alternative method to Derive local up vector based on
|
|
|
|
// *geodetic* coordinates
|
2000-09-27 20:16:22 +00:00
|
|
|
// alt_up = sgPolarToCart(FG_Longitude, FG_Latitude, 1.0);
|
1998-04-25 20:24:00 +00:00
|
|
|
// printf( " Alt Up = (%.4f, %.4f, %.4f)\n",
|
|
|
|
// alt_up.x, alt_up.y, alt_up.z);
|
1997-08-27 21:31:17 +00:00
|
|
|
|
2000-04-04 05:46:37 +00:00
|
|
|
// VIEWo = LOCAL * UP
|
|
|
|
// sgMultMat4( VIEWo, LOCAL, UP );
|
|
|
|
sgCopyMat4( VIEWo, LOCAL );
|
|
|
|
sgPostMultMat4( VIEWo, UP );
|
1999-10-04 04:02:10 +00:00
|
|
|
// cout << "VIEWo matrix" << endl;
|
|
|
|
// print_sgMat4( VIEWo );
|
1999-08-08 15:21:54 +00:00
|
|
|
|
2000-06-15 22:31:20 +00:00
|
|
|
// generate the sg view up and forward vectors
|
|
|
|
sgSetVec3( view_up, VIEWo[0][0], VIEWo[0][1], VIEWo[0][2] );
|
|
|
|
// cout << "view = " << view[0] << ","
|
|
|
|
// << view[1] << "," << view[2] << endl;
|
|
|
|
sgSetVec3( forward, VIEWo[2][0], VIEWo[2][1], VIEWo[2][2] );
|
|
|
|
// cout << "forward = " << forward[0] << ","
|
|
|
|
// << forward[1] << "," << forward[2] << endl;
|
1999-08-08 15:21:54 +00:00
|
|
|
|
1999-10-04 04:43:09 +00:00
|
|
|
// generate the pilot offset vector in world coordinates
|
|
|
|
sgVec3 pilot_offset_world;
|
2000-06-15 22:31:20 +00:00
|
|
|
sgSetVec3( pilot_offset_world,
|
1999-10-04 04:43:09 +00:00
|
|
|
pilot_offset[2], pilot_offset[1], -pilot_offset[0] );
|
2000-06-15 22:31:20 +00:00
|
|
|
sgXformVec3( pilot_offset_world, pilot_offset_world, VIEWo );
|
1999-10-04 04:43:09 +00:00
|
|
|
|
1999-08-08 15:21:54 +00:00
|
|
|
// generate the view offset matrix
|
1999-10-04 04:02:10 +00:00
|
|
|
sgMakeRotMat4( VIEW_OFFSET, view_offset * RAD_TO_DEG, view_up );
|
|
|
|
// cout << "VIEW_OFFSET matrix" << endl;
|
|
|
|
// print_sgMat4( VIEW_OFFSET );
|
2000-08-09 21:35:17 +00:00
|
|
|
sgXformVec3( view_forward, forward, VIEW_OFFSET );
|
|
|
|
// cout << "view_forward = " << view_forward[0] << ","
|
|
|
|
// << view_forward[1] << "," << view_forward[2] << endl;
|
1999-09-28 22:43:52 +00:00
|
|
|
|
2000-04-04 05:46:37 +00:00
|
|
|
// VIEW_ROT = LARC_TO_SSG * ( VIEWo * VIEW_OFFSET )
|
2000-08-09 21:35:17 +00:00
|
|
|
#ifdef USE_FAST_VIEWROT
|
|
|
|
fgMakeViewRot( VIEW_ROT, VIEW_OFFSET, VIEWo );
|
|
|
|
#else
|
|
|
|
// sgMultMat4( VIEW_ROT, VIEW_OFFSET, VIEWo );
|
|
|
|
// sgPreMultMat4( VIEW_ROT, LARC_TO_SSG );
|
2000-04-04 05:46:37 +00:00
|
|
|
sgCopyMat4( VIEW_ROT, VIEWo );
|
|
|
|
sgPostMultMat4( VIEW_ROT, VIEW_OFFSET );
|
|
|
|
sgPreMultMat4( VIEW_ROT, LARC_TO_SSG );
|
2000-08-09 21:35:17 +00:00
|
|
|
#endif
|
1999-10-04 04:02:10 +00:00
|
|
|
// cout << "VIEW_ROT matrix" << endl;
|
|
|
|
// print_sgMat4( VIEW_ROT );
|
1999-08-08 15:21:54 +00:00
|
|
|
|
2000-06-15 22:31:20 +00:00
|
|
|
sgVec3 trans_vec;
|
|
|
|
sgSetVec3( trans_vec,
|
|
|
|
view_pos.x() + pilot_offset_world[0],
|
|
|
|
view_pos.y() + pilot_offset_world[1],
|
|
|
|
view_pos.z() + pilot_offset_world[2] );
|
1997-08-27 21:31:17 +00:00
|
|
|
|
2000-04-04 05:46:37 +00:00
|
|
|
// VIEW = VIEW_ROT * TRANS
|
|
|
|
sgCopyMat4( VIEW, VIEW_ROT );
|
2000-06-15 22:31:20 +00:00
|
|
|
sgPostMultMat4ByTransMat4( VIEW, trans_vec );
|
1997-08-27 21:31:17 +00:00
|
|
|
|
2000-06-15 22:31:20 +00:00
|
|
|
//!!!!!!!!!!!!!!!!!!!
|
1999-10-15 20:43:02 +00:00
|
|
|
// THIS IS THE EXPERIMENTAL VIEWING ANGLE SHIFTER
|
|
|
|
// THE MAJORITY OF THE WORK IS DONE IN GUI.CXX
|
|
|
|
// this in gui.cxx for now just testing
|
2000-06-15 22:31:20 +00:00
|
|
|
extern float quat_mat[4][4];
|
|
|
|
sgPreMultMat4( VIEW, quat_mat);
|
|
|
|
// !!!!!!!!!! testing
|
1997-08-27 21:31:17 +00:00
|
|
|
|
1998-04-25 20:24:00 +00:00
|
|
|
// make a vector to the current view position
|
1999-10-03 18:49:39 +00:00
|
|
|
sgSetVec3( v0, view_pos.x(), view_pos.y(), view_pos.z() );
|
1998-04-25 20:24:00 +00:00
|
|
|
|
|
|
|
// Given a vector pointing straight down (-Z), map into onto the
|
|
|
|
// local plane representing "horizontal". This should give us the
|
|
|
|
// local direction for moving "south".
|
1999-10-03 18:49:39 +00:00
|
|
|
sgSetVec3( minus_z, 0.0, 0.0, -1.0 );
|
|
|
|
|
|
|
|
sgmap_vec_onto_cur_surface_plane(local_up, v0, minus_z, surface_south);
|
|
|
|
sgNormalizeVec3(surface_south);
|
|
|
|
// cout << "Surface direction directly south " << surface_south[0] << ","
|
|
|
|
// << surface_south[1] << "," << surface_south[2] << endl;
|
1997-12-22 04:14:28 +00:00
|
|
|
|
1998-04-25 20:24:00 +00:00
|
|
|
// now calculate the surface east vector
|
2000-08-09 21:35:17 +00:00
|
|
|
#define USE_FAST_SURFACE_EAST
|
|
|
|
#ifdef USE_FAST_SURFACE_EAST
|
|
|
|
sgVec3 local_down;
|
|
|
|
sgNegateVec3(local_down, local_up);
|
|
|
|
sgVectorProductVec3(surface_east, surface_south, local_down);
|
|
|
|
#else
|
|
|
|
#define USE_LOCAL_UP
|
|
|
|
#ifdef USE_LOCAL_UP
|
|
|
|
sgMakeRotMat4( TMP, FG_PI_2 * RAD_TO_DEG, local_up );
|
|
|
|
#else
|
1999-10-04 04:02:10 +00:00
|
|
|
sgMakeRotMat4( TMP, FG_PI_2 * RAD_TO_DEG, view_up );
|
2000-08-09 21:35:17 +00:00
|
|
|
#endif // USE_LOCAL_UP
|
1999-10-04 04:02:10 +00:00
|
|
|
// cout << "sgMat4 TMP" << endl;
|
|
|
|
// print_sgMat4( TMP );
|
|
|
|
sgXformVec3(surface_east, surface_south, TMP);
|
2000-08-09 21:35:17 +00:00
|
|
|
#endif // USE_FAST_SURFACE_EAST
|
|
|
|
// cout << "Surface direction directly east " << surface_east[0] << ","
|
1999-10-03 18:49:39 +00:00
|
|
|
// << surface_east[1] << "," << surface_east[2] << endl;
|
|
|
|
// cout << "Should be close to zero = "
|
|
|
|
// << sgScalarProductVec3(surface_south, surface_east) << endl;
|
1998-05-16 13:08:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-08-11 20:25:30 +00:00
|
|
|
void FGView::CurrentNormalInLocalPlane(sgVec3 dst, sgVec3 src) {
|
2000-08-09 21:35:17 +00:00
|
|
|
sgVec3 tmp;
|
|
|
|
sgSetVec3(tmp, src[0], src[1], src[2] );
|
|
|
|
sgMat4 TMP;
|
|
|
|
sgTransposeNegateMat4 ( TMP, UP ) ;
|
|
|
|
sgXformVec3(tmp, tmp, TMP);
|
|
|
|
sgSetVec3(dst, tmp[2], tmp[1], tmp[0] );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-05-16 13:08:34 +00:00
|
|
|
// Destructor
|
1998-12-09 18:50:12 +00:00
|
|
|
FGView::~FGView( void ) {
|
1997-08-27 21:31:17 +00:00
|
|
|
}
|