1
0
Fork 0

Check point ... making progress with a FGViewerLookAt class so we can

more easily do nifty external views.
This commit is contained in:
curt 2000-10-26 18:10:28 +00:00
parent 0175b4cd25
commit 35819b8c4d
9 changed files with 72 additions and 96 deletions

View file

@ -44,6 +44,7 @@ fgfs_SOURCES = \
save.cxx save.hxx \
splash.cxx splash.hxx \
viewer.cxx viewer.hxx \
viewer_lookat.cxx viewer_lookat.hxx \
viewer_rph.cxx viewer_rph.hxx
fgfs_LDADD = \

View file

@ -118,6 +118,9 @@ ssgTransform *ship_pos = NULL;
#include "keyboard.hxx"
#include "splash.hxx"
// temporary?
#include "viewer_lookat.hxx"
FGViewerLookAt *tv;
// -dw- use custom sioux settings so I can see output window
#ifdef macintosh
@ -336,6 +339,38 @@ void fgRenderFrame( void ) {
cur_fdm_state->get_Theta(),
cur_fdm_state->get_Psi() );
// this is a test, we are trying to match RPH and LookAt
// matrices
tv->set_geod_view_pos( cur_fdm_state->get_Longitude(),
cur_fdm_state->get_Lat_geocentric(),
cur_fdm_state->get_Altitude() *
FEET_TO_METER );
tv->set_sea_level_radius( cur_fdm_state->get_Sea_level_radius() *
FEET_TO_METER );
tv->set_view_forward( globals->get_current_view()->get_view_forward() );
tv->set_view_up( globals->get_current_view()->get_view_up() );
sgMat4 rph;
sgCopyMat4( rph, globals->get_current_view()->get_VIEW() );
cout << "RPH Matrix = " << endl;
int i, j;
for ( i = 0; i < 4; i++ ) {
for ( j = 0; j < 4; j++ ) {
printf("%10.4f ", rph[i][j]);
}
cout << endl;
}
sgMat4 la;
sgCopyMat4( la, tv->get_VIEW() );
cout << "LookAt Matrix = " << endl;
for ( i = 0; i < 4; i++ ) {
for ( j = 0; j < 4; j++ ) {
printf("%10.4f ", la[i][j]);
}
cout << endl;
}
// update view volume parameters
// cout << "before pilot_view update" << endl;
if ( globals->get_options()->get_view_mode() ==
@ -480,7 +515,7 @@ void fgRenderFrame( void ) {
thesky->reposition( globals->get_current_view()->get_view_pos(),
globals->get_current_view()->get_zero_elev(),
globals->get_current_view()->get_local_up(),
globals->get_current_view()->get_world_up(),
cur_fdm_state->get_Longitude(),
cur_fdm_state->get_Latitude(),
cur_fdm_state->get_Altitude() * FEET_TO_METER,
@ -1181,13 +1216,6 @@ void fgReshape( int width, int height ) {
ssgSetFOV(fov, fov * globals->get_options()->get_win_ratio());
fgHUDReshape();
if ( idle_state == 1000 ) {
// yes we've finished all our initializations and are running
// the main loop, so this will now work without seg faulting
// the system.
// globals->get_current_view()->UpdateViewParams();
}
}
@ -1342,8 +1370,8 @@ int main( int argc, char **argv ) {
FGViewerRPH *pv = new FGViewerRPH;
globals->set_current_view( pv );
// FGViewer *cv = new FGViewer;
// globals->set_current_view( cv );
tv = new FGViewerLookAt;
tv->init();
// Scan the config file(s) and command line options to see if
// fg_root was specified (ignore all other options for now)
@ -1582,14 +1610,6 @@ void fgLoadDCS(void) {
string obj_filename;
FGPath tile_path( globals->get_options()->get_fg_root());
tile_path.append( "Scenery" );
tile_path.append( "Objects.txt" );
fg_gzifstream in( tile_path.str() );
if ( ! in.is_open() ) {
FG_LOG( FG_TERRAIN, FG_ALERT, "Cannot open file: " << tile_path.str() );
}
FGPath modelpath( globals->get_options()->get_fg_root() );
modelpath.append( "Models" );
modelpath.append( "Geometry" );

View file

@ -28,15 +28,8 @@
# include <config.h>
#endif
#include <plib/ssg.h> // plib include
#include <simgear/constants.h>
#include <simgear/debug/logstream.hxx>
#include <simgear/math/point3d.hxx>
#include <simgear/math/polar3d.hxx>
#include <simgear/math/vector.hxx>
#include "globals.hxx"
#include "viewer.hxx"
@ -46,38 +39,6 @@ FGViewer::FGViewer( void )
}
#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
// Initialize a view structure
void FGViewer::init( void ) {
FG_LOG( FG_VIEW, FG_ALERT, "Shouldn't ever see this" );

View file

@ -31,7 +31,6 @@
#endif
#include <simgear/compiler.h>
#include <simgear/timing/sg_time.hxx>
#include <plib/sg.h> // plib include
@ -53,6 +52,9 @@ protected:
// the goal view offset angle (used for smooth view changes)
double goal_view_offset;
// geodetic view position
sgdVec3 geod_view_pos;
// absolute view position in earth coordinates
sgdVec3 abs_view_pos;
@ -93,9 +95,9 @@ protected:
// with sun)
sgVec3 surface_east;
// local up vector (normal to the plane tangent to the earth's
// world up vector (normal to the plane tangent to the earth's
// surface at the spot we are directly above
sgVec3 local_up;
sgVec3 world_up;
// sg versions of our friendly matrices
sgMat4 VIEW, VIEW_ROT, UP;
@ -132,6 +134,13 @@ public:
set_dirty();
goal_view_offset = a;
}
inline void set_geod_view_pos( double lon, double lat, double alt ) {
// data should be in radians and meters asl
set_dirty();
// cout << "set_geod_view_pos = " << lon << ", " << lat << ", " << alt
// << endl;
sgdSetVec3( geod_view_pos, lon, lat, alt );
}
inline void set_pilot_offset( float x, float y, float z ) {
set_dirty();
sgSetVec3( pilot_offset, x, y, z );
@ -148,6 +157,7 @@ public:
inline bool is_dirty() const { return dirty; }
inline double get_view_offset() const { return view_offset; }
inline double get_goal_view_offset() const { return goal_view_offset; }
inline double *get_geod_view_pos() { return geod_view_pos; }
inline float *get_pilot_offset() { return pilot_offset; }
inline double get_sea_level_radius() const { return sea_level_radius; }
@ -174,9 +184,9 @@ public:
if ( dirty ) { update(); }
return surface_east;
}
inline float *get_local_up() {
inline float *get_world_up() {
if ( dirty ) { update(); }
return local_up;
return world_up;
}
inline const sgVec4 *get_VIEW() {
if ( dirty ) { update(); }

View file

@ -37,12 +37,10 @@
#include <simgear/math/polar3d.hxx>
#include <simgear/math/vector.hxx>
#include <Aircraft/aircraft.hxx>
#include <Cockpit/panel.hxx>
#include <Scenery/scenery.hxx>
#include "globals.hxx"
#include "viewer.hxx"
#include "viewer_rph.hxx"
// Constructor
@ -257,12 +255,12 @@ void FGViewerRPH::update() {
0.0,
-geod_view_pos[1] * RAD_TO_DEG );
sgSetVec3( local_up, UP[0][0], UP[0][1], UP[0][2] );
// sgXformVec3( local_up, UP );
// cout << "Local Up = " << local_up[0] << "," << local_up[1] << ","
// << local_up[2] << endl;
sgSetVec3( world_up, UP[0][0], UP[0][1], UP[0][2] );
// sgXformVec3( world_up, UP );
// cout << "World Up = " << world_up[0] << "," << world_up[1] << ","
// << world_up[2] << endl;
// Alternative method to Derive local up vector based on
// Alternative method to Derive world up vector based on
// *geodetic* coordinates
// alt_up = sgPolarToCart(FG_Longitude, FG_Latitude, 1.0);
// printf( " Alt Up = (%.4f, %.4f, %.4f)\n",
@ -330,7 +328,7 @@ void FGViewerRPH::update() {
// local direction for moving "south".
sgSetVec3( minus_z, 0.0, 0.0, -1.0 );
sgmap_vec_onto_cur_surface_plane(local_up, view_pos, minus_z,
sgmap_vec_onto_cur_surface_plane(world_up, view_pos, minus_z,
surface_south);
sgNormalizeVec3(surface_south);
// cout << "Surface direction directly south " << surface_south[0] << ","
@ -339,16 +337,11 @@ void FGViewerRPH::update() {
// now calculate the surface east vector
#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);
sgVec3 world_down;
sgNegateVec3(world_down, world_up);
sgVectorProductVec3(surface_east, surface_south, world_down);
#else
#define USE_LOCAL_UP
#ifdef USE_LOCAL_UP
sgMakeRotMat4( TMP, FG_PI_2 * RAD_TO_DEG, local_up );
#else
sgMakeRotMat4( TMP, FG_PI_2 * RAD_TO_DEG, view_up );
#endif // USE_LOCAL_UP
sgMakeRotMat4( TMP, FG_PI_2 * RAD_TO_DEG, world_up );
// cout << "sgMat4 TMP" << endl;
// print_sgMat4( TMP );
sgXformVec3(surface_east, surface_south, TMP);

View file

@ -40,9 +40,6 @@ class FGViewerRPH: public FGViewer {
private:
// geodetic view position
sgdVec3 geod_view_pos;
// view orientation (roll, pitch, heading)
sgVec3 rph;
@ -77,13 +74,6 @@ public:
//////////////////////////////////////////////////////////////////////
// setter functions
//////////////////////////////////////////////////////////////////////
inline void set_geod_view_pos( double lon, double lat, double alt ) {
// data should be in radians and meters asl
set_dirty();
// cout << "set_geod_view_pos = " << lon << ", " << lat << ", " << alt
// << endl;
sgdSetVec3( geod_view_pos, lon, lat, alt );
}
inline void set_rph( double r, double p, double h ) {
// data should be in radians
set_dirty();
@ -93,8 +83,9 @@ public:
//////////////////////////////////////////////////////////////////////
// accessor functions
//////////////////////////////////////////////////////////////////////
inline double *get_geod_view_pos() { return geod_view_pos; }
inline float *get_rph() { return rph; }
inline float *get_view_forward() { return view_forward; }
inline float *get_view_up() { return view_up; }
//////////////////////////////////////////////////////////////////////
// derived values accessor functions

View file

@ -206,7 +206,7 @@ bool FGTileMgr::current_elev_ssg( sgdVec3 abs_view_pos, sgVec3 view_pos ) {
} else {
FG_LOG( FG_TERRAIN, FG_INFO, "no terrain intersection" );
scenery.cur_elev = 0.0;
float *up = globals->get_current_view()->get_local_up();
float *up = globals->get_current_view()->get_world_up();
sgdSetVec3(scenery.cur_normal, up[0], up[1], up[2]);
return false;
}

View file

@ -374,7 +374,7 @@ void fgUpdateMoonPos( void ) {
// << ","<< l->moon_vec[2] << endl;
// calculate the moon's relative angle to local up
sgCopyVec3( nup, v->get_local_up() );
sgCopyVec3( nup, v->get_world_up() );
sgSetVec3( nmoon, l->fg_moonpos.x(), l->fg_moonpos.y(), l->fg_moonpos.z() );
sgNormalizeVec3(nup);
sgNormalizeVec3(nmoon);
@ -400,7 +400,7 @@ void fgUpdateMoonPos( void ) {
// earth's surface the moon is directly over, map into onto the
// local plane representing "horizontal".
sgmap_vec_onto_cur_surface_plane( v->get_local_up(), v->get_view_pos(),
sgmap_vec_onto_cur_surface_plane( v->get_world_up(), v->get_view_pos(),
v->get_to_moon(), surface_to_moon );
sgNormalizeVec3(surface_to_moon);
v->set_surface_to_moon( surface_to_moon[0], surface_to_moon[1],

View file

@ -281,7 +281,7 @@ void fgUpdateSunPos( void ) {
// << ","<< l->sun_vec[2] << endl;
// calculate the sun's relative angle to local up
sgCopyVec3( nup, v->get_local_up() );
sgCopyVec3( nup, v->get_world_up() );
sgSetVec3( nsun, l->fg_sunpos.x(), l->fg_sunpos.y(), l->fg_sunpos.z() );
sgNormalizeVec3(nup);
sgNormalizeVec3(nsun);
@ -306,7 +306,7 @@ void fgUpdateSunPos( void ) {
// earth's surface the sun is directly over, map into onto the
// local plane representing "horizontal".
sgmap_vec_onto_cur_surface_plane( v->get_local_up(), v->get_view_pos(),
sgmap_vec_onto_cur_surface_plane( v->get_world_up(), v->get_view_pos(),
v->get_to_sun(), surface_to_sun );
sgNormalizeVec3(surface_to_sun);
v->set_surface_to_sun( surface_to_sun[0], surface_to_sun[1],