more easily do nifty external views.
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 = \
#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
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() ==
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,
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();
- }
}
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)
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" );
# 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"
}
-#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" );
#endif
#include <simgear/compiler.h>
-#include <simgear/timing/sg_time.hxx>
#include <plib/sg.h> // plib include
// 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;
// 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;
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 );
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; }
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(); }
#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
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",
// 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] << ","
// 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);
private:
- // geodetic view position
- sgdVec3 geod_view_pos;
-
// view orientation (roll, pitch, heading)
sgVec3 rph;
//////////////////////////////////////////////////////////////////////
// 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();
//////////////////////////////////////////////////////////////////////
// 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
} 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;
}
// << ","<< 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);
// 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],
// << ","<< 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);
// 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],