The view frustum is defined in plib apps using calls to ssgSetFOV() and
ssgSetNearFar(). This by default creates a symmetric view frustum which is typically what an application wants. However, to get control of the view frustum in order to build support for asymmetric view frustums, we need to wrap these calls with a bit of our own logic. This set of changes wraps all calls to ssgSetFOV() and ssgSetNearFar() with FGRenderer methods. I also standardized how the FGRenderer class is handled in globals.[ch]xx. This led to some cascading changes in a variety of source files. As I was working my way through the changes, I fixed a few warnings along the way.
This commit is contained in:
parent
7cc58da6a9
commit
40170cb722
14 changed files with 116 additions and 19 deletions
|
@ -35,6 +35,9 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#include <simgear/compiler.h>
|
#include <simgear/compiler.h>
|
||||||
|
|
||||||
|
#include <plib/sg.h>
|
||||||
|
|
||||||
#include <Environment/environment_mgr.hxx>
|
#include <Environment/environment_mgr.hxx>
|
||||||
#include <Environment/environment.hxx>
|
#include <Environment/environment.hxx>
|
||||||
#include <simgear/misc/sg_path.hxx>
|
#include <simgear/misc/sg_path.hxx>
|
||||||
|
@ -113,7 +116,7 @@ string ScheduleTime::getName(time_t dayStart)
|
||||||
//cerr << "Nr of items to process: " << nrItems << endl;
|
//cerr << "Nr of items to process: " << nrItems << endl;
|
||||||
if (nrItems > 0)
|
if (nrItems > 0)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < start.size(); i++)
|
for (unsigned int i = 0; i < start.size(); i++)
|
||||||
{
|
{
|
||||||
//cerr << i << endl;
|
//cerr << i << endl;
|
||||||
if ((dayStart >= start[i]) && (dayStart <= end[i]))
|
if ((dayStart >= start[i]) && (dayStart <= end[i]))
|
||||||
|
@ -209,8 +212,8 @@ void RunwayGroup::setActive(string aptId,
|
||||||
FGRunway rwy;
|
FGRunway rwy;
|
||||||
int activeRwys = rwyList.size(); // get the number of runways active
|
int activeRwys = rwyList.size(); // get the number of runways active
|
||||||
int nrOfPreferences;
|
int nrOfPreferences;
|
||||||
bool found = true;
|
// bool found = true;
|
||||||
double heading;
|
// double heading;
|
||||||
double hdgDiff;
|
double hdgDiff;
|
||||||
double crossWind;
|
double crossWind;
|
||||||
double tailWind;
|
double tailWind;
|
||||||
|
@ -335,7 +338,7 @@ void RunwayGroup::getActive(int i, string *name, string *type)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (nrActive == rwyList.size())
|
if (nrActive == (int)rwyList.size())
|
||||||
{
|
{
|
||||||
*name = rwyList[i].getRwyList(active);
|
*name = rwyList[i].getRwyList(active);
|
||||||
*type = rwyList[i].getType();
|
*type = rwyList[i].getType();
|
||||||
|
@ -851,14 +854,14 @@ void FGAirport::getParking (int id, double *lat, double* lon, double *heading)
|
||||||
|
|
||||||
FGParking *FGAirport::getParking(int i)
|
FGParking *FGAirport::getParking(int i)
|
||||||
{
|
{
|
||||||
if (i < parkings.size())
|
if (i < (int)parkings.size())
|
||||||
return &(parkings[i]);
|
return &(parkings[i]);
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
string FGAirport::getParkingName(int i)
|
string FGAirport::getParkingName(int i)
|
||||||
{
|
{
|
||||||
if (i < parkings.size() && i >= 0)
|
if (i < (int)parkings.size() && i >= 0)
|
||||||
return (parkings[i].getName());
|
return (parkings[i].getName());
|
||||||
else
|
else
|
||||||
return string("overflow");
|
return string("overflow");
|
||||||
|
@ -888,7 +891,7 @@ void FGAirport::endXML () {
|
||||||
}
|
}
|
||||||
|
|
||||||
void FGAirport::startElement (const char * name, const XMLAttributes &atts) {
|
void FGAirport::startElement (const char * name, const XMLAttributes &atts) {
|
||||||
const char * attval;
|
// const char *attval;
|
||||||
FGParking park;
|
FGParking park;
|
||||||
//cout << "Start element " << name << endl;
|
//cout << "Start element " << name << endl;
|
||||||
string attname;
|
string attname;
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
|
|
||||||
#include <Main/main.hxx>
|
#include <Main/main.hxx>
|
||||||
#include <Main/fg_props.hxx>
|
#include <Main/fg_props.hxx>
|
||||||
|
#include <Main/renderer.hxx>
|
||||||
#include <Aircraft/aircraft.hxx>
|
#include <Aircraft/aircraft.hxx>
|
||||||
|
|
||||||
#include "environment.hxx"
|
#include "environment.hxx"
|
||||||
|
|
|
@ -79,6 +79,7 @@
|
||||||
#include <Main/fg_io.hxx>
|
#include <Main/fg_io.hxx>
|
||||||
#include <Main/globals.hxx>
|
#include <Main/globals.hxx>
|
||||||
#include <Main/fg_props.hxx>
|
#include <Main/fg_props.hxx>
|
||||||
|
#include <Main/renderer.hxx>
|
||||||
#include <Main/viewmgr.hxx>
|
#include <Main/viewmgr.hxx>
|
||||||
|
|
||||||
#if defined( WIN32 ) && !defined( __CYGWIN__ ) && !defined(__MINGW32__)
|
#if defined( WIN32 ) && !defined( __CYGWIN__ ) && !defined(__MINGW32__)
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include <Main/globals.hxx>
|
#include <Main/globals.hxx>
|
||||||
#include <Main/fg_init.hxx>
|
#include <Main/fg_init.hxx>
|
||||||
#include <Main/fg_props.hxx>
|
#include <Main/fg_props.hxx>
|
||||||
|
#include <Main/renderer.hxx>
|
||||||
#include <Scenery/tilemgr.hxx>
|
#include <Scenery/tilemgr.hxx>
|
||||||
#include <Time/light.hxx>
|
#include <Time/light.hxx>
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include <simgear/misc/sg_path.hxx>
|
#include <simgear/misc/sg_path.hxx>
|
||||||
|
|
||||||
#include "globals.hxx"
|
#include "globals.hxx"
|
||||||
|
#include "renderer.hxx"
|
||||||
#include "viewmgr.hxx"
|
#include "viewmgr.hxx"
|
||||||
|
|
||||||
#include "fg_props.hxx"
|
#include "fg_props.hxx"
|
||||||
|
|
|
@ -42,8 +42,6 @@ SG_USING_STD( string );
|
||||||
typedef vector<string> string_list;
|
typedef vector<string> string_list;
|
||||||
|
|
||||||
|
|
||||||
#include "renderer.hxx"
|
|
||||||
|
|
||||||
// Forward declarations
|
// Forward declarations
|
||||||
|
|
||||||
// This file is included, directly or indirectly, almost everywhere in
|
// This file is included, directly or indirectly, almost everywhere in
|
||||||
|
@ -88,6 +86,7 @@ class FGPanel;
|
||||||
class FGTileMgr;
|
class FGTileMgr;
|
||||||
class FGViewMgr;
|
class FGViewMgr;
|
||||||
class FGViewer;
|
class FGViewer;
|
||||||
|
class FGRenderer;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -228,6 +228,7 @@ FGRenderer::init( void ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Update all Visuals (redraws anything graphics related)
|
// Update all Visuals (redraws anything graphics related)
|
||||||
void
|
void
|
||||||
FGRenderer::update( bool refresh_camera_settings ) {
|
FGRenderer::update( bool refresh_camera_settings ) {
|
||||||
|
@ -501,7 +502,7 @@ FGRenderer::update( bool refresh_camera_settings ) {
|
||||||
scene_farplane = 120000.0f;
|
scene_farplane = 120000.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssgSetNearFar( scene_nearplane, scene_farplane );
|
setNearFar( scene_nearplane, scene_farplane );
|
||||||
|
|
||||||
if ( draw_otw && skyblend ) {
|
if ( draw_otw && skyblend ) {
|
||||||
// draw the sky backdrop
|
// draw the sky backdrop
|
||||||
|
@ -517,8 +518,6 @@ FGRenderer::update( bool refresh_camera_settings ) {
|
||||||
// draw the ssg scene
|
// draw the ssg scene
|
||||||
glEnable( GL_DEPTH_TEST );
|
glEnable( GL_DEPTH_TEST );
|
||||||
|
|
||||||
ssgSetNearFar( scene_nearplane, scene_farplane );
|
|
||||||
|
|
||||||
if ( fgGetBool("/sim/rendering/wireframe") ) {
|
if ( fgGetBool("/sim/rendering/wireframe") ) {
|
||||||
// draw wire frame
|
// draw wire frame
|
||||||
glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
|
glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
|
||||||
|
@ -565,7 +564,7 @@ FGRenderer::update( bool refresh_camera_settings ) {
|
||||||
// the current view frustum will still be freed properly.
|
// the current view frustum will still be freed properly.
|
||||||
static int counter = 0;
|
static int counter = 0;
|
||||||
counter++;
|
counter++;
|
||||||
if (counter == 200) {
|
if (counter >= 200) {
|
||||||
sgFrustum f;
|
sgFrustum f;
|
||||||
f.setFOV(360, 360);
|
f.setFOV(360, 360);
|
||||||
// No need to put the near plane too close;
|
// No need to put the near plane too close;
|
||||||
|
@ -584,7 +583,9 @@ FGRenderer::update( bool refresh_camera_settings ) {
|
||||||
|
|
||||||
// draw runway lighting
|
// draw runway lighting
|
||||||
glFogf (GL_FOG_DENSITY, rwy_exp2_punch_through);
|
glFogf (GL_FOG_DENSITY, rwy_exp2_punch_through);
|
||||||
ssgSetNearFar( scene_nearplane, scene_farplane );
|
|
||||||
|
// CLO - 02/25/2005 - DO WE NEED THIS extra fgSetNearFar()?
|
||||||
|
// fgSetNearFar( scene_nearplane, scene_farplane );
|
||||||
|
|
||||||
if ( enhanced_lighting ) {
|
if ( enhanced_lighting ) {
|
||||||
|
|
||||||
|
@ -794,8 +795,8 @@ FGRenderer::resize( int width, int height ) {
|
||||||
set_aspect_ratio((float)view_h / (float)width);
|
set_aspect_ratio((float)view_h / (float)width);
|
||||||
}
|
}
|
||||||
|
|
||||||
ssgSetFOV( viewmgr->get_current_view()->get_h_fov(),
|
setFOV( viewmgr->get_current_view()->get_h_fov(),
|
||||||
viewmgr->get_current_view()->get_v_fov() );
|
viewmgr->get_current_view()->get_v_fov() );
|
||||||
|
|
||||||
#ifdef FG_USE_CLOUDS_3D
|
#ifdef FG_USE_CLOUDS_3D
|
||||||
sgClouds3d->Resize( viewmgr->get_current_view()->get_h_fov(),
|
sgClouds3d->Resize( viewmgr->get_current_view()->get_h_fov(),
|
||||||
|
@ -808,4 +809,69 @@ FGRenderer::resize( int width, int height ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// These are wrapper functions around ssgSetNearFar() and ssgSetFOV()
|
||||||
|
// which will post process and rewrite the resulting frustum if we
|
||||||
|
// want to do asymmetric view frustums.
|
||||||
|
|
||||||
|
static void fgHackFrustum() {
|
||||||
|
|
||||||
|
/* experiment in assymetric view frustums */
|
||||||
|
sgFrustum *f = ssgGetFrustum();
|
||||||
|
cout << " l = " << f->getLeft()
|
||||||
|
<< " r = " << f->getRight()
|
||||||
|
<< " b = " << f->getBot()
|
||||||
|
<< " t = " << f->getTop()
|
||||||
|
<< " n = " << f->getNear()
|
||||||
|
<< " f = " << f->getFar()
|
||||||
|
<< endl;
|
||||||
|
static double incr = 0.0;
|
||||||
|
double factor = (sin(incr) + 1.0) / 2.0; // map to [0-1]
|
||||||
|
double w = (f->getRight() - f->getLeft()) / 2.0;
|
||||||
|
double l = f->getLeft() + w * factor;
|
||||||
|
double r = l + w;
|
||||||
|
ssgSetFrustum(l, r, f->getBot(), f->getTop(), f->getNear(), f->getFar());
|
||||||
|
incr += 0.001;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// we need some static storage space for these values. However, we
|
||||||
|
// can't store it in a renderer class object because the functions
|
||||||
|
// that manipulate these are static. They are static so they can
|
||||||
|
// interface to the display callback system. There's probably a
|
||||||
|
// better way, there has to be a better way, but I'm not seeing it
|
||||||
|
// right now.
|
||||||
|
static float width, height, near, far;
|
||||||
|
|
||||||
|
|
||||||
|
/** FlightGear code should use this routine to set the FOV rather than
|
||||||
|
* calling the ssg routine directly
|
||||||
|
*/
|
||||||
|
void FGRenderer::setFOV( float w, float h ) {
|
||||||
|
width = w;
|
||||||
|
height = h;
|
||||||
|
|
||||||
|
// fully specify the view frustum before hacking it (so we don't
|
||||||
|
// accumulate hacked effects
|
||||||
|
ssgSetFOV( w, h );
|
||||||
|
ssgSetNearFar( near, far );
|
||||||
|
|
||||||
|
fgHackFrustum();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** FlightGear code should use this routine to set the Near/Far clip
|
||||||
|
* planes rather than calling the ssg routine directly
|
||||||
|
*/
|
||||||
|
void FGRenderer::setNearFar( float n, float f ) {
|
||||||
|
near = n;
|
||||||
|
far = f;
|
||||||
|
|
||||||
|
// fully specify the view frustum before hacking it (so we don't
|
||||||
|
// accumulate hacked effects
|
||||||
|
ssgSetNearFar( n, f );
|
||||||
|
ssgSetFOV( width, height );
|
||||||
|
|
||||||
|
fgHackFrustum();
|
||||||
|
}
|
||||||
|
|
||||||
// end of renderer.cxx
|
// end of renderer.cxx
|
||||||
|
|
|
@ -18,6 +18,7 @@ extern bool glPointParameterIsSupported;
|
||||||
class FGRenderer {
|
class FGRenderer {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
FGRenderer();
|
FGRenderer();
|
||||||
~FGRenderer();
|
~FGRenderer();
|
||||||
|
|
||||||
|
@ -31,6 +32,18 @@ public:
|
||||||
// renderer which needs to set the view frustum itself.
|
// renderer which needs to set the view frustum itself.
|
||||||
static void update( bool refresh_camera_settings );
|
static void update( bool refresh_camera_settings );
|
||||||
inline static void update() { update( true ); }
|
inline static void update() { update( true ); }
|
||||||
|
|
||||||
|
|
||||||
|
/** FlightGear code should use this routine to set the FOV rather
|
||||||
|
* than calling the ssg routine directly
|
||||||
|
*/
|
||||||
|
static void setFOV( float w, float h );
|
||||||
|
|
||||||
|
|
||||||
|
/** FlightGear code should use this routine to set the Near/Far
|
||||||
|
* clip planes rather than calling the ssg routine directly
|
||||||
|
*/
|
||||||
|
static void setNearFar( float n, float f );
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
|
|
||||||
#include <Main/globals.hxx>
|
#include <Main/globals.hxx>
|
||||||
#include <Main/fg_props.hxx>
|
#include <Main/fg_props.hxx>
|
||||||
|
#include <Main/renderer.hxx>
|
||||||
#include <Main/viewmgr.hxx>
|
#include <Main/viewmgr.hxx>
|
||||||
#include <Main/viewer.hxx>
|
#include <Main/viewer.hxx>
|
||||||
#include <Scenery/scenery.hxx>
|
#include <Scenery/scenery.hxx>
|
||||||
|
@ -120,7 +121,7 @@ FGAircraftModel::draw ()
|
||||||
if (_aircraft->getVisible() && is_internal) {
|
if (_aircraft->getVisible() && is_internal) {
|
||||||
glClearDepth(1);
|
glClearDepth(1);
|
||||||
glClear(GL_DEPTH_BUFFER_BIT);
|
glClear(GL_DEPTH_BUFFER_BIT);
|
||||||
ssgSetNearFar(_nearplane, _farplane);
|
FGRenderer::setNearFar(_nearplane, _farplane);
|
||||||
ssgCullAndDraw(_scene);
|
ssgCullAndDraw(_scene);
|
||||||
_selector->select(0);
|
_selector->select(0);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -33,9 +33,13 @@
|
||||||
# include <fcntl.h>
|
# include <fcntl.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
#include STL_STRING
|
#include STL_STRING
|
||||||
|
|
||||||
#include <simgear/debug/logstream.hxx>
|
#include <simgear/debug/logstream.hxx>
|
||||||
|
#include <simgear/misc/sg_path.hxx>
|
||||||
|
|
||||||
#include <Main/fg_props.hxx>
|
#include <Main/fg_props.hxx>
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,8 @@
|
||||||
|
|
||||||
#include <plib/netChat.h>
|
#include <plib/netChat.h>
|
||||||
|
|
||||||
|
#include <simgear/misc/sg_path.hxx>
|
||||||
|
|
||||||
#include <Main/fg_props.hxx>
|
#include <Main/fg_props.hxx>
|
||||||
|
|
||||||
#include "protocol.hxx"
|
#include "protocol.hxx"
|
||||||
|
|
|
@ -33,9 +33,13 @@
|
||||||
# include <fcntl.h>
|
# include <fcntl.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
#include STL_STRING
|
#include STL_STRING
|
||||||
|
|
||||||
#include <simgear/debug/logstream.hxx>
|
#include <simgear/debug/logstream.hxx>
|
||||||
|
#include <simgear/misc/sg_path.hxx>
|
||||||
|
|
||||||
#include <Main/fg_props.hxx>
|
#include <Main/fg_props.hxx>
|
||||||
|
|
||||||
|
@ -382,7 +386,6 @@ bool FGATCOutput::open( int lock_fd ) {
|
||||||
/////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
bool FGATCOutput::do_lamps() {
|
bool FGATCOutput::do_lamps() {
|
||||||
|
|
||||||
if ( lamps_out_node != NULL ) {
|
if ( lamps_out_node != NULL ) {
|
||||||
for ( int i = 0; i < lamps_out_node->nChildren(); ++i ) {
|
for ( int i = 0; i < lamps_out_node->nChildren(); ++i ) {
|
||||||
// read the next config entry from the property tree
|
// read the next config entry from the property tree
|
||||||
|
|
|
@ -12,9 +12,10 @@
|
||||||
#include <simgear/compiler.h>
|
#include <simgear/compiler.h>
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
SG_USING_STD(vector);
|
SG_USING_STD(vector);
|
||||||
|
|
||||||
|
#include <plib/ssg.h>
|
||||||
|
|
||||||
class ssgEntity;
|
class ssgEntity;
|
||||||
class ssgBranch;
|
class ssgBranch;
|
||||||
|
|
||||||
|
|
|
@ -58,6 +58,7 @@ SG_USING_STD(string);
|
||||||
#include <Main/main.hxx>
|
#include <Main/main.hxx>
|
||||||
#include <Main/globals.hxx>
|
#include <Main/globals.hxx>
|
||||||
#include <Main/fg_props.hxx>
|
#include <Main/fg_props.hxx>
|
||||||
|
#include <Main/renderer.hxx>
|
||||||
#include <Main/viewer.hxx>
|
#include <Main/viewer.hxx>
|
||||||
|
|
||||||
#include "light.hxx"
|
#include "light.hxx"
|
||||||
|
|
Loading…
Reference in a new issue