1
0
Fork 0

Modified Files:

configure.ac src/AIModel/AIAircraft.cxx src/AIModel/AIBase.cxx
 	src/AIModel/AIBase.hxx src/AIModel/AICarrier.cxx
 	src/AIModel/AICarrier.hxx src/AIModel/AIManager.cxx
 	src/AIModel/AIManager.hxx src/ATC/AIEntity.cxx
 	src/ATC/AIEntity.hxx src/ATC/AIMgr.cxx src/ATC/AIMgr.hxx
 	src/ATC/ATCdisplay.cxx src/ATC/ATCdisplay.hxx
 	src/Cockpit/cockpit.cxx src/Cockpit/cockpit.hxx
 	src/Cockpit/hud.cxx src/Cockpit/hud.hxx
 	src/Cockpit/hud_rwy.cxx src/Cockpit/panel.cxx
 	src/Cockpit/panel.hxx src/Cockpit/built_in/FGMagRibbon.cxx
 	src/Cockpit/built_in/FGMagRibbon.hxx src/FDM/flight.cxx
 	src/FDM/groundcache.cxx src/FDM/groundcache.hxx
 	src/GUI/gui_funcs.cxx src/Input/input.cxx
 	src/Instrumentation/od_gauge.cxx
 	src/Instrumentation/od_gauge.hxx
 	src/Instrumentation/render_area_2d.cxx
 	src/Instrumentation/render_area_2d.hxx
 	src/Instrumentation/wxradar.cxx
 	src/Instrumentation/wxradar.hxx
 	src/Instrumentation/HUD/HUD.cxx
 	src/Instrumentation/HUD/HUD.hxx
 	src/Instrumentation/HUD/HUD_runway.cxx src/Main/Makefile.am
 	src/Main/main.cxx src/Main/renderer.cxx src/Main/renderer.hxx
 	src/Main/viewmgr.cxx src/Model/acmodel.cxx
 	src/Model/acmodel.hxx src/Model/model_panel.cxx
 	src/Model/model_panel.hxx src/Model/modelmgr.cxx
 	src/Model/modelmgr.hxx src/Model/panelnode.cxx
 	src/Model/panelnode.hxx src/Navaids/awynet.cxx
 	src/Scenery/Makefile.am src/Scenery/hitlist.cxx
 	src/Scenery/hitlist.hxx src/Scenery/newcache.cxx
 	src/Scenery/scenery.cxx src/Scenery/scenery.hxx
 	src/Scenery/tileentry.cxx src/Scenery/tileentry.hxx
 	src/Scenery/tilemgr.cxx src/Scripting/NasalSys.cxx
 	src/Scripting/NasalSys.hxx src/Time/light.cxx
	Big BLOB on the way to OSG.
This commit is contained in:
frohlich 2006-10-29 19:30:21 +00:00
parent 74faacdf16
commit b0f9d24f9d
63 changed files with 2032 additions and 2467 deletions

View file

@ -38,6 +38,14 @@ if test "x$with_plib" != "x" ; then
EXTRA_DIRS="${EXTRA_DIRS} $with_plib" EXTRA_DIRS="${EXTRA_DIRS} $with_plib"
fi fi
# specify the osg location
AC_ARG_WITH(osg, [ --with-osg=PREFIX Specify the prefix path to osg])
if test "x$with_osg" != "x" ; then
echo "osg prefix is $with_osg"
EXTRA_DIRS="${EXTRA_DIRS} $with_osg"
fi
dnl Determine an extra directories to add to include/lib search paths dnl Determine an extra directories to add to include/lib search paths
case "${host}" in case "${host}" in
*-apple-darwin* | *-*-mingw32*) *-apple-darwin* | *-*-mingw32*)

View file

@ -82,6 +82,11 @@ FGAIAircraft::FGAIAircraft(FGAISchedule *ref) :
use_perf_vs = true; use_perf_vs = true;
isTanker = false; isTanker = false;
no_roll = false;
tgt_speed = 0;
speed = 0;
groundTargetSpeed = 0;
// set heading and altitude locks // set heading and altitude locks
hdg_lock = false; hdg_lock = false;
alt_lock = false; alt_lock = false;

View file

@ -26,8 +26,8 @@
#include STL_STRING #include STL_STRING
#include <plib/sg.h> #include <osg/ref_ptr>
#include <plib/ssg.h> #include <osg/Node>
#include <simgear/math/point3d.hxx> #include <simgear/math/point3d.hxx>
#include <simgear/math/polar3d.hxx> #include <simgear/math/polar3d.hxx>
@ -73,7 +73,7 @@ FGAIBase::~FGAIBase() {
// Unregister that one at the scenery manager // Unregister that one at the scenery manager
if (globals->get_scenery()) { if (globals->get_scenery()) {
globals->get_scenery()->unregister_placement_transform(aip.getTransform()); globals->get_scenery()->unregister_placement_transform(aip.getTransform());
globals->get_scenery()->get_scene_graph()->removeKid(aip.getSceneGraph()); globals->get_scenery()->get_scene_graph()->removeChild(aip.getSceneGraph());
} }
if (props) { if (props) {
SGPropertyNode* parent = props->getParent(); SGPropertyNode* parent = props->getParent();
@ -135,11 +135,11 @@ bool FGAIBase::init() {
model = NULL; model = NULL;
} }
} }
if (model) { if (model.get()) {
aip.init( model ); aip.init( model.get() );
aip.setVisible(true); aip.setVisible(true);
invisible = false; invisible = false;
globals->get_scenery()->get_scene_graph()->addKid(aip.getSceneGraph()); globals->get_scenery()->get_scene_graph()->addChild(aip.getSceneGraph());
// Register that one at the scenery manager // Register that one at the scenery manager
globals->get_scenery()->register_placement_transform(aip.getTransform()); globals->get_scenery()->register_placement_transform(aip.getTransform());
fgSetString("/ai/models/model-added", props->getPath()); fgSetString("/ai/models/model-added", props->getPath());
@ -155,15 +155,16 @@ bool FGAIBase::init() {
} }
ssgBranch * FGAIBase::load3DModel(const string& fg_root, osg::Node*
const string &path, FGAIBase::load3DModel(const string& fg_root,
SGPropertyNode *prop_root, const string &path,
double sim_time_sec) SGPropertyNode *prop_root,
double sim_time_sec)
{ {
// some more code here to check whether a model with this name has already been loaded // some more code here to check whether a model with this name has already been loaded
// if not load it, otherwise, get the memory pointer and do something like // if not load it, otherwise, get the memory pointer and do something like
// SetModel as in ATC/AIEntity.cxx // SetModel as in ATC/AIEntity.cxx
ssgBranch *personality_branch = new SGPersonalityBranch; osg::Group* personality_branch = new SGPersonalityBranch;
model = manager->getModel(path); model = manager->getModel(path);
if (!(model)) { if (!(model)) {
@ -171,9 +172,9 @@ ssgBranch * FGAIBase::load3DModel(const string& fg_root,
path, path,
prop_root, prop_root,
sim_time_sec); sim_time_sec);
manager->setModel(path, model); manager->setModel(path, model.get());
} }
personality_branch->addKid( model ); personality_branch->addChild( model.get() );
return personality_branch; return personality_branch;
//return model; //return model;

View file

@ -118,7 +118,7 @@ protected:
double ht_diff; // value used by radar display instrument double ht_diff; // value used by radar display instrument
string model_path; //Path to the 3D model string model_path; //Path to the 3D model
ssgSharedPtr<ssgBranch> model; //The 3D model object osg::ref_ptr<osg::Node> model; //The 3D model object
SGModelPlacement aip; SGModelPlacement aip;
bool delete_me; bool delete_me;
bool invisible; bool invisible;
@ -173,7 +173,7 @@ public:
static const double lbs_to_slugs; static const double lbs_to_slugs;
inline double _getRange() { return range; }; inline double _getRange() { return range; };
ssgBranch * load3DModel(const string& fg_root, osg::Node* load3DModel(const string& fg_root,
const string &path, const string &path,
SGPropertyNode *prop_root, SGPropertyNode *prop_root,
double sim_time_sec); double sim_time_sec);

View file

@ -21,22 +21,79 @@
# include <config.h> # include <config.h>
#endif #endif
#include <algorithm>
#include <string> #include <string>
#include <vector> #include <vector>
#include <osg/NodeVisitor>
#include <simgear/math/SGMath.hxx> #include <simgear/math/SGMath.hxx>
#include <simgear/math/point3d.hxx>
#include <simgear/math/sg_geodesy.hxx> #include <simgear/math/sg_geodesy.hxx>
#include <simgear/scene/util/SGNodeMasks.hxx>
#include <math.h> #include <math.h>
#include <Main/util.hxx> #include <Main/util.hxx>
#include <Main/viewer.hxx> #include <Main/viewer.hxx>
#include "AICarrier.hxx" #include "AICarrier.hxx"
/** Value of earth radius (meters) */ class FGCarrierVisitor : public osg::NodeVisitor {
#define RADIUS_M SG_EQUATORIAL_RADIUS_M public:
FGCarrierVisitor(FGAICarrier* carrier,
const std::list<std::string>& wireObjects,
const std::list<std::string>& catapultObjects,
const std::list<std::string>& solidObjects) :
osg::NodeVisitor(osg::NodeVisitor::NODE_VISITOR,
osg::NodeVisitor::TRAVERSE_ALL_CHILDREN),
mWireObjects(wireObjects),
mCatapultObjects(catapultObjects),
mSolidObjects(solidObjects),
mFoundHot(false),
mCarrier(carrier)
{ }
virtual void apply(osg::Node& node)
{
osg::ref_ptr<osg::Referenced> oldUserData = mUserData;
bool oldFoundHot = mFoundHot;
mFoundHot = false;
if (std::find(mWireObjects.begin(), mWireObjects.end(), node.getName())
!= mWireObjects.end()) {
mFoundHot = true;
mUserData = FGAICarrierHardware::newWire(mCarrier);
}
if (std::find(mCatapultObjects.begin(), mCatapultObjects.end(), node.getName())
!= mCatapultObjects.end()) {
mFoundHot = true;
mUserData = FGAICarrierHardware::newCatapult(mCarrier);
}
if (std::find(mSolidObjects.begin(), mSolidObjects.end(), node.getName())
!= mSolidObjects.end()) {
mFoundHot = true;
mUserData = FGAICarrierHardware::newSolid(mCarrier);
}
node.setUserData(mUserData.get());
traverse(node);
mFoundHot = oldFoundHot || mFoundHot;
if (mFoundHot) {
node.setNodeMask(node.getNodeMask() | SG_NODEMASK_TERRAIN_BIT);
} else
node.setNodeMask(node.getNodeMask() & ~SG_NODEMASK_TERRAIN_BIT);
mUserData = oldUserData;
}
private:
std::list<std::string> mWireObjects;
std::list<std::string> mCatapultObjects;
std::list<std::string> mSolidObjects;
bool mFoundHot;
FGAICarrier* mCarrier;
osg::ref_ptr<osg::Referenced> mUserData;
};
FGAICarrier::FGAICarrier() : FGAIShip(otCarrier) { FGAICarrier::FGAICarrier() : FGAIShip(otCarrier) {
} }
@ -140,10 +197,10 @@ void FGAICarrier::setTACANChannelID(const string& id) {
TACAN_channel_id = id; TACAN_channel_id = id;
} }
void FGAICarrier::getVelocityWrtEarth(sgdVec3& v, sgdVec3& omega, sgdVec3& pivot) { void FGAICarrier::getVelocityWrtEarth(SGVec3d& v, SGVec3d& omega, SGVec3d& pivot) {
sgdCopyVec3(v, vel_wrt_earth.sg() ); v = vel_wrt_earth;
sgdCopyVec3(omega, rot_wrt_earth.sg() ); omega = rot_wrt_earth;
sgdCopyVec3(pivot, rot_pivot_wrt_earth.sg() ); pivot = rot_pivot_wrt_earth;
} }
void FGAICarrier::update(double dt) { void FGAICarrier::update(double dt) {
@ -263,14 +320,12 @@ bool FGAICarrier::init() {
// To avoid that every detail in a carrier 3D model will end into // To avoid that every detail in a carrier 3D model will end into
// the aircraft local cache, only set the HOT traversal bit on // the aircraft local cache, only set the HOT traversal bit on
// selected objects. // selected objects.
ssgEntity *sel = aip.getSceneGraph(); osg::Node* sel = aip.getSceneGraph();
// Clear the HOT traversal flag // Clear the HOT traversal flag
mark_nohot(sel);
// Selectively set that flag again for wires/cats/solid objects. // Selectively set that flag again for wires/cats/solid objects.
// Attach a pointer to this carrier class to those objects. // Attach a pointer to this carrier class to those objects.
mark_wires(sel, wire_objects); FGCarrierVisitor carrierVisitor(this, wire_objects, catapult_objects, solid_objects);
mark_cat(sel, catapult_objects); sel->accept(carrierVisitor);
mark_solid(sel, solid_objects);
_longitude_node = fgGetNode("/position/longitude-deg", true); _longitude_node = fgGetNode("/position/longitude-deg", true);
_latitude_node = fgGetNode("/position/latitude-deg", true); _latitude_node = fgGetNode("/position/latitude-deg", true);
@ -416,187 +471,6 @@ bool FGAICarrier::getParkPosition(const string& id, SGGeod& geodPos,
return false; return false;
} }
void FGAICarrier::mark_nohot(ssgEntity* e) {
if (e->isAKindOf(ssgTypeBranch())) {
ssgBranch* br = (ssgBranch*)e;
ssgEntity* kid;
for ( kid = br->getKid(0); kid != NULL ; kid = br->getNextKid() )
mark_nohot(kid);
br->clrTraversalMaskBits(SSGTRAV_HOT);
} else if (e->isAKindOf(ssgTypeLeaf())) {
e->clrTraversalMaskBits(SSGTRAV_HOT);
}
}
bool FGAICarrier::mark_wires(ssgEntity* e, const list<string>& wire_objects, bool mark) {
bool found = false;
if (e->isAKindOf(ssgTypeBranch())) {
ssgBranch* br = (ssgBranch*)e;
ssgEntity* kid;
list<string>::const_iterator it;
for (it = wire_objects.begin(); it != wire_objects.end(); ++it)
mark = mark || (e->getName() && (*it) == e->getName());
for ( kid = br->getKid(0); kid != NULL ; kid = br->getNextKid() )
found = mark_wires(kid, wire_objects, mark) || found;
if (found)
br->setTraversalMaskBits(SSGTRAV_HOT);
} else if (e->isAKindOf(ssgTypeLeaf())) {
list<string>::const_iterator it;
for (it = wire_objects.begin(); it != wire_objects.end(); ++it) {
if (mark || (e->getName() && (*it) == e->getName())) {
e->setTraversalMaskBits(SSGTRAV_HOT);
ssgBase* ud = e->getUserData();
if (ud) {
FGAICarrierHardware* ch = dynamic_cast<FGAICarrierHardware*>(ud);
if (ch) {
SG_LOG(SG_GENERAL, SG_WARN,
"AICarrier: Carrier hardware gets marked twice!\n"
" You have probably a whole branch marked as"
" a wire which also includes other carrier hardware.");
} else {
SG_LOG(SG_GENERAL, SG_ALERT,
"AICarrier: Found user data attached to a leaf node which "
"should be marked as a wire!\n ****Skipping!****");
}
} else {
e->setUserData( FGAICarrierHardware::newWire( this ) );
ssgLeaf *l = (ssgLeaf*)e;
if ( l->getNumLines() != 1 ) {
SG_LOG(SG_GENERAL, SG_ALERT,
"AICarrier: Found wires not modeled with exactly one line!");
}
found = true;
}
}
}
}
return found;
}
bool FGAICarrier::mark_solid(ssgEntity* e, const list<string>& solid_objects, bool mark) {
bool found = false;
if (e->isAKindOf(ssgTypeBranch())) {
ssgBranch* br = (ssgBranch*)e;
ssgEntity* kid;
list<string>::const_iterator it;
for (it = solid_objects.begin(); it != solid_objects.end(); ++it)
mark = mark || (e->getName() && (*it) == e->getName());
for ( kid = br->getKid(0); kid != NULL ; kid = br->getNextKid() )
found = mark_solid(kid, solid_objects, mark) || found;
if (found)
br->setTraversalMaskBits(SSGTRAV_HOT);
} else if (e->isAKindOf(ssgTypeLeaf())) {
list<string>::const_iterator it;
for (it = solid_objects.begin(); it != solid_objects.end(); ++it) {
if (mark || (e->getName() && (*it) == e->getName())) {
e->setTraversalMaskBits(SSGTRAV_HOT);
ssgBase* ud = e->getUserData();
if (ud) {
FGAICarrierHardware* ch = dynamic_cast<FGAICarrierHardware*>(ud);
if (ch) {
SG_LOG(SG_GENERAL, SG_WARN,
"AICarrier: Carrier hardware gets marked twice!\n"
" You have probably a whole branch marked solid"
" which also includes other carrier hardware.");
} else {
SG_LOG(SG_GENERAL, SG_ALERT,
"AICarrier: Found user data attached to a leaf node which "
"should be marked solid!\n ****Skipping!****");
}
} else {
e->setUserData( FGAICarrierHardware::newSolid( this ) );
found = true;
}
}
}
}
return found;
}
bool FGAICarrier::mark_cat(ssgEntity* e, const list<string>& cat_objects, bool mark) {
bool found = false;
if (e->isAKindOf(ssgTypeBranch())) {
ssgBranch* br = (ssgBranch*)e;
ssgEntity* kid;
list<string>::const_iterator it;
for (it = cat_objects.begin(); it != cat_objects.end(); ++it)
mark = mark || (e->getName() && (*it) == e->getName());
for ( kid = br->getKid(0); kid != NULL ; kid = br->getNextKid() )
found = mark_cat(kid, cat_objects, mark) || found;
if (found)
br->setTraversalMaskBits(SSGTRAV_HOT);
} else if (e->isAKindOf(ssgTypeLeaf())) {
list<string>::const_iterator it;
for (it = cat_objects.begin(); it != cat_objects.end(); ++it) {
if (mark || (e->getName() && (*it) == e->getName())) {
e->setTraversalMaskBits(SSGTRAV_HOT);
ssgBase* ud = e->getUserData();
if (ud) {
FGAICarrierHardware* ch = dynamic_cast<FGAICarrierHardware*>(ud);
if (ch) {
SG_LOG(SG_GENERAL, SG_WARN,
"AICarrier: Carrier hardware gets marked twice!\n"
"You have probably a whole branch marked as"
"a catapult which also includes other carrier hardware.");
} else {
SG_LOG(SG_GENERAL, SG_ALERT,
"AICarrier: Found user data attached to a leaf node which "
"should be marked as a catapult!\n ****Skipping!****");
}
} else {
e->setUserData( FGAICarrierHardware::newCatapult( this ) );
ssgLeaf *l = (ssgLeaf*)e;
if ( l->getNumLines() != 1 ) {
SG_LOG(SG_GENERAL, SG_ALERT,
"AICarrier: Found a cat not modeled with exactly "
"one line!");
} else {
// Now some special code to make sure the cat points in the right
// direction. The 0 index must be the backward end, the 1 index
// the forward end.
// Forward is positive x-direction in our 3D model, also the model
// as such is flattened when it is loaded, so we do not need to
// care for transforms ...
short v[2];
l->getLine(0, v, v+1 );
SGVec3f ends[2];
for (int k=0; k<2; ++k)
sgCopyVec3( ends[k].sg(), l->getVertex( v[k] ) );
// When the 1 end is behind the 0 end, swap the coordinates.
if (ends[0][0] < ends[1][0]) {
sgCopyVec3( l->getVertex( v[0] ), ends[1].sg() );
sgCopyVec3( l->getVertex( v[1] ), ends[0].sg() );
}
found = true;
}
}
}
}
}
return found;
}
// find relative wind // find relative wind
void FGAICarrier::UpdateWind( double dt) { void FGAICarrier::UpdateWind( double dt) {
@ -746,12 +620,6 @@ bool FGAICarrier::OutsideBox() { //returns true if the carrier is outside operat
} // end OutsideBox } // end OutsideBox
// return the distance to the horizon, given the altitude and the radius of the earth
float FGAICarrier::Horizon(float h) {
return RADIUS_M * acos(RADIUS_M / (RADIUS_M + h));
}
bool FGAICarrier::InToWind() { bool FGAICarrier::InToWind() {
if ( fabs(rel_wind) < 5 ) if ( fabs(rel_wind) < 5 )
return true; return true;

View file

@ -23,7 +23,10 @@
#include <string> #include <string>
#include <list> #include <list>
#include <plib/ssg.h>
#include <osg/Referenced>
#include <osg/Node>
#include <simgear/compiler.h> #include <simgear/compiler.h>
SG_USING_STD(string); SG_USING_STD(string);
@ -37,7 +40,7 @@ SG_USING_STD(list);
class FGAIManager; class FGAIManager;
class FGAICarrier; class FGAICarrier;
class FGAICarrierHardware : public ssgBase { class FGAICarrierHardware : public osg::Referenced {
public: public:
enum Type { Catapult, Wire, Solid }; enum Type { Catapult, Wire, Solid };
@ -84,7 +87,7 @@ public:
void setSign(const string& ); void setSign(const string& );
void setTACANChannelID(const string &); void setTACANChannelID(const string &);
void getVelocityWrtEarth(sgdVec3& v, sgdVec3& omega, sgdVec3& pivot); void getVelocityWrtEarth(SGVec3d& v, SGVec3d& omega, SGVec3d& pivot);
virtual void bind(); virtual void bind();
virtual void unbind(); virtual void unbind();
void UpdateWind ( double dt ); void UpdateWind ( double dt );
@ -97,7 +100,6 @@ public:
void TurnToLaunch(); void TurnToLaunch();
void TurnToBase(); void TurnToBase();
void ReturnToBox(); void ReturnToBox();
float Horizon(float h);
bool OutsideBox(); bool OutsideBox();
bool init(); bool init();
@ -124,11 +126,6 @@ private:
void update(double dt); void update(double dt);
void mark_nohot(ssgEntity*);
bool mark_wires(ssgEntity*, const list<string>&, bool = false);
bool mark_cat(ssgEntity*, const list<string>&, bool = false);
bool mark_solid(ssgEntity*, const list<string>&, bool = false);
double wind_from_east; // fps double wind_from_east; // fps
double wind_from_north; // fps double wind_from_north; // fps
double rel_wind_speed_kts; double rel_wind_speed_kts;

View file

@ -259,7 +259,7 @@ FGAIManager::loadScenarioFile(const std::string& filename)
// This code keeps track of models that have already been loaded // This code keeps track of models that have already been loaded
// Eventually we'd prbably need to find a way to keep track of models // Eventually we'd prbably need to find a way to keep track of models
// that are unloaded again // that are unloaded again
ssgBranch * FGAIManager::getModel(const string& path) osg::Node* FGAIManager::getModel(const string& path)
{ {
ModelVecIterator i = loadedModels.begin(); ModelVecIterator i = loadedModels.begin();
//cerr << "Reference count summary " << endl; //cerr << "Reference count summary " << endl;
@ -291,7 +291,7 @@ ssgBranch * FGAIManager::getModel(const string& path)
return 0; return 0;
} }
void FGAIManager::setModel(const string& path, ssgBranch *model) void FGAIManager::setModel(const string& path, osg::Node *model)
{ {
loadedModels.push_back(FGModelID(path,model)); loadedModels.push_back(FGModelID(path,model));
} }

View file

@ -26,7 +26,6 @@
#include <list> #include <list>
#include <simgear/structure/subsystem_mgr.hxx> #include <simgear/structure/subsystem_mgr.hxx>
#include <simgear/structure/ssgSharedPtr.hxx>
#include <simgear/structure/SGSharedPtr.hxx> #include <simgear/structure/SGSharedPtr.hxx>
#include <Main/fg_props.hxx> #include <Main/fg_props.hxx>
@ -43,13 +42,13 @@ SG_USING_STD(vector);
class FGModelID class FGModelID
{ {
private: private:
ssgSharedPtr<ssgBranch> model; osg::ref_ptr<osg::Node> model;
string path; string path;
public: public:
FGModelID(const string& pth, ssgBranch * mdl) { path =pth; model=mdl;}; FGModelID(const string& pth, osg::Node* mdl) { path =pth; model=mdl;};
ssgBranch * const getModelId() const { return model;}; osg::Node* const getModelId() const { return model.get();};
const string & getPath() const { return path;}; const string & getPath() const { return path;};
int getNumRefs() const { return model.getNumRefs(); }; int getNumRefs() const { return model->referenceCount(); };
}; };
typedef vector<FGModelID> ModelVec; typedef vector<FGModelID> ModelVec;
@ -100,8 +99,8 @@ public:
void processScenario( const string &filename ); void processScenario( const string &filename );
ssgBranch * getModel(const string& path); osg::Node* getModel(const string& path);
void setModel(const string& path, ssgBranch *model); void setModel(const string& path, osg::Node *model);
static SGPropertyNode_ptr loadScenarioFile(const std::string& filename); static SGPropertyNode_ptr loadScenarioFile(const std::string& filename);

View file

@ -46,18 +46,18 @@ FGAIEntity::FGAIEntity() {
FGAIEntity::~FGAIEntity() { FGAIEntity::~FGAIEntity() {
//cout << "FGAIEntity dtor called..." << endl; //cout << "FGAIEntity dtor called..." << endl;
//cout << "Removing model from scene graph..." << endl; //cout << "Removing model from scene graph..." << endl;
globals->get_scenery()->get_scene_graph()->removeKid(_aip.getSceneGraph()); globals->get_scenery()->get_scene_graph()->removeChild(_aip.getSceneGraph());
// Unregister that one at the scenery manager // Unregister that one at the scenery manager
globals->get_scenery()->unregister_placement_transform(_aip.getTransform()); globals->get_scenery()->unregister_placement_transform(_aip.getTransform());
//cout << "Done!" << endl; //cout << "Done!" << endl;
} }
void FGAIEntity::SetModel(ssgBranch* model) { void FGAIEntity::SetModel(osg::Node* model) {
_model = model; _model = model;
_aip.init(_model); _aip.init(_model.get());
_aip.setVisible(false); _aip.setVisible(false);
globals->get_scenery()->get_scene_graph()->addKid(_aip.getSceneGraph()); globals->get_scenery()->get_scene_graph()->addChild(_aip.getSceneGraph());
// Register that one at the scenery manager // Register that one at the scenery manager
globals->get_scenery()->register_placement_transform(_aip.getTransform()); globals->get_scenery()->register_placement_transform(_aip.getTransform());

View file

@ -24,10 +24,6 @@
#include <simgear/math/point3d.hxx> #include <simgear/math/point3d.hxx>
#include <simgear/scene/model/model.hxx> #include <simgear/scene/model/model.hxx>
#include <simgear/scene/model/placement.hxx> #include <simgear/scene/model/placement.hxx>
#include <simgear/structure/ssgSharedPtr.hxx>
class ssgBase;
/***************************************************************** /*****************************************************************
@ -46,7 +42,7 @@ public:
virtual ~FGAIEntity(); virtual ~FGAIEntity();
// Set the 3D model to use (Must be called) // Set the 3D model to use (Must be called)
void SetModel(ssgBranch* model); void SetModel(osg::Node* model);
// Run the internal calculations // Run the internal calculations
virtual void Update(double dt)=0; virtual void Update(double dt)=0;
@ -67,7 +63,7 @@ protected:
double _pitch; //degrees double _pitch; //degrees
char* _model_path; //Path to the 3D model char* _model_path; //Path to the 3D model
ssgSharedPtr<ssgBranch> _model; // Pointer to the model osg::ref_ptr<osg::Node> _model; // Pointer to the model
SGModelPlacement _aip; SGModelPlacement _aip;
void Transform(); void Transform();

View file

@ -306,7 +306,7 @@ void FGAIMgr::ActivateAirport(const string& ident) {
ATC->AIRegisterAirport(ident); ATC->AIRegisterAirport(ident);
// TODO - need to start the traffic more randomly // TODO - need to start the traffic more randomly
FGAILocalTraffic* local_traffic = new FGAILocalTraffic; FGAILocalTraffic* local_traffic = new FGAILocalTraffic;
local_traffic->SetModel(_defaultModel); // currently hardwired to cessna. local_traffic->SetModel(_defaultModel.get()); // currently hardwired to cessna.
//local_traffic->Init(ident, IN_PATTERN, TAKEOFF_ROLL); //local_traffic->Init(ident, IN_PATTERN, TAKEOFF_ROLL);
local_traffic->Init(GenerateShortForm(GenerateUniqueCallsign()), ident); local_traffic->Init(GenerateShortForm(GenerateUniqueCallsign()), ident);
local_traffic->FlyCircuits(1, true); // Fly 2 circuits with touch & go in between local_traffic->FlyCircuits(1, true); // Fly 2 circuits with touch & go in between
@ -469,7 +469,7 @@ void FGAIMgr::GenerateSimpleAirportTraffic(const string& ident, double min_dist)
else cessna = true; else cessna = true;
string s = GenerateShortForm(GenerateUniqueCallsign(), (cessna ? "Cessna-" : "Piper-")); string s = GenerateShortForm(GenerateUniqueCallsign(), (cessna ? "Cessna-" : "Piper-"));
FGAIGAVFRTraffic* t = new FGAIGAVFRTraffic(); FGAIGAVFRTraffic* t = new FGAIGAVFRTraffic();
t->SetModel(cessna ? _defaultModel : (_havePiperModel ? _piperModel : _defaultModel)); t->SetModel(cessna ? _defaultModel.get() : (_havePiperModel ? _piperModel.get() : _defaultModel.get()));
//cout << "Generating VFR traffic " << s << " inbound to " << ident << " " << ad << " meters out from " << dir << " degrees\n"; //cout << "Generating VFR traffic " << s << " inbound to " << ident << " " << ad << " meters out from " << dir << " degrees\n";
Point3D tpos = dclUpdatePosition(aptpos, dir, 6.0, ad); Point3D tpos = dclUpdatePosition(aptpos, dir, 6.0, ad);
if(tpos.elev() > (aptpos.elev() + 3000.0)) tpos.setelev(aptpos.elev() + 3000.0); // FEET yuk :-( if(tpos.elev() > (aptpos.elev() + 3000.0)) tpos.setelev(aptpos.elev() + 3000.0); // FEET yuk :-(

View file

@ -23,7 +23,6 @@
#define _FG_AIMGR_HXX #define _FG_AIMGR_HXX
#include <simgear/structure/subsystem_mgr.hxx> #include <simgear/structure/subsystem_mgr.hxx>
#include <simgear/structure/ssgSharedPtr.hxx>
#include <Main/fg_props.hxx> #include <Main/fg_props.hxx>
@ -110,8 +109,8 @@ public:
private: private:
ssgSharedPtr<ssgBranch> _defaultModel; // Cessna 172! osg::ref_ptr<osg::Node> _defaultModel; // Cessna 172!
ssgSharedPtr<ssgBranch> _piperModel; // pa28-161 osg::ref_ptr<osg::Node> _piperModel; // pa28-161
bool initDone; // Hack - guard against update getting called before init bool initDone; // Hack - guard against update getting called before init

View file

@ -61,8 +61,13 @@ void FGATCDisplay::bind() {
void FGATCDisplay::unbind() { void FGATCDisplay::unbind() {
} }
void FGATCDisplay::update(double dt)
{
std::cout << "OSGFIXME" << std::endl;
}
// update - this actually draws the visuals and should be called from the main Flightgear rendering loop. // update - this actually draws the visuals and should be called from the main Flightgear rendering loop.
void FGATCDisplay::update(double dt) { void FGATCDisplay::update(double dt, osg::State& state) {
// These strings are used for temporary storage of the transmission string in order // These strings are used for temporary storage of the transmission string in order
// that the string we view only changes when the next repetition starts scrolling // that the string we view only changes when the next repetition starts scrolling

View file

@ -27,6 +27,7 @@
# include <config.h> # include <config.h>
#endif #endif
#include <osg/State>
#include <simgear/structure/subsystem_mgr.hxx> #include <simgear/structure/subsystem_mgr.hxx>
#include <vector> #include <vector>
@ -72,6 +73,7 @@ public:
void unbind(); void unbind();
// Display any registered messages // Display any registered messages
void update(double dt, osg::State&);
void update(double dt); void update(double dt);
// Register a single message for display after a delay of delay seconds // Register a single message for display after a delay of delay seconds

View file

@ -36,7 +36,7 @@ FGMagRibbon::FGMagRibbon (int w, int h)
} }
void void
FGMagRibbon::draw () FGMagRibbon::draw (osg::State& state)
{ {
double heading = _magcompass_node->getDoubleValue(); double heading = _magcompass_node->getDoubleValue();
double xoffset, yoffset; double xoffset, yoffset;
@ -71,10 +71,16 @@ FGMagRibbon::draw ()
FGCroppedTexture *t = getTexture(); FGCroppedTexture *t = getTexture();
t->setCrop(xoffset, yoffset, xoffset + 0.5, yoffset + 0.25); t->setCrop(xoffset, yoffset, xoffset + 0.5, yoffset + 0.25);
glPushAttrib(GL_DEPTH_BUFFER_BIT); static osg::ref_ptr<osg::StateSet> stateSet = new osg::StateSet;
glEnable(GL_DEPTH_TEST); stateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF);
FGTexturedLayer::draw();
glPopAttrib(); state.pushStateSet(stateSet.get());
state.apply();
FGTexturedLayer::draw(state);
state.popStateSet();
state.apply();
} }
// end of FGMagRibbon.cxx // end of FGMagRibbon.cxx

View file

@ -34,7 +34,7 @@ public:
FGMagRibbon (int w, int h); FGMagRibbon (int w, int h);
virtual ~FGMagRibbon () {} virtual ~FGMagRibbon () {}
virtual void draw (); virtual void draw (osg::State& state);
private: private:
SGPropertyNode_ptr _magcompass_node; SGPropertyNode_ptr _magcompass_node;

View file

@ -550,7 +550,7 @@ bool fgCockpitInit( fgAIRCRAFT *cur_aircraft )
return true; return true;
} }
void fgCockpitUpdate( void ) { void fgCockpitUpdate( osg::State* state ) {
SG_LOG( SG_COCKPIT, SG_DEBUG, SG_LOG( SG_COCKPIT, SG_DEBUG,
"Cockpit: code " << ac_cockpit->code() << " status " "Cockpit: code " << ac_cockpit->code() << " status "
@ -568,7 +568,7 @@ void fgCockpitUpdate( void ) {
if ( hud_visibility_node->getBoolValue() ) { if ( hud_visibility_node->getBoolValue() ) {
// This will check the global hud linked list pointer. // This will check the global hud linked list pointer.
// If there is anything to draw it will. // If there is anything to draw it will.
fgUpdateHUD(); fgUpdateHUD( state );
} }
glViewport( 0, 0, iwidth, iheight ); glViewport( 0, 0, iwidth, iheight );

View file

@ -31,8 +31,9 @@
# error This library requires C++ # error This library requires C++
#endif #endif
#include <osg/State>
#include <Aircraft/aircraft.hxx> #include "Aircraft/aircraft.hxx"
#include "panel.hxx" #include "panel.hxx"
// Class fg_Cockpit This class is a holder for the heads up display // Class fg_Cockpit This class is a holder for the heads up display
@ -53,7 +54,7 @@ class fg_Cockpit {
typedef fg_Cockpit * pCockpit; typedef fg_Cockpit * pCockpit;
bool fgCockpitInit( fgAIRCRAFT *cur_aircraft ); bool fgCockpitInit( fgAIRCRAFT *cur_aircraft );
void fgCockpitUpdate( void ); void fgCockpitUpdate( osg::State* );
#endif /* _COCKPIT_HXX */ #endif /* _COCKPIT_HXX */

View file

@ -79,8 +79,8 @@ float HUD_matrix[16];
int readHud( istream &input ); int readHud( istream &input );
int readInstrument ( const SGPropertyNode * node); int readInstrument ( const SGPropertyNode * node);
static void drawHUD(); static void drawHUD(osg::State*);
static void fgUpdateHUDVirtual(); static void fgUpdateHUDVirtual(osg::State*);
class locRECT { class locRECT {
@ -255,8 +255,6 @@ int fgHUDInit( fgAIRCRAFT * /* current_aircraft */ )
input.close(); input.close();
} }
fgHUDReshape();
if ( HUDtext ) { if ( HUDtext ) {
// this chunk of code is not necessarily thread safe if the // this chunk of code is not necessarily thread safe if the
// compiler optimizer reorders these statements. Note that // compiler optimizer reorders these statements. Note that
@ -314,39 +312,17 @@ int fgHUDInit2( fgAIRCRAFT * /* current_aircraft */ )
//$$$ End - added, Neetha, 28 Nov 2k //$$$ End - added, Neetha, 28 Nov 2k
void fgHUDReshape(void) {
#if 0
if ( HUDtext ) {
// this chunk of code is not necessarily thread safe if the
// compiler optimizer reorders these statements. Note that
// "delete ptr" does not set "ptr = NULL". We have to do that
// ourselves.
fntRenderer *tmp = HUDtext;
HUDtext = NULL;
delete tmp;
}
HUD_TextSize = fgGetInt("/sim/startup/xsize") / 60;
HUD_TextSize = 10;
HUDtext = new fntRenderer();
HUDtext -> setFont ( guiFntHandle ) ;
HUDtext -> setPointSize ( HUD_TextSize ) ;
HUD_TextList.setFont( HUDtext );
#endif
}
// fgUpdateHUD // fgUpdateHUD
// //
// Performs a once around the list of calls to instruments installed in // Performs a once around the list of calls to instruments installed in
// the HUD object with requests for redraw. Kinda. It will when this is // the HUD object with requests for redraw. Kinda. It will when this is
// all C++. // all C++.
// //
void fgUpdateHUD( void ) { void fgUpdateHUD( osg::State* state ) {
static const SGPropertyNode *enable3d_node = fgGetNode("/sim/hud/enable3d"); static const SGPropertyNode *enable3d_node = fgGetNode("/sim/hud/enable3d");
if ( HUD_style == 1 && enable3d_node->getBoolValue() ) { if ( HUD_style == 1 && enable3d_node->getBoolValue() ) {
fgUpdateHUDVirtual(); fgUpdateHUDVirtual(state);
return; return;
} }
@ -356,15 +332,15 @@ void fgUpdateHUD( void ) {
if ( current_aspect > normal_aspect ) { if ( current_aspect > normal_aspect ) {
float aspect_adjust = current_aspect / normal_aspect; float aspect_adjust = current_aspect / normal_aspect;
float adjust = 320.0f*aspect_adjust - 320.0f; float adjust = 320.0f*aspect_adjust - 320.0f;
fgUpdateHUD( -adjust, 0.0f, 640.0f+adjust, 480.0f ); fgUpdateHUD( state, -adjust, 0.0f, 640.0f+adjust, 480.0f );
} else { } else {
float aspect_adjust = normal_aspect / current_aspect; float aspect_adjust = normal_aspect / current_aspect;
float adjust = 240.0f*aspect_adjust - 240.0f; float adjust = 240.0f*aspect_adjust - 240.0f;
fgUpdateHUD( 0.0f, -adjust, 640.0f, 480.0f+adjust ); fgUpdateHUD( state, 0.0f, -adjust, 640.0f, 480.0f+adjust );
} }
} }
void fgUpdateHUDVirtual() void fgUpdateHUDVirtual(osg::State* state)
{ {
FGViewer* view = globals->get_current_view(); FGViewer* view = globals->get_current_view();
@ -406,7 +382,7 @@ void fgUpdateHUDVirtual()
glTranslatef(-320, -240, -1); glTranslatef(-320, -240, -1);
// Do the deed // Do the deed
drawHUD(); drawHUD(state);
// Clean up our mess // Clean up our mess
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
@ -416,7 +392,7 @@ void fgUpdateHUDVirtual()
} }
void fgUpdateHUD( GLfloat x_start, GLfloat y_start, void fgUpdateHUD( osg::State* state, GLfloat x_start, GLfloat y_start,
GLfloat x_end, GLfloat y_end ) GLfloat x_end, GLfloat y_end )
{ {
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
@ -428,7 +404,7 @@ void fgUpdateHUD( GLfloat x_start, GLfloat y_start,
glPushMatrix(); glPushMatrix();
glLoadIdentity(); glLoadIdentity();
drawHUD(); drawHUD(state);
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glPopMatrix(); glPopMatrix();
@ -437,7 +413,7 @@ void fgUpdateHUD( GLfloat x_start, GLfloat y_start,
} }
void drawHUD() void drawHUD(osg::State* state)
{ {
if ( !HUD_deque.size() ) // Trust everyone, but ALWAYS cut the cards! if ( !HUD_deque.size() ) // Trust everyone, but ALWAYS cut the cards!
return; return;

View file

@ -41,15 +41,13 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
//#ifdef HAVE_VALUES_H
//# include <values.h> // for MAXINT
//#endif
#include <algorithm> // for_each() #include <algorithm> // for_each()
#include <vector> // STL vector #include <vector> // STL vector
#include <deque> // STL double ended queue #include <deque> // STL double ended queue
#include STL_FSTREAM #include STL_FSTREAM
#include <osg/State>
#include <simgear/math/SGMath.hxx> #include <simgear/math/SGMath.hxx>
#include <simgear/constants.h> #include <simgear/constants.h>
@ -106,32 +104,6 @@ enum fgLabelJust{ LEFT_JUST, CENTER_JUST, RIGHT_JUST } ;
#define HUDS_DECITICS 0x0040 #define HUDS_DECITICS 0x0040
#define HUDS_NOTEXT 0x0080 #define HUDS_NOTEXT 0x0080
// Ladder orientaion
// #define HUD_VERTICAL 1
// #define HUD_HORIZONTAL 2
// #define HUD_FREEFLOAT 3
// Ladder orientation modes
// #define HUD_LEFT 1
// #define HUD_RIGHT 2
// #define HUD_TOP 1
// #define HUD_BOTTOM 2
// #define HUD_V_LEFT 1
// #define HUD_V_RIGHT 2
// #define HUD_H_TOP 1
// #define HUD_H_BOTTOM 2
// Ladder sub-types
// #define HUD_LIM 1
// #define HUD_NOLIM 2
// #define HUD_CIRC 3
// #define HUD_INSTR_LADDER 1
// #define HUD_INSTR_CLADDER 2
// #define HUD_INSTR_HORIZON 3
// #define HUD_INSTR_LABEL 4
// in cockpit.cxx // in cockpit.cxx
extern float get_throttleval ( void ); extern float get_throttleval ( void );
extern float get_aileronval ( void ); extern float get_aileronval ( void );
@ -161,10 +133,8 @@ extern float get_climb_rate ( void );
extern float get_mach( void ); extern float get_mach( void );
extern char *coord_format_lat(float); extern char *coord_format_lat(float);
extern char *coord_format_lon(float); extern char *coord_format_lon(float);
//extern char *coord_format_latlon(float latitude, float longitude); // cockpit.cxx
// $$$ begin - added, VS Renganathan, 13 Oct 2K // $$$ begin - added, VS Renganathan, 13 Oct 2K
// #define FIGHTER_HUD
extern float get_anzg (void); extern float get_anzg (void);
extern float get_Vx (void); extern float get_Vx (void);
extern float get_Vy (void); extern float get_Vy (void);
@ -205,7 +175,6 @@ extern float get_aux18(void);
// $$$ end - added, VS Renganathan, 13 Oct 2K // $$$ end - added, VS Renganathan, 13 Oct 2K
extern char *get_formated_gmt_time( void ); extern char *get_formated_gmt_time( void );
extern void fgHUDReshape(void);
enum hudinstype{ HUDno_instr, enum hudinstype{ HUDno_instr,
HUDscale, HUDscale,
@ -522,9 +491,7 @@ class HUDdraw {
}; };
extern deque< instr_item *> HUD_deque;
extern int HUD_style; extern int HUD_style;
//extern hud_deque_type HUD_deque;
// instr_item This class has no other purpose than to maintain // instr_item This class has no other purpose than to maintain
// a linked list of instrument and derived class // a linked list of instrument and derived class
@ -788,27 +755,12 @@ public:
}; };
//using namespace std;
//deque <instr_item> * Hdeque_ptr;
extern int fgHUDInit( fgAIRCRAFT * /* current_aircraft */ ); extern int fgHUDInit( fgAIRCRAFT * /* current_aircraft */ );
extern int fgHUDInit2( fgAIRCRAFT * /* current_aircraft */ ); extern int fgHUDInit2( fgAIRCRAFT * /* current_aircraft */ );
extern void fgUpdateHUD( void ); extern void fgUpdateHUD( osg::State* );
extern void fgUpdateHUD( GLfloat x_start, GLfloat y_start, extern void fgUpdateHUD( osg::State*, GLfloat x_start, GLfloat y_start,
GLfloat x_end, GLfloat y_end ); GLfloat x_end, GLfloat y_end );
/*
bool AddHUDInstrument( instr_item *pBlackBox );
void DrawHUD ( void );
bool DamageInstrument( INSTR_HANDLE unit );
bool RepairInstrument( INSTR_HANDLE unit );
void fgUpdateHUD ( Hptr hud );
void fgUpdateHUD2( Hptr hud ); // Future use?
void fgHUDSetTimeMode( Hptr hud, int time_of_day );
*/

View file

@ -105,13 +105,16 @@ void runway_instr::draw()
globals->get_viewmgr()->copyToCurrent(); globals->get_viewmgr()->copyToCurrent();
} }
//Set the camera to the cockpit view to get the view of the runway from the cockpit //Set the camera to the cockpit view to get the view of the runway from the cockpit
ssgSetCamera((sgVec4 *)cockpit_view->get_VIEW()); // OSGFIXME
// ssgSetCamera((sgVec4 *)cockpit_view->get_VIEW());
get_rwy_points(points3d); get_rwy_points(points3d);
//Get the current project matrix //Get the current project matrix
ssgGetProjectionMatrix(projMat); // OSGFIXME
// ssgGetProjectionMatrix(projMat);
// const sgVec4 *viewMat = globals->get_current_view()->get_VIEW(); // const sgVec4 *viewMat = globals->get_current_view()->get_VIEW();
//Get the current model view matrix (cockpit view) //Get the current model view matrix (cockpit view)
ssgGetModelviewMatrix(modelView); // OSGFIXME
// ssgGetModelviewMatrix(modelView);
//Create a rotation matrix to correct for any offsets (other than default offsets) to the model view matrix //Create a rotation matrix to correct for any offsets (other than default offsets) to the model view matrix
sgMat4 xy; //rotation about the Rxy, negate the sin's on Ry sgMat4 xy; //rotation about the Rxy, negate the sin's on Ry
xy[0][0] = cYaw; xy[1][0] = 0.0f; xy[2][0] = -sYaw; xy[3][0] = 0.0f; xy[0][0] = cYaw; xy[1][0] = 0.0f; xy[2][0] = -sYaw; xy[3][0] = 0.0f;
@ -164,7 +167,8 @@ void runway_instr::draw()
curr_view->setGoalPitchOffset_deg(gpo); curr_view->setGoalPitchOffset_deg(gpo);
} }
//Set the camera back to the current view //Set the camera back to the current view
ssgSetCamera((sgVec4 *)curr_view); // OSGFIXME
// ssgSetCamera((sgVec4 *)curr_view);
glPopAttrib(); glPopAttrib();
}//if not broken }//if not broken
} }

View file

@ -38,15 +38,21 @@
#include <stdio.h> // sprintf #include <stdio.h> // sprintf
#include <string.h> #include <string.h>
#include <osg/CullFace>
#include <osg/Depth>
#include <osg/Material>
#include <osg/TexEnv>
#include <osg/PolygonOffset>
#include <simgear/compiler.h> #include <simgear/compiler.h>
#include SG_GLU_H #include SG_GLU_H
#include <plib/ssg.h>
#include <plib/fnt.h> #include <plib/fnt.h>
#include <simgear/debug/logstream.hxx> #include <simgear/debug/logstream.hxx>
#include <simgear/misc/sg_path.hxx> #include <simgear/misc/sg_path.hxx>
#include <simgear/scene/model/model.hxx>
#include <Main/globals.hxx> #include <Main/globals.hxx>
#include <Main/fg_props.hxx> #include <Main/fg_props.hxx>
@ -109,23 +115,24 @@ fgPanelVisible ()
// Implementation of FGTextureManager. // Implementation of FGTextureManager.
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
map<string,ssgTexture *> FGTextureManager::_textureMap; map<string,osg::ref_ptr<osg::Texture2D> > FGTextureManager::_textureMap;
ssgTexture * osg::Texture2D*
FGTextureManager::createTexture (const string &relativePath) FGTextureManager::createTexture (const string &relativePath)
{ {
ssgTexture * texture = _textureMap[relativePath]; osg::Texture2D* texture = _textureMap[relativePath].get();
if (texture == 0) { if (texture == 0) {
SG_LOG( SG_COCKPIT, SG_DEBUG, SG_LOG( SG_COCKPIT, SG_DEBUG,
"Texture " << relativePath << " does not yet exist" ); "Texture " << relativePath << " does not yet exist" );
SGPath tpath(globals->get_fg_root()); SGPath tpath(globals->get_fg_root());
tpath.append(relativePath); tpath.append(relativePath);
texture = new ssgTexture((char *)tpath.c_str(), false, false);
texture = SGLoadTexture2D(tpath);
_textureMap[relativePath] = texture; _textureMap[relativePath] = texture;
if (_textureMap[relativePath] == 0) if (!_textureMap[relativePath].valid())
SG_LOG( SG_COCKPIT, SG_ALERT, "Texture *still* doesn't exist" ); SG_LOG( SG_COCKPIT, SG_ALERT, "Texture *still* doesn't exist" );
SG_LOG( SG_COCKPIT, SG_DEBUG, "Created texture " << relativePath SG_LOG( SG_COCKPIT, SG_DEBUG, "Created texture " << relativePath );
<< " handle=" << texture->getHandle() );
} }
return texture; return texture;
@ -160,13 +167,16 @@ FGCroppedTexture::~FGCroppedTexture ()
} }
ssgTexture * osg::StateSet*
FGCroppedTexture::getTexture () FGCroppedTexture::getTexture ()
{ {
if (_texture == 0) { if (_texture == 0) {
_texture = FGTextureManager::createTexture(_path); _texture = new osg::StateSet;
_texture->setTextureAttribute(0, FGTextureManager::createTexture(_path));
_texture->setTextureMode(0, GL_TEXTURE_2D, osg::StateAttribute::ON);
_texture->setTextureAttribute(0, new osg::TexEnv(osg::TexEnv::MODULATE));
} }
return _texture; return _texture.get();
} }
@ -254,11 +264,52 @@ FGPanel::unbind ()
} }
void
FGPanel::update (double dt)
{
std::cout << "OSGFIXME" << std::endl;
}
void
FGPanel::update (osg::State& state, GLfloat winx, GLfloat winw, GLfloat winy, GLfloat winh)
{
// Calculate accelerations
// and jiggle the panel accordingly
// The factors and bounds are just
// initial guesses; using sqrt smooths
// out the spikes.
double x_offset = _x_offset->getIntValue();
double y_offset = _y_offset->getIntValue();
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
if ( _flipx->getBoolValue() ) {
gluOrtho2D(winx + winw, winx, winy + winh, winy); /* up side down */
} else {
gluOrtho2D(winx, winx + winw, winy, winy + winh); /* right side up */
}
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glTranslated(x_offset, y_offset, 0);
draw(state);
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
}
/** /**
* Update the panel. * Update the panel.
*/ */
void void
FGPanel::update (double dt) FGPanel::update (osg::State& state)
{ {
// Do nothing if the panel isn't visible. // Do nothing if the panel isn't visible.
if ( !fgPanelVisible() ) { if ( !fgPanelVisible() ) {
@ -271,9 +322,9 @@ FGPanel::update (double dt)
float aspect_adjust = get_aspect_adjust(_xsize_node->getIntValue(), float aspect_adjust = get_aspect_adjust(_xsize_node->getIntValue(),
_ysize_node->getIntValue()); _ysize_node->getIntValue());
if (aspect_adjust <1.0) if (aspect_adjust <1.0)
update(WIN_X, int(WIN_W * aspect_adjust), WIN_Y, WIN_H); update(state, WIN_X, int(WIN_W * aspect_adjust), WIN_Y, WIN_H);
else else
update(WIN_X, WIN_W, WIN_Y, int(WIN_H / aspect_adjust)); update(state, WIN_X, WIN_W, WIN_Y, int(WIN_H / aspect_adjust));
} }
/** /**
@ -294,87 +345,39 @@ void FGPanel::updateMouseDelay()
void void
FGPanel::update (GLfloat winx, GLfloat winw, GLfloat winy, GLfloat winh) FGPanel::draw(osg::State& state)
{
// Calculate accelerations
// and jiggle the panel accordingly
// The factors and bounds are just
// initial guesses; using sqrt smooths
// out the spikes.
double x_offset = _x_offset->getIntValue();
double y_offset = _y_offset->getIntValue();
#if 0
if (_jitter->getFloatValue() != 0.0) {
double a_x_pilot = current_aircraft.fdm_state->get_A_X_pilot();
double a_y_pilot = current_aircraft.fdm_state->get_A_Y_pilot();
double a_z_pilot = current_aircraft.fdm_state->get_A_Z_pilot();
double a_zx_pilot = a_z_pilot - a_x_pilot;
int x_adjust = int(sqrt(fabs(a_y_pilot) * _jitter->getFloatValue())) *
(a_y_pilot < 0 ? -1 : 1);
int y_adjust = int(sqrt(fabs(a_zx_pilot) * _jitter->getFloatValue())) *
(a_zx_pilot < 0 ? -1 : 1);
// adjustments in screen coordinates
x_offset += x_adjust;
y_offset += y_adjust;
}
#endif
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
if ( _flipx->getBoolValue() ) {
gluOrtho2D(winx + winw, winx, winy + winh, winy); /* up side down */
} else {
gluOrtho2D(winx, winx + winw, winy, winy + winh); /* right side up */
}
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glTranslated(x_offset, y_offset, 0);
draw();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
ssgForceBasicState();
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
}
void
FGPanel::draw()
{ {
// In 3D mode, it's possible that we are being drawn exactly on top // In 3D mode, it's possible that we are being drawn exactly on top
// of an existing polygon. Use an offset to prevent z-fighting. In // of an existing polygon. Use an offset to prevent z-fighting. In
// 2D mode, this is a no-op. // 2D mode, this is a no-op.
glEnable(GL_POLYGON_OFFSET_FILL); static osg::ref_ptr<osg::StateSet> panelStateSet;
glPolygonOffset(-1, -POFF_UNITS); if (!panelStateSet.valid()) {
panelStateSet = new osg::StateSet;
panelStateSet->setAttributeAndModes(new osg::PolygonOffset(-1, -POFF_UNITS));
panelStateSet->setTextureAttribute(0, new osg::TexEnv);
// save some state // Draw the background
glPushAttrib( GL_COLOR_BUFFER_BIT | GL_ENABLE_BIT | GL_LIGHTING_BIT panelStateSet->setTextureMode(0, GL_TEXTURE_2D, osg::StateAttribute::ON);
| GL_TEXTURE_BIT | GL_PIXEL_MODE_BIT | GL_CULL_FACE panelStateSet->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
| GL_DEPTH_BUFFER_BIT ); panelStateSet->setMode(GL_BLEND, osg::StateAttribute::ON);
panelStateSet->setMode(GL_ALPHA_TEST, osg::StateAttribute::ON);
// Draw the background osg::Material* material = new osg::Material;
glEnable(GL_TEXTURE_2D); material->setColorMode(osg::Material::AMBIENT_AND_DIFFUSE);
glDisable(GL_LIGHTING); material->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4(1, 1, 1, 1));
glEnable(GL_BLEND); material->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4(1, 1, 1, 1));
glEnable(GL_ALPHA_TEST); material->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4(0, 0, 0, 1));
glEnable(GL_COLOR_MATERIAL); material->setEmission(osg::Material::FRONT_AND_BACK, osg::Vec4(0, 0, 0, 1));
glEnable(GL_CULL_FACE); panelStateSet->setAttribute(material);
glCullFace(GL_BACK); panelStateSet->setMode(GL_COLOR_MATERIAL, osg::StateAttribute::ON);
if ( _enable_depth_test ) panelStateSet->setMode(GL_CULL_FACE, osg::StateAttribute::ON);
glDepthFunc(GL_ALWAYS); panelStateSet->setAttributeAndModes(new osg::CullFace(osg::CullFace::BACK));
else if ( _enable_depth_test )
glDisable(GL_DEPTH_TEST); panelStateSet->setAttributeAndModes(new osg::Depth(osg::Depth::ALWAYS));
else
panelStateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF);
}
state.pushStateSet(panelStateSet.get());
state.apply();
FGLight *l = (FGLight *)(globals->get_subsystem("lighting")); FGLight *l = (FGLight *)(globals->get_subsystem("lighting"));
sgCopyVec4( panel_color, l->scene_diffuse()); sgCopyVec4( panel_color, l->scene_diffuse());
@ -385,36 +388,40 @@ FGPanel::draw()
} }
glColor4fv( panel_color ); glColor4fv( panel_color );
if (_bg != 0) { if (_bg != 0) {
glBindTexture(GL_TEXTURE_2D, _bg->getHandle()); state.pushStateSet(_bg.get());
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); state.apply();
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glBegin(GL_POLYGON); glBegin(GL_POLYGON);
glTexCoord2f(0.0, 0.0); glVertex2f(WIN_X, WIN_Y); glTexCoord2f(0.0, 0.0); glVertex2f(WIN_X, WIN_Y);
glTexCoord2f(1.0, 0.0); glVertex2f(WIN_X + _width, WIN_Y); glTexCoord2f(1.0, 0.0); glVertex2f(WIN_X + _width, WIN_Y);
glTexCoord2f(1.0, 1.0); glVertex2f(WIN_X + _width, WIN_Y + _height); glTexCoord2f(1.0, 1.0); glVertex2f(WIN_X + _width, WIN_Y + _height);
glTexCoord2f(0.0, 1.0); glVertex2f(WIN_X, WIN_Y + _height); glTexCoord2f(0.0, 1.0); glVertex2f(WIN_X, WIN_Y + _height);
glEnd(); glEnd();
state.popStateSet();
state.apply();
} else { } else {
for (int i = 0; i < 4; i ++) { for (int i = 0; i < 4; i ++) {
// top row of textures...(1,3,5,7) // top row of textures...(1,3,5,7)
glBindTexture(GL_TEXTURE_2D, _mbg[i*2]->getHandle()); state.pushStateSet(_mbg[i*2].get());
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); state.apply();
glBegin(GL_POLYGON); glBegin(GL_POLYGON);
glTexCoord2f(0.0, 0.0); glVertex2f(WIN_X + (_width/4) * i, WIN_Y + (_height/2)); glTexCoord2f(0.0, 0.0); glVertex2f(WIN_X + (_width/4) * i, WIN_Y + (_height/2));
glTexCoord2f(1.0, 0.0); glVertex2f(WIN_X + (_width/4) * (i+1), WIN_Y + (_height/2)); glTexCoord2f(1.0, 0.0); glVertex2f(WIN_X + (_width/4) * (i+1), WIN_Y + (_height/2));
glTexCoord2f(1.0, 1.0); glVertex2f(WIN_X + (_width/4) * (i+1), WIN_Y + _height); glTexCoord2f(1.0, 1.0); glVertex2f(WIN_X + (_width/4) * (i+1), WIN_Y + _height);
glTexCoord2f(0.0, 1.0); glVertex2f(WIN_X + (_width/4) * i, WIN_Y + _height); glTexCoord2f(0.0, 1.0); glVertex2f(WIN_X + (_width/4) * i, WIN_Y + _height);
glEnd(); glEnd();
state.popStateSet();
state.apply();
// bottom row of textures...(2,4,6,8) // bottom row of textures...(2,4,6,8)
glBindTexture(GL_TEXTURE_2D, _mbg[(i*2)+1]->getHandle()); state.pushStateSet(_mbg[i*2+1].get());
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); state.apply();
glBegin(GL_POLYGON); glBegin(GL_POLYGON);
glTexCoord2f(0.0, 0.0); glVertex2f(WIN_X + (_width/4) * i, WIN_Y); glTexCoord2f(0.0, 0.0); glVertex2f(WIN_X + (_width/4) * i, WIN_Y);
glTexCoord2f(1.0, 0.0); glVertex2f(WIN_X + (_width/4) * (i+1), WIN_Y); glTexCoord2f(1.0, 0.0); glVertex2f(WIN_X + (_width/4) * (i+1), WIN_Y);
glTexCoord2f(1.0, 1.0); glVertex2f(WIN_X + (_width/4) * (i+1), WIN_Y + (_height/2)); glTexCoord2f(1.0, 1.0); glVertex2f(WIN_X + (_width/4) * (i+1), WIN_Y + (_height/2));
glTexCoord2f(0.0, 1.0); glVertex2f(WIN_X + (_width/4) * i, WIN_Y + (_height/2)); glTexCoord2f(0.0, 1.0); glVertex2f(WIN_X + (_width/4) * i, WIN_Y + (_height/2));
glEnd(); glEnd();
state.popStateSet();
state.apply();
} }
} }
@ -448,7 +455,7 @@ FGPanel::draw()
glEnable(GL_CLIP_PLANE2); glEnable(GL_CLIP_PLANE2);
glEnable(GL_CLIP_PLANE3); glEnable(GL_CLIP_PLANE3);
glPopMatrix(); glPopMatrix();
instr->draw(); instr->draw(state);
glPopMatrix(); glPopMatrix();
} }
@ -458,24 +465,24 @@ FGPanel::draw()
glDisable(GL_CLIP_PLANE2); glDisable(GL_CLIP_PLANE2);
glDisable(GL_CLIP_PLANE3); glDisable(GL_CLIP_PLANE3);
state.popStateSet();
state.apply();
// Draw yellow "hotspots" if directed to. This is a panel authoring // Draw yellow "hotspots" if directed to. This is a panel authoring
// feature; not intended to be high performance or to look good. // feature; not intended to be high performance or to look good.
if ( fgGetBool("/sim/panel-hotspots") ) { if ( fgGetBool("/sim/panel-hotspots") ) {
glDisable(GL_TEXTURE_2D); static osg::ref_ptr<osg::StateSet> hotspotStateSet = new osg::StateSet;
hotspotStateSet->setTextureMode(0, GL_TEXTURE_2D, osg::StateAttribute::OFF);
state.pushStateSet(hotspotStateSet.get());
state.apply();
glColor3f(1, 1, 0); glColor3f(1, 1, 0);
for ( unsigned int i = 0; i < _instruments.size(); i++ ) for ( unsigned int i = 0; i < _instruments.size(); i++ )
_instruments[i]->drawHotspots(); _instruments[i]->drawHotspots(state);
state.popStateSet();
state.apply();
} }
// restore some original state
if ( _enable_depth_test )
glDepthFunc(GL_LESS);
glPopAttrib();
glPolygonOffset(0, 0);
glDisable(GL_POLYGON_OFFSET_FILL);
} }
/** /**
@ -502,19 +509,28 @@ FGPanel::getVisibility () const
* Set the panel's background texture. * Set the panel's background texture.
*/ */
void void
FGPanel::setBackground (ssgTexture * texture) FGPanel::setBackground (osg::Texture2D* texture)
{ {
_bg = texture; osg::StateSet* stateSet = new osg::StateSet;
stateSet->setTextureAttribute(0, texture);
stateSet->setTextureMode(0, GL_TEXTURE_2D, osg::StateAttribute::ON);
stateSet->setTextureAttribute(0, new osg::TexEnv(osg::TexEnv::MODULATE));
_bg = stateSet;
} }
/** /**
* Set the panel's multiple background textures. * Set the panel's multiple background textures.
*/ */
void void
FGPanel::setMultiBackground (ssgTexture * texture, int idx) FGPanel::setMultiBackground (osg::Texture2D* texture, int idx)
{ {
_bg = 0; _bg = 0;
_mbg[idx] = texture;
osg::StateSet* stateSet = new osg::StateSet;
stateSet->setTextureAttribute(0, texture);
stateSet->setTextureMode(0, GL_TEXTURE_2D, osg::StateAttribute::ON);
stateSet->setTextureAttribute(0, new osg::TexEnv(osg::TexEnv::MODULATE));
_mbg[idx] = stateSet;
} }
/** /**
@ -702,7 +718,7 @@ FGPanelInstrument::~FGPanelInstrument ()
} }
void void
FGPanelInstrument::drawHotspots() FGPanelInstrument::drawHotspots(osg::State& state)
{ {
for ( unsigned int i = 0; i < _actions.size(); i++ ) { for ( unsigned int i = 0; i < _actions.size(); i++ ) {
FGPanelAction* a = _actions[i]; FGPanelAction* a = _actions[i];
@ -800,14 +816,14 @@ FGLayeredInstrument::~FGLayeredInstrument ()
} }
void void
FGLayeredInstrument::draw () FGLayeredInstrument::draw (osg::State& state)
{ {
if (!test()) if (!test())
return; return;
for (int i = 0; i < (int)_layers.size(); i++) { for (int i = 0; i < (int)_layers.size(); i++) {
glPushMatrix(); glPushMatrix();
_layers[i]->draw(); _layers[i]->draw(state);
glPopMatrix(); glPopMatrix();
} }
} }
@ -857,7 +873,7 @@ FGSpecialInstrument::~FGSpecialInstrument ()
} }
void void
FGSpecialInstrument::draw () FGSpecialInstrument::draw (osg::State& state)
{ {
complex->draw(); complex->draw();
} }
@ -947,13 +963,13 @@ FGGroupLayer::~FGGroupLayer ()
} }
void void
FGGroupLayer::draw () FGGroupLayer::draw (osg::State& state)
{ {
if (test()) { if (test()) {
transform(); transform();
int nLayers = _layers.size(); int nLayers = _layers.size();
for (int i = 0; i < nLayers; i++) for (int i = 0; i < nLayers; i++)
_layers[i]->draw(); _layers[i]->draw(state);
} }
} }
@ -984,14 +1000,15 @@ FGTexturedLayer::~FGTexturedLayer ()
void void
FGTexturedLayer::draw () FGTexturedLayer::draw (osg::State& state)
{ {
if (test()) { if (test()) {
int w2 = _w / 2; int w2 = _w / 2;
int h2 = _h / 2; int h2 = _h / 2;
transform(); transform();
glBindTexture(GL_TEXTURE_2D, _texture.getTexture()->getHandle()); state.pushStateSet(_texture.getTexture());
state.apply();
glBegin(GL_POLYGON); glBegin(GL_POLYGON);
if (_emissive) { if (_emissive) {
@ -1007,6 +1024,8 @@ FGTexturedLayer::draw ()
glTexCoord2f(_texture.getMaxX(), _texture.getMaxY()); glVertex2f(w2, h2); glTexCoord2f(_texture.getMaxX(), _texture.getMaxY()); glVertex2f(w2, h2);
glTexCoord2f(_texture.getMinX(), _texture.getMaxY()); glVertex2f(-w2, h2); glTexCoord2f(_texture.getMinX(), _texture.getMaxY()); glVertex2f(-w2, h2);
glEnd(); glEnd();
state.popStateSet();
state.apply();
} }
} }
@ -1034,7 +1053,7 @@ FGTextLayer::~FGTextLayer ()
} }
void void
FGTextLayer::draw () FGTextLayer::draw (osg::State& state)
{ {
if (test()) { if (test()) {
glColor4fv(_color); glColor4fv(_color);
@ -1187,14 +1206,14 @@ FGSwitchLayer::FGSwitchLayer ()
} }
void void
FGSwitchLayer::draw () FGSwitchLayer::draw (osg::State& state)
{ {
if (test()) { if (test()) {
transform(); transform();
int nLayers = _layers.size(); int nLayers = _layers.size();
for (int i = 0; i < nLayers; i++) { for (int i = 0; i < nLayers; i++) {
if (_layers[i]->test()) { if (_layers[i]->test()) {
_layers[i]->draw(); _layers[i]->draw(state);
return; return;
} }
} }

View file

@ -34,6 +34,10 @@
# include <windows.h> # include <windows.h>
#endif #endif
#include <osg/ref_ptr>
#include <osg/StateSet>
#include <osg/Texture2D>
#include <plib/fnt.h> #include <plib/fnt.h>
#include <simgear/compiler.h> #include <simgear/compiler.h>
@ -54,7 +58,6 @@ SG_USING_STD(vector);
SG_USING_STD(map); SG_USING_STD(map);
class ssgTexture;
class FGPanelInstrument; class FGPanelInstrument;
@ -72,9 +75,9 @@ class FGPanelInstrument;
class FGTextureManager class FGTextureManager
{ {
public: public:
static ssgTexture * createTexture(const string &relativePath); static osg::Texture2D* createTexture(const string &relativePath);
private: private:
static map<string,ssgTexture *> _textureMap; static map<string,osg::ref_ptr<osg::Texture2D> > _textureMap;
}; };
@ -97,7 +100,7 @@ public:
virtual const string &getPath () const { return _path; } virtual const string &getPath () const { return _path; }
virtual ssgTexture * getTexture (); virtual osg::StateSet* getTexture ();
virtual void setCrop (float minX, float minY, float maxX, float maxY) { virtual void setCrop (float minX, float minY, float maxX, float maxY) {
_minX = minX; _minY = minY; _maxX = maxX; _maxY = maxY; _minX = minX; _minY = minY; _maxX = maxX; _maxY = maxY;
@ -111,7 +114,7 @@ public:
private: private:
string _path; string _path;
ssgTexture * _texture; osg::ref_ptr<osg::StateSet> _texture;
float _minX, _minY, _maxX, _maxY; float _minX, _minY, _maxX, _maxY;
}; };
@ -141,9 +144,10 @@ public:
virtual void init (); virtual void init ();
virtual void bind (); virtual void bind ();
virtual void unbind (); virtual void unbind ();
virtual void draw (); virtual void draw (osg::State& state);
virtual void update (double dt); virtual void update (double);
virtual void update (GLfloat winx, GLfloat winw, GLfloat winy, GLfloat winh); void update (osg::State& state);
virtual void update (osg::State& state, GLfloat winx, GLfloat winw, GLfloat winy, GLfloat winh);
virtual void updateMouseDelay(); virtual void updateMouseDelay();
@ -151,10 +155,10 @@ public:
virtual void addInstrument (FGPanelInstrument * instrument); virtual void addInstrument (FGPanelInstrument * instrument);
// Background texture. // Background texture.
virtual void setBackground (ssgTexture * texture); virtual void setBackground (osg::Texture2D* texture);
// Background multiple textures. // Background multiple textures.
virtual void setMultiBackground (ssgTexture * texture, int idx); virtual void setMultiBackground (osg::Texture2D* texture, int idx);
// Make the panel visible or invisible. // Make the panel visible or invisible.
virtual bool getVisibility () const; virtual bool getVisibility () const;
@ -208,8 +212,8 @@ private:
SGConstPropertyNode_ptr _xsize_node; SGConstPropertyNode_ptr _xsize_node;
SGConstPropertyNode_ptr _ysize_node; SGConstPropertyNode_ptr _ysize_node;
ssgTexture * _bg; osg::ref_ptr<osg::StateSet> _bg;
ssgTexture * _mbg[8]; osg::ref_ptr<osg::StateSet> _mbg[8];
// List of instruments in panel. // List of instruments in panel.
instrument_list_type _instruments; instrument_list_type _instruments;
bool _enable_depth_test; bool _enable_depth_test;
@ -335,7 +339,7 @@ public:
FGInstrumentLayer (int w = -1, int h = -1); FGInstrumentLayer (int w = -1, int h = -1);
virtual ~FGInstrumentLayer (); virtual ~FGInstrumentLayer ();
virtual void draw () = 0; virtual void draw (osg::State& state) = 0;
virtual void transform () const; virtual void transform () const;
virtual int getWidth () const { return _w; } virtual int getWidth () const { return _w; }
@ -377,8 +381,8 @@ public:
FGPanelInstrument (int x, int y, int w, int h); FGPanelInstrument (int x, int y, int w, int h);
virtual ~FGPanelInstrument (); virtual ~FGPanelInstrument ();
virtual void draw () = 0; virtual void draw (osg::State& state) = 0;
virtual void drawHotspots(); virtual void drawHotspots(osg::State& state);
virtual void setPosition(int x, int y); virtual void setPosition(int x, int y);
virtual void setSize(int w, int h); virtual void setSize(int w, int h);
@ -414,7 +418,7 @@ public:
FGLayeredInstrument (int x, int y, int w, int h); FGLayeredInstrument (int x, int y, int w, int h);
virtual ~FGLayeredInstrument (); virtual ~FGLayeredInstrument ();
virtual void draw (); virtual void draw (osg::State& state);
// Transfer pointer ownership!! // Transfer pointer ownership!!
virtual int addLayer (FGInstrumentLayer *layer); virtual int addLayer (FGInstrumentLayer *layer);
@ -444,7 +448,7 @@ public:
//FGSpecialInstrument (int x, int y, int w, int h); //FGSpecialInstrument (int x, int y, int w, int h);
virtual ~FGSpecialInstrument (); virtual ~FGSpecialInstrument ();
virtual void draw (); virtual void draw (osg::State& state);
protected: protected:
DCLGPS* complex; DCLGPS* complex;
@ -463,7 +467,7 @@ class FGGroupLayer : public FGInstrumentLayer
public: public:
FGGroupLayer (); FGGroupLayer ();
virtual ~FGGroupLayer (); virtual ~FGGroupLayer ();
virtual void draw (); virtual void draw (osg::State& state);
// transfer pointer ownership // transfer pointer ownership
virtual void addLayer (FGInstrumentLayer * layer); virtual void addLayer (FGInstrumentLayer * layer);
protected: protected:
@ -485,7 +489,7 @@ public:
FGTexturedLayer (const FGCroppedTexture &texture, int w = -1, int h = -1); FGTexturedLayer (const FGCroppedTexture &texture, int w = -1, int h = -1);
virtual ~FGTexturedLayer (); virtual ~FGTexturedLayer ();
virtual void draw (); virtual void draw (osg::State& state);
virtual void setTexture (const FGCroppedTexture &texture) { virtual void setTexture (const FGCroppedTexture &texture) {
_texture = texture; _texture = texture;
@ -540,7 +544,7 @@ public:
FGTextLayer (int w = -1, int h = -1); FGTextLayer (int w = -1, int h = -1);
virtual ~FGTextLayer (); virtual ~FGTextLayer ();
virtual void draw (); virtual void draw (osg::State& state);
// Transfer pointer!! // Transfer pointer!!
virtual void addChunk (Chunk * chunk); virtual void addChunk (Chunk * chunk);
@ -576,7 +580,7 @@ class FGSwitchLayer : public FGGroupLayer
public: public:
// Transfer pointers!! // Transfer pointers!!
FGSwitchLayer (); FGSwitchLayer ();
virtual void draw (); virtual void draw (osg::State& state);
}; };

View file

@ -800,29 +800,32 @@ bool
FGInterface::prepare_ground_cache_m(double ref_time, const double pt[3], FGInterface::prepare_ground_cache_m(double ref_time, const double pt[3],
double rad) double rad)
{ {
return ground_cache.prepare_ground_cache(ref_time, pt, rad); return ground_cache.prepare_ground_cache(ref_time, SGVec3d(pt), rad);
} }
bool FGInterface::prepare_ground_cache_ft(double ref_time, const double pt[3], bool FGInterface::prepare_ground_cache_ft(double ref_time, const double pt[3],
double rad) double rad)
{ {
// Convert units and do the real work. // Convert units and do the real work.
sgdVec3 pt_ft; SGVec3d pt_ft = SG_FEET_TO_METER*SGVec3d(pt);
sgdScaleVec3( pt_ft, pt, SG_FEET_TO_METER );
return ground_cache.prepare_ground_cache(ref_time, pt_ft, rad*SG_FEET_TO_METER); return ground_cache.prepare_ground_cache(ref_time, pt_ft, rad*SG_FEET_TO_METER);
} }
bool bool
FGInterface::is_valid_m(double *ref_time, double pt[3], double *rad) FGInterface::is_valid_m(double *ref_time, double pt[3], double *rad)
{ {
return ground_cache.is_valid(ref_time, pt, rad); SGVec3d _pt;
bool valid = ground_cache.is_valid(*ref_time, _pt, *rad);
sgdCopyVec3(pt, _pt.data());
return valid;
} }
bool FGInterface::is_valid_ft(double *ref_time, double pt[3], double *rad) bool FGInterface::is_valid_ft(double *ref_time, double pt[3], double *rad)
{ {
// Convert units and do the real work. // Convert units and do the real work.
bool found_ground = ground_cache.is_valid(ref_time, pt, rad); SGVec3d _pt;
sgdScaleVec3(pt, SG_METER_TO_FEET); bool found_ground = ground_cache.is_valid(*ref_time, _pt, *rad);
sgdScaleVec3(pt, _pt.data(), SG_METER_TO_FEET);
*rad *= SG_METER_TO_FEET; *rad *= SG_METER_TO_FEET;
return found_ground; return found_ground;
} }
@ -831,7 +834,13 @@ double
FGInterface::get_cat_m(double t, const double pt[3], FGInterface::get_cat_m(double t, const double pt[3],
double end[2][3], double vel[2][3]) double end[2][3], double vel[2][3])
{ {
return ground_cache.get_cat(t, pt, end, vel); SGVec3d _end[2], _vel[2];
double dist = ground_cache.get_cat(t, SGVec3d(pt), _end, _vel);
for (int k=0; k<2; ++k) {
sgdCopyVec3( end[k], _end[k].data() );
sgdCopyVec3( vel[k], _vel[k].data() );
}
return dist;
} }
double double
@ -839,12 +848,12 @@ FGInterface::get_cat_ft(double t, const double pt[3],
double end[2][3], double vel[2][3]) double end[2][3], double vel[2][3])
{ {
// Convert units and do the real work. // Convert units and do the real work.
sgdVec3 pt_m; SGVec3d pt_m = SG_FEET_TO_METER*SGVec3d(pt);
sgdScaleVec3( pt_m, pt, SG_FEET_TO_METER ); SGVec3d _end[2], _vel[2];
double dist = ground_cache.get_cat(t, pt_m, end, vel); double dist = ground_cache.get_cat(t, pt_m, _end, _vel);
for (int k=0; k<2; ++k) { for (int k=0; k<2; ++k) {
sgdScaleVec3( end[k], SG_METER_TO_FEET ); sgdScaleVec3( end[k], _end[k].data(), SG_METER_TO_FEET );
sgdScaleVec3( vel[k], SG_METER_TO_FEET ); sgdScaleVec3( vel[k], _vel[k].data(), SG_METER_TO_FEET );
} }
return dist*SG_METER_TO_FEET; return dist*SG_METER_TO_FEET;
} }
@ -857,8 +866,12 @@ FGInterface::get_agl_m(double t, const double pt[3],
double *frictionFactor, double *agl) double *frictionFactor, double *agl)
{ {
const SGMaterial* material; const SGMaterial* material;
bool ret = ground_cache.get_agl(t, pt, 2.0, contact, normal, vel, type, SGVec3d _contact, _normal, _vel;
&material, agl); bool ret = ground_cache.get_agl(t, SGVec3d(pt), 2.0, _contact, _normal,
_vel, type, &material, agl);
sgdCopyVec3(contact, _contact.data());
sgdCopyVec3(normal, _normal.data());
sgdCopyVec3(vel, _vel.data());
if (material) { if (material) {
*loadCapacity = material->get_load_resistence(); *loadCapacity = material->get_load_resistence();
*frictionFactor = material->get_friction_factor(); *frictionFactor = material->get_friction_factor();
@ -878,15 +891,16 @@ FGInterface::get_agl_ft(double t, const double pt[3],
double *frictionFactor, double *agl) double *frictionFactor, double *agl)
{ {
// Convert units and do the real work. // Convert units and do the real work.
sgdVec3 pt_m; SGVec3d pt_m = SG_FEET_TO_METER*SGVec3d(pt);
sgdScaleVec3( pt_m, pt, SG_FEET_TO_METER );
const SGMaterial* material; const SGMaterial* material;
bool ret = ground_cache.get_agl(t, pt_m, 2.0, contact, normal, vel, SGVec3d _contact, _normal, _vel;
bool ret = ground_cache.get_agl(t, pt_m, 2.0, _contact, _normal, _vel,
type, &material, agl); type, &material, agl);
// Convert units back ... // Convert units back ...
sgdScaleVec3( contact, SG_METER_TO_FEET ); sgdScaleVec3( contact, _contact.data(), SG_METER_TO_FEET );
sgdScaleVec3( vel, SG_METER_TO_FEET ); sgdScaleVec3( vel, _vel.data(), SG_METER_TO_FEET );
sgdCopyVec3( normal, _normal.data() );
*agl *= SG_METER_TO_FEET; *agl *= SG_METER_TO_FEET;
// return material properties if available // return material properties if available
@ -906,8 +920,13 @@ FGInterface::get_agl_m(double t, const double pt[3], double max_altoff,
double contact[3], double normal[3], double vel[3], double contact[3], double normal[3], double vel[3],
int *type, const SGMaterial** material, double *agl) int *type, const SGMaterial** material, double *agl)
{ {
return ground_cache.get_agl(t, pt, max_altoff, contact, normal, vel, type, SGVec3d _contact, _normal, _vel;
material, agl); bool found = ground_cache.get_agl(t, SGVec3d(pt), max_altoff, _contact,
_normal, _vel, type, material, agl);
sgdCopyVec3(contact, _contact.data());
sgdCopyVec3(normal, _normal.data());
sgdCopyVec3(vel, _vel.data());
return found;
} }
bool bool
@ -916,14 +935,15 @@ FGInterface::get_agl_ft(double t, const double pt[3], double max_altoff,
int *type, const SGMaterial** material, double *agl) int *type, const SGMaterial** material, double *agl)
{ {
// Convert units and do the real work. // Convert units and do the real work.
sgdVec3 pt_m; SGVec3d pt_m = SG_FEET_TO_METER*SGVec3d(pt);
sgdScaleVec3( pt_m, pt, SG_FEET_TO_METER ); SGVec3d _contact, _normal, _vel;
bool ret = ground_cache.get_agl(t, pt_m, SG_FEET_TO_METER * max_altoff, bool ret = ground_cache.get_agl(t, pt_m, SG_FEET_TO_METER * max_altoff,
contact, normal, vel, _contact, _normal, _vel,
type, material, agl); type, material, agl);
// Convert units back ... // Convert units back ...
sgdScaleVec3( contact, SG_METER_TO_FEET ); sgdScaleVec3( contact, _contact.data(), SG_METER_TO_FEET );
sgdScaleVec3( vel, SG_METER_TO_FEET ); sgdScaleVec3( vel, _vel.data(), SG_METER_TO_FEET );
sgdCopyVec3( normal, _normal.data() );
*agl *= SG_METER_TO_FEET; *agl *= SG_METER_TO_FEET;
return ret; return ret;
} }
@ -932,37 +952,37 @@ FGInterface::get_agl_ft(double t, const double pt[3], double max_altoff,
double double
FGInterface::get_groundlevel_m(double lat, double lon, double alt) FGInterface::get_groundlevel_m(double lat, double lon, double alt)
{ {
sgdVec3 pos, cpos;
// Compute the cartesian position of the given lat/lon/alt. // Compute the cartesian position of the given lat/lon/alt.
sgGeodToCart(lat, lon, alt, pos); SGVec3d pos = SGVec3d::fromGeod(SGGeod::fromRadM(lon, lat, alt));
// FIXME: how to handle t - ref_time differences ??? // FIXME: how to handle t - ref_time differences ???
SGVec3d cpos;
double ref_time, radius; double ref_time, radius;
// Prepare the ground cache for that position. // Prepare the ground cache for that position.
if (!is_valid_m(&ref_time, cpos, &radius)) { if (!is_valid_m(&ref_time, cpos.data(), &radius)) {
bool ok = prepare_ground_cache_m(ref_time, pos, 10); bool ok = prepare_ground_cache_m(ref_time, pos.data(), 10);
/// This is most likely the case when the given altitude is /// This is most likely the case when the given altitude is
/// too low, try with a new altitude of 10000m, that should be /// too low, try with a new altitude of 10000m, that should be
/// sufficient to find a ground level below everywhere on our planet /// sufficient to find a ground level below everywhere on our planet
if (!ok) { if (!ok) {
sgGeodToCart(lat, lon, 10000, pos); pos = SGVec3d::fromGeod(SGGeod::fromRadM(lon, lat, 10000));
/// If there is still no ground, return sea level radius /// If there is still no ground, return sea level radius
if (!prepare_ground_cache_m(ref_time, pos, 10)) if (!prepare_ground_cache_m(ref_time, pos.data(), 10))
return 0; return 0;
} }
} else if (radius*radius <= sgdDistanceSquaredVec3(pos, cpos)) { } else if (radius*radius <= distSqr(pos, cpos)) {
/// We reuse the old radius value, but only if it is at least 10 Meters .. /// We reuse the old radius value, but only if it is at least 10 Meters ..
if (!(10 < radius)) // Well this strange compare is nan safe if (!(10 < radius)) // Well this strange compare is nan safe
radius = 10; radius = 10;
bool ok = prepare_ground_cache_m(ref_time, pos, radius); bool ok = prepare_ground_cache_m(ref_time, pos.data(), radius);
/// This is most likely the case when the given altitude is /// This is most likely the case when the given altitude is
/// too low, try with a new altitude of 10000m, that should be /// too low, try with a new altitude of 10000m, that should be
/// sufficient to find a ground level below everywhere on our planet /// sufficient to find a ground level below everywhere on our planet
if (!ok) { if (!ok) {
sgGeodToCart(lat, lon, 10000, pos); pos = SGVec3d::fromGeod(SGGeod::fromRadM(lon, lat, 10000));
/// If there is still no ground, return sea level radius /// If there is still no ground, return sea level radius
if (!prepare_ground_cache_m(ref_time, pos, radius)) if (!prepare_ground_cache_m(ref_time, pos.data(), radius))
return 0; return 0;
} }
} }
@ -973,24 +993,28 @@ FGInterface::get_groundlevel_m(double lat, double lon, double alt)
// the returns stem from the groundcache or from the coarse // the returns stem from the groundcache or from the coarse
// computations below the groundcache. The contact point is still something // computations below the groundcache. The contact point is still something
// valid, the normals and the other returns just contain some defaults. // valid, the normals and the other returns just contain some defaults.
get_agl_m(ref_time, pos, 2.0, contact, normal, vel, &type, 0, &agl); get_agl_m(ref_time, pos.data(), 2.0, contact, normal, vel, &type, 0, &agl);
Point3D geodPos = sgCartToGeod(Point3D(contact[0], contact[1], contact[2])); SGGeod geod = SGGeod::fromCart(SGVec3d(contact));
return geodPos.elev(); return geod.getElevationM();
} }
bool bool
FGInterface::caught_wire_m(double t, const double pt[4][3]) FGInterface::caught_wire_m(double t, const double pt[4][3])
{ {
return ground_cache.caught_wire(t, pt); SGVec3d pt_m[4];
for (int i=0; i<4; ++i)
sgdCopyVec3(pt_m[i].data(), pt[i]);
return ground_cache.caught_wire(t, pt_m);
} }
bool bool
FGInterface::caught_wire_ft(double t, const double pt[4][3]) FGInterface::caught_wire_ft(double t, const double pt[4][3])
{ {
// Convert units and do the real work. // Convert units and do the real work.
double pt_m[4][3]; SGVec3d pt_m[4];
for (int i=0; i<4; ++i) for (int i=0; i<4; ++i)
sgdScaleVec3(pt_m[i], pt[i], SG_FEET_TO_METER); sgdScaleVec3(pt_m[i].data(), pt[i], SG_FEET_TO_METER);
return ground_cache.caught_wire(t, pt_m); return ground_cache.caught_wire(t, pt_m);
} }
@ -998,17 +1022,24 @@ FGInterface::caught_wire_ft(double t, const double pt[4][3])
bool bool
FGInterface::get_wire_ends_m(double t, double end[2][3], double vel[2][3]) FGInterface::get_wire_ends_m(double t, double end[2][3], double vel[2][3])
{ {
return ground_cache.get_wire_ends(t, end, vel); SGVec3d _end[2], _vel[2];
bool ret = ground_cache.get_wire_ends(t, _end, _vel);
for (int k=0; k<2; ++k) {
sgdCopyVec3( end[k], _end[k].data() );
sgdCopyVec3( vel[k], _vel[k].data() );
}
return ret;
} }
bool bool
FGInterface::get_wire_ends_ft(double t, double end[2][3], double vel[2][3]) FGInterface::get_wire_ends_ft(double t, double end[2][3], double vel[2][3])
{ {
// Convert units and do the real work. // Convert units and do the real work.
bool ret = ground_cache.get_wire_ends(t, end, vel); SGVec3d _end[2], _vel[2];
bool ret = ground_cache.get_wire_ends(t, _end, _vel);
for (int k=0; k<2; ++k) { for (int k=0; k<2; ++k) {
sgdScaleVec3( end[k], SG_METER_TO_FEET ); sgdScaleVec3( end[k], _end[k].data(), SG_METER_TO_FEET );
sgdScaleVec3( vel[k], SG_METER_TO_FEET ); sgdScaleVec3( vel[k], _vel[k].data(), SG_METER_TO_FEET );
} }
return ret; return ret;
} }

File diff suppressed because it is too large Load diff

View file

@ -23,12 +23,12 @@
#ifndef _GROUNDCACHE_HXX #ifndef _GROUNDCACHE_HXX
#define _GROUNDCACHE_HXX #define _GROUNDCACHE_HXX
#include <plib/sg.h>
#include <plib/ssg.h>
#include <simgear/compiler.h> #include <simgear/compiler.h>
#include <simgear/constants.h> #include <simgear/constants.h>
#include <simgear/math/SGMath.hxx>
class SGMaterial; class SGMaterial;
class GroundCacheFillVisitor;
class FGGroundCache { class FGGroundCache {
public: public:
@ -42,19 +42,18 @@ public:
// Prepare the ground cache for the wgs84 position pt_*. // Prepare the ground cache for the wgs84 position pt_*.
// That is take all vertices in the ball with radius rad around the // That is take all vertices in the ball with radius rad around the
// position given by the pt_* and store them in a local scene graph. // position given by the pt_* and store them in a local scene graph.
bool prepare_ground_cache(double ref_time, const double pt[3], bool prepare_ground_cache(double ref_time, const SGVec3d& pt,
double rad); double rad);
// Returns true if the cache is valid. // Returns true if the cache is valid.
// Also the reference time, point and radius values where the cache // Also the reference time, point and radius values where the cache
// is valid for are returned. // is valid for are returned.
bool is_valid(double *ref_time, double pt[3], double *rad); bool is_valid(double& ref_time, SGVec3d& pt, double& rad);
// Return the nearest catapult to the given point // Return the nearest catapult to the given point
// pt in wgs84 coordinates. // pt in wgs84 coordinates.
double get_cat(double t, const double pt[3], double get_cat(double t, const SGVec3d& pt,
double end[2][3], double vel[2][3]); SGVec3d end[2], SGVec3d vel[2]);
// Return the altitude above ground below the wgs84 point pt // Return the altitude above ground below the wgs84 point pt
@ -63,8 +62,8 @@ public:
// this kind kind of ground can carry, the friction factor between // this kind kind of ground can carry, the friction factor between
// 0 and 1 which can be used to model lower friction with wet runways // 0 and 1 which can be used to model lower friction with wet runways
// and finally the altitude above ground. // and finally the altitude above ground.
bool get_agl(double t, const double pt[3], double max_altoff, bool get_agl(double t, const SGVec3d& pt, double max_altoff,
double contact[3], double normal[3], double vel[3], SGVec3d& contact, SGVec3d& normal, SGVec3d& vel,
int *type, const SGMaterial** material, double *agl); int *type, const SGMaterial** material, double *agl);
// Return 1 if the hook intersects with a wire. // Return 1 if the hook intersects with a wire.
@ -72,51 +71,54 @@ public:
// intersects with the line representing the wire. // intersects with the line representing the wire.
// If the wire is caught, the cache will trace this wires endpoints until // If the wire is caught, the cache will trace this wires endpoints until
// the FDM calls release_wire(). // the FDM calls release_wire().
bool caught_wire(double t, const double pt[4][3]); bool caught_wire(double t, const SGVec3d pt[4]);
// Return the location and speed of the wire endpoints. // Return the location and speed of the wire endpoints.
bool get_wire_ends(double t, double end[2][3], double vel[2][3]); bool get_wire_ends(double t, SGVec3d end[2], SGVec3d vel[2]);
// Tell the cache code that it does no longer need to care for // Tell the cache code that it does no longer need to care for
// the wire end position. // the wire end position.
void release_wire(void); void release_wire(void);
private: private:
friend class GroundCacheFillVisitor;
struct Triangle { struct Triangle {
Triangle() : material(0) {} Triangle() : material(0) {}
// The edge vertices. // The edge vertices.
sgdVec3 vertices[3]; SGVec3d vertices[3];
// The surface normal. // The surface normal.
sgdVec4 plane; SGVec4d plane;
// The bounding shpere. // The bounding shpere.
sgdSphere sphere; SGVec3d boundCenter;
double boundRadius;
// The linear and angular velocity. // The linear and angular velocity.
sgdVec3 velocity; SGVec3d velocity;
sgdVec3 rotation; SGVec3d rotation;
sgdVec3 rotation_pivot; SGVec3d rotation_pivot;
// Ground type // Ground type
int type; int type;
// the simgear material reference, contains friction coeficients ... // the simgear material reference, contains friction coeficients ...
const SGMaterial* material; const SGMaterial* material;
}; };
struct Catapult { struct Catapult {
sgdVec3 start; SGVec3d start;
sgdVec3 end; SGVec3d end;
sgdVec3 velocity; SGVec3d velocity;
sgdVec3 rotation; SGVec3d rotation;
sgdVec3 rotation_pivot; SGVec3d rotation_pivot;
}; };
struct Wire { struct Wire {
sgdVec3 ends[2]; SGVec3d ends[2];
sgdVec3 velocity; SGVec3d velocity;
sgdVec3 rotation; SGVec3d rotation;
sgdVec3 rotation_pivot; SGVec3d rotation_pivot;
int wire_id; int wire_id;
}; };
// The center of the cache. // The center of the cache.
sgdVec3 cache_center; SGVec3d cache_center;
// Approximate ground radius. // Approximate ground radius.
// In case the aircraft is too high above ground. // In case the aircraft is too high above ground.
double ground_radius; double ground_radius;
@ -133,37 +135,23 @@ private:
// The point and radius where the cache is built around. // The point and radius where the cache is built around.
// That are the arguments that were given to prepare_ground_cache. // That are the arguments that were given to prepare_ground_cache.
sgdVec3 reference_wgs84_point; SGVec3d reference_wgs84_point;
double reference_vehicle_radius; double reference_vehicle_radius;
SGVec3d down;
bool found_ground; bool found_ground;
// Fills the environment cache with everything inside the sphere sp.
void cache_fill(ssgBranch *branch, sgdMat4 xform,
sgdSphere* sp, sgdVec3 down, sgdSphere* wsp);
// compute the ground property of this leaf.
void putSurfaceLeafIntoCache(const sgdSphere *sp, const sgdMat4 xform,
bool sphIsec, sgdVec3 down, ssgLeaf *l);
void putLineLeafIntoCache(const sgdSphere *wsp, const sgdMat4 xform,
ssgLeaf *l);
// Helper class to hold some properties of the ground triangle. // Helper class to hold some properties of the ground triangle.
struct GroundProperty { struct GroundProperty {
GroundProperty() : type(0), material(0) {} GroundProperty() : type(0), material(0) {}
int type; int type;
int wire_id; int wire_id;
sgdVec3 vel; SGVec3d vel;
sgdVec3 rot; SGVec3d rot;
sgdVec3 pivot; SGVec3d pivot;
const SGMaterial* material; const SGMaterial* material;
}; };
// compute the ground property of this leaf.
static GroundProperty extractGroundProperty( ssgLeaf* leaf );
static void velocityTransformTriangle(double dt, Triangle& dst, static void velocityTransformTriangle(double dt, Triangle& dst,
const Triangle& src); const Triangle& src);
}; };

View file

@ -60,8 +60,6 @@
# endif # endif
#endif #endif
#include <plib/ssg.h>
#include <simgear/constants.h> #include <simgear/constants.h>
#include <simgear/debug/logstream.hxx> #include <simgear/debug/logstream.hxx>
#include <simgear/misc/sg_path.hxx> #include <simgear/misc/sg_path.hxx>
@ -283,7 +281,7 @@ void fgHiResDump()
} }
FGRenderer *renderer = globals->get_renderer(); FGRenderer *renderer = globals->get_renderer();
renderer->init(); // renderer->init();
renderer->resize( fgGetInt("/sim/startup/xsize"), renderer->resize( fgGetInt("/sim/startup/xsize"),
fgGetInt("/sim/startup/ysize") ); fgGetInt("/sim/startup/ysize") );
@ -325,11 +323,12 @@ void fgHiResDump()
trTileBuffer(tr, GL_RGB, GL_UNSIGNED_BYTE, tile); trTileBuffer(tr, GL_RGB, GL_UNSIGNED_BYTE, tile);
trImageSize(tr, imageWidth, imageHeight); trImageSize(tr, imageWidth, imageHeight);
trRowOrder(tr, TR_TOP_TO_BOTTOM); trRowOrder(tr, TR_TOP_TO_BOTTOM);
sgFrustum *frustum = ssgGetFrustum(); // OSGFIXME
trFrustum(tr, // sgFrustum *frustum = ssgGetFrustum();
frustum->getLeft(), frustum->getRight(), // trFrustum(tr,
frustum->getBot(), frustum->getTop(), // frustum->getLeft(), frustum->getRight(),
frustum->getNear(), frustum->getFar()); // frustum->getBot(), frustum->getTop(),
// frustum->getNear(), frustum->getFar());
/* Prepare ppm output file */ /* Prepare ppm output file */
while (count < 1000) { while (count < 1000) {
@ -380,13 +379,15 @@ void fgHiResDump()
int curRow = trGet(tr, TR_CURRENT_ROW); int curRow = trGet(tr, TR_CURRENT_ROW);
renderer->update( false ); renderer->update( false );
if ( do_hud ) // OSGFIXME
fgUpdateHUD( curColumn*hud_col_step, curRow*hud_row_step, // if ( do_hud )
(curColumn+1)*hud_col_step, (curRow+1)*hud_row_step ); // fgUpdateHUD( curColumn*hud_col_step, curRow*hud_row_step,
if (do_panel) // (curColumn+1)*hud_col_step, (curRow+1)*hud_row_step );
globals->get_current_panel()->update( // OSGFIXME
curColumn*panel_col_step, panel_col_step, // if (do_panel)
curRow*panel_row_step, panel_row_step ); // globals->get_current_panel()->update(
// curColumn*panel_col_step, panel_col_step,
// curRow*panel_row_step, panel_row_step );
more = trEndTile(tr); more = trEndTile(tr);
/* save tile into tile row buffer*/ /* save tile into tile row buffer*/
@ -472,7 +473,7 @@ GLubyte *hiResScreenCapture( int multiplier )
float fov = oldfov / multiplier; float fov = oldfov / multiplier;
FGViewer *v = globals->get_current_view(); FGViewer *v = globals->get_current_view();
fgSetDouble("/sim/current-view/field-of-view", fov); fgSetDouble("/sim/current-view/field-of-view", fov);
globals->get_renderer()->init(); // globals->get_renderer()->init();
int cur_width = fgGetInt("/sim/startup/xsize"); int cur_width = fgGetInt("/sim/startup/xsize");
int cur_height = fgGetInt("/sim/startup/ysize"); int cur_height = fgGetInt("/sim/startup/ysize");
delete( b1 ); delete( b1 );
@ -554,7 +555,7 @@ void fgDumpSnapShot () {
fgSetBool("/sim/signals/screenshot", true); fgSetBool("/sim/signals/screenshot", true);
FGRenderer *renderer = globals->get_renderer(); FGRenderer *renderer = globals->get_renderer();
renderer->init(); // renderer->init();
renderer->resize( fgGetInt("/sim/startup/xsize"), renderer->resize( fgGetInt("/sim/startup/xsize"),
fgGetInt("/sim/startup/ysize") ); fgGetInt("/sim/startup/ysize") );

View file

@ -59,7 +59,6 @@
#include <Scenery/scenery.hxx> #include <Scenery/scenery.hxx>
#include <Main/renderer.hxx> #include <Main/renderer.hxx>
#include <plib/ssg.h>
#include <simgear/math/sg_geodesy.hxx> #include <simgear/math/sg_geodesy.hxx>
SG_USING_STD(ifstream); SG_USING_STD(ifstream);

View file

@ -144,7 +144,7 @@ void HUD::update(double dt)
} }
void HUD::draw() void HUD::draw(osg::State&)
{ {
if (!isVisible()) if (!isVisible())
return; return;

View file

@ -36,6 +36,8 @@ SG_USING_STD(deque);
SG_USING_STD(vector); SG_USING_STD(vector);
SG_USING_NAMESPACE(std); SG_USING_NAMESPACE(std);
#include <osg/State>
#include <plib/sg.h> #include <plib/sg.h>
#include <simgear/math/SGLimits.hxx> #include <simgear/math/SGLimits.hxx>
@ -134,7 +136,7 @@ public:
void update(double); void update(double);
// called from Main/renderer.cxx to draw 2D and 3D HUD // called from Main/renderer.cxx to draw 2D and 3D HUD
void draw(); void draw(osg::State&);
// listener callback to read various HUD related properties // listener callback to read various HUD related properties
void valueChanged(SGPropertyNode *); void valueChanged(SGPropertyNode *);

View file

@ -98,13 +98,16 @@ void HUD::Runway::draw()
globals->get_viewmgr()->copyToCurrent(); globals->get_viewmgr()->copyToCurrent();
} }
//Set the camera to the cockpit view to get the view of the runway from the cockpit //Set the camera to the cockpit view to get the view of the runway from the cockpit
ssgSetCamera((sgVec4 *)_cockpit_view->get_VIEW()); // OSGFIXME
// ssgSetCamera((sgVec4 *)_cockpit_view->get_VIEW());
get_rwy_points(_points3d); get_rwy_points(_points3d);
//Get the current project matrix //Get the current project matrix
ssgGetProjectionMatrix(projMat); // OSGFIXME
// ssgGetProjectionMatrix(projMat);
// const sgVec4 *viewMat = globals->get_current_view()->get_VIEW(); // const sgVec4 *viewMat = globals->get_current_view()->get_VIEW();
//Get the current model view matrix (cockpit view) //Get the current model view matrix (cockpit view)
ssgGetModelviewMatrix(modelView); // OSGFIXME
// ssgGetModelviewMatrix(modelView);
//Create a rotation matrix to correct for any offsets (other than default offsets) to the model view matrix //Create a rotation matrix to correct for any offsets (other than default offsets) to the model view matrix
sgMat4 xy; //rotation about the Rxy, negate the sin's on Ry sgMat4 xy; //rotation about the Rxy, negate the sin's on Ry
xy[0][0] = cYaw, xy[1][0] = 0.0f, xy[2][0] = -sYaw, xy[3][0] = 0.0f; xy[0][0] = cYaw, xy[1][0] = 0.0f, xy[2][0] = -sYaw, xy[3][0] = 0.0f;
@ -157,7 +160,8 @@ void HUD::Runway::draw()
curr_view->setGoalPitchOffset_deg(gpo); curr_view->setGoalPitchOffset_deg(gpo);
} }
//Set the camera back to the current view //Set the camera back to the current view
ssgSetCamera((sgVec4 *)curr_view); // OSGFIXME
// ssgSetCamera((sgVec4 *)curr_view);
glPopAttrib(); glPopAttrib();
} }

View file

@ -24,7 +24,6 @@
# include "config.h" # include "config.h"
#endif #endif
#include <plib/ssg.h>
#include <simgear/screen/extensions.hxx> #include <simgear/screen/extensions.hxx>
#include <simgear/screen/RenderTexture.h> #include <simgear/screen/RenderTexture.h>
#include <simgear/debug/logstream.hxx> #include <simgear/debug/logstream.hxx>
@ -35,8 +34,8 @@
#include "od_gauge.hxx" #include "od_gauge.hxx"
FGODGauge::FGODGauge() : FGODGauge::FGODGauge() :
rtAvailable( false ), rtAvailable( false )// ,
rt( 0 ) // rt( 0 )
{ {
} }
@ -44,49 +43,49 @@ FGODGauge::FGODGauge() :
// never used // never used
void FGODGauge::allocRT () { void FGODGauge::allocRT () {
GLint colorBits = 0; GLint colorBits = 0;
glGetIntegerv( GL_BLUE_BITS, &colorBits ); // glGetIntegerv( GL_BLUE_BITS, &colorBits );
textureWH = 256; textureWH = 256;
rt = new RenderTexture(); // rt = new RenderTexture();
if( colorBits < 8 ) // if( colorBits < 8 )
rt->Reset("rgba=5,5,5,1 ctt"); // rt->Reset("rgba=5,5,5,1 ctt");
else // else
rt->Reset("rgba ctt"); // rt->Reset("rgba ctt");
if( rt->Initialize(256, 256, true) ) { // if( rt->Initialize(256, 256, true) ) {
SG_LOG(SG_ALL, SG_INFO, "FGODGauge:Initialize sucessfull"); // SG_LOG(SG_ALL, SG_INFO, "FGODGauge:Initialize sucessfull");
if (rt->BeginCapture()) // if (rt->BeginCapture())
{ // {
SG_LOG(SG_ALL, SG_INFO, "FGODGauge:BeginCapture sucessfull, RTT available"); // SG_LOG(SG_ALL, SG_INFO, "FGODGauge:BeginCapture sucessfull, RTT available");
rtAvailable = true; // rtAvailable = true;
glViewport(0, 0, textureWH, textureWH); // glViewport(0, 0, textureWH, textureWH);
glMatrixMode(GL_PROJECTION); // glMatrixMode(GL_PROJECTION);
glLoadIdentity(); // glLoadIdentity();
gluOrtho2D( -256.0, 256.0, -256.0, 256.0 ); // gluOrtho2D( -256.0, 256.0, -256.0, 256.0 );
glMatrixMode(GL_MODELVIEW); // glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); // glLoadIdentity();
glDisable(GL_LIGHTING); // glDisable(GL_LIGHTING);
glEnable(GL_COLOR_MATERIAL); // glEnable(GL_COLOR_MATERIAL);
glDisable(GL_CULL_FACE); // glDisable(GL_CULL_FACE);
glDisable(GL_FOG); // glDisable(GL_FOG);
glDisable(GL_DEPTH_TEST); // glDisable(GL_DEPTH_TEST);
glClearColor(0.0, 0.0, 0.0, 0.0); // glClearColor(0.0, 0.0, 0.0, 0.0);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); // glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glBindTexture(GL_TEXTURE_2D, 0); // glBindTexture(GL_TEXTURE_2D, 0);
glEnable(GL_TEXTURE_2D); // glEnable(GL_TEXTURE_2D);
glEnable(GL_ALPHA_TEST); // glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.0f); // glAlphaFunc(GL_GREATER, 0.0f);
glDisable(GL_SMOOTH); // glDisable(GL_SMOOTH);
glEnable(GL_BLEND); // glEnable(GL_BLEND);
glBlendFunc( GL_ONE, GL_ONE_MINUS_SRC_ALPHA ); // glBlendFunc( GL_ONE, GL_ONE_MINUS_SRC_ALPHA );
rt->EndCapture(); // rt->EndCapture();
} else // } else
SG_LOG(SG_ALL, SG_WARN, "FGODGauge:BeginCapture failed, RTT not available, using backbuffer"); // SG_LOG(SG_ALL, SG_WARN, "FGODGauge:BeginCapture failed, RTT not available, using backbuffer");
} else // } else
SG_LOG(SG_ALL, SG_WARN, "FGODGauge:Initialize failed, RTT not available, using backbuffer"); // SG_LOG(SG_ALL, SG_WARN, "FGODGauge:Initialize failed, RTT not available, using backbuffer");
} }
FGODGauge::~FGODGauge() { FGODGauge::~FGODGauge() {
delete rt; // delete rt;
} }
void FGODGauge::init () { void FGODGauge::init () {
@ -96,58 +95,59 @@ void FGODGauge::update (double dt) {
} }
void FGODGauge::beginCapture(int viewSize) { void FGODGauge::beginCapture(int viewSize) {
if( ! rt ) // if( ! rt )
allocRT(); // allocRT();
if(rtAvailable) { // if(rtAvailable) {
rt->BeginCapture(); // rt->BeginCapture();
} // }
else // else
set2D(); // set2D();
textureWH = viewSize; // textureWH = viewSize;
glViewport(0, 0, textureWH, textureWH); // glViewport(0, 0, textureWH, textureWH);
} }
void FGODGauge::beginCapture(void) { void FGODGauge::beginCapture(void) {
if( ! rt ) // if( ! rt )
allocRT(); // allocRT();
if(rtAvailable) { // if(rtAvailable) {
rt->BeginCapture(); // rt->BeginCapture();
} // }
else // else
set2D(); // set2D();
} }
void FGODGauge::Clear(void) { void FGODGauge::Clear(void) {
if(rtAvailable) { // if(rtAvailable) {
glClear(GL_COLOR_BUFFER_BIT); // glClear(GL_COLOR_BUFFER_BIT);
} // }
else { // else {
glDisable(GL_BLEND); // glDisable(GL_BLEND);
glDisable(GL_ALPHA_TEST); // glDisable(GL_ALPHA_TEST);
glColor4f(0.0f, 0.0f, 0.0f, 0.0f); // glColor4f(0.0f, 0.0f, 0.0f, 0.0f);
glRectf(-256.0, -256.0, 256.0, 256.0); // glRectf(-256.0, -256.0, 256.0, 256.0);
glEnable(GL_BLEND); // glEnable(GL_BLEND);
glBlendFunc( GL_ONE, GL_ONE_MINUS_SRC_ALPHA ); // glBlendFunc( GL_ONE, GL_ONE_MINUS_SRC_ALPHA );
glEnable(GL_ALPHA_TEST); // glEnable(GL_ALPHA_TEST);
} // }
} }
void FGODGauge::endCapture(GLuint texID) { void FGODGauge::endCapture(osg::Texture2D* texID) {
glBindTexture(GL_TEXTURE_2D, texID); // OSGFIXME
// don't use mimaps if we don't update them // glBindTexture(GL_TEXTURE_2D, texID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // // don't use mimaps if we don't update them
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, textureWH, textureWH); // glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, textureWH, textureWH);
if(rtAvailable) // if(rtAvailable)
rt->EndCapture(); // rt->EndCapture();
else // else
set3D(); // set3D();
glBindTexture(GL_TEXTURE_2D, 0); // glBindTexture(GL_TEXTURE_2D, 0);
} }
void FGODGauge::setSize(int viewSize) { void FGODGauge::setSize(int viewSize) {
textureWH = viewSize; textureWH = viewSize;
glViewport(0, 0, textureWH, textureWH); // glViewport(0, 0, textureWH, textureWH);
} }
bool FGODGauge::serviceable(void) { bool FGODGauge::serviceable(void) {
@ -168,9 +168,11 @@ static const char *strip_path(const char *name) {
return fn ; return fn ;
} }
static ssgSimpleState * // OSGFIXME
find_texture_node (ssgEntity * node, const char * name) static osg::StateSet*
find_texture_node(osg::Node* node, const char * name)
{ {
#if 0
if( node->isAKindOf( ssgTypeLeaf() ) ) { if( node->isAKindOf( ssgTypeLeaf() ) ) {
ssgLeaf *leaf = (ssgLeaf *) node; ssgLeaf *leaf = (ssgLeaf *) node;
ssgSimpleState *state = (ssgSimpleState *) leaf->getState(); ssgSimpleState *state = (ssgSimpleState *) leaf->getState();
@ -195,49 +197,51 @@ find_texture_node (ssgEntity * node, const char * name)
return result; return result;
} }
} }
#endif
return 0; return 0;
} }
void FGODGauge::set_texture(const char * name, GLuint new_texture) { void FGODGauge::set_texture(const char * name, osg::Texture2D* new_texture) {
ssgEntity * root = globals->get_scenery()->get_aircraft_branch(); osg::Group* root = globals->get_scenery()->get_aircraft_branch();
name = strip_path( name ); name = strip_path( name );
ssgSimpleState * node = find_texture_node( root, name ); // OSGFIXME
if( node ) // osg::StateSet* node = find_texture_node( root, name );
node->setTexture( new_texture ); // if( node )
// node->setTexture( new_texture );
} }
void FGODGauge::set2D() { void FGODGauge::set2D() {
glPushAttrib ( GL_ENABLE_BIT | GL_VIEWPORT_BIT | GL_TRANSFORM_BIT | GL_LIGHTING_BIT ) ; // glPushAttrib ( GL_ENABLE_BIT | GL_VIEWPORT_BIT | GL_TRANSFORM_BIT | GL_LIGHTING_BIT ) ;
glDisable(GL_LIGHTING); // glDisable(GL_LIGHTING);
glEnable(GL_COLOR_MATERIAL); // glEnable(GL_COLOR_MATERIAL);
glDisable(GL_CULL_FACE); // glDisable(GL_CULL_FACE);
glDisable(GL_FOG); // glDisable(GL_FOG);
glDisable(GL_DEPTH_TEST); // glDisable(GL_DEPTH_TEST);
glClearColor(0.0, 0.0, 0.0, 0.0); // glClearColor(0.0, 0.0, 0.0, 0.0);
glEnable(GL_TEXTURE_2D); // glEnable(GL_TEXTURE_2D);
glDisable(GL_SMOOTH); // glDisable(GL_SMOOTH);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); // glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glBindTexture(GL_TEXTURE_2D, 0); // glBindTexture(GL_TEXTURE_2D, 0);
glViewport ( 0, 0, textureWH, textureWH ) ; // glViewport ( 0, 0, textureWH, textureWH ) ;
glMatrixMode ( GL_PROJECTION ) ; // glMatrixMode ( GL_PROJECTION ) ;
glPushMatrix () ; // glPushMatrix () ;
glLoadIdentity () ; // glLoadIdentity () ;
gluOrtho2D( -256.0, 256.0, -256.0, 256.0 ); // gluOrtho2D( -256.0, 256.0, -256.0, 256.0 );
glMatrixMode ( GL_MODELVIEW ) ; // glMatrixMode ( GL_MODELVIEW ) ;
glPushMatrix () ; // glPushMatrix () ;
glLoadIdentity () ; // glLoadIdentity () ;
glAlphaFunc(GL_GREATER, 0.0f); // glAlphaFunc(GL_GREATER, 0.0f);
} }
void FGODGauge::set3D() { void FGODGauge::set3D() {
glMatrixMode ( GL_PROJECTION ) ; // glMatrixMode ( GL_PROJECTION ) ;
glPopMatrix () ; // glPopMatrix () ;
glMatrixMode ( GL_MODELVIEW ) ; // glMatrixMode ( GL_MODELVIEW ) ;
glPopMatrix () ; // glPopMatrix () ;
glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ; // glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
glPopAttrib () ; // glPopAttrib () ;
} }

View file

@ -23,12 +23,10 @@
#ifndef _OD_GAUGE_HXX #ifndef _OD_GAUGE_HXX
#define _OD_GAUGE_HXX #define _OD_GAUGE_HXX
#include <osg/Texture2D>
#include <plib/ssg.h>
#include <simgear/structure/subsystem_mgr.hxx> #include <simgear/structure/subsystem_mgr.hxx>
class RenderTexture;
/** /**
* Owner Drawn Gauge helper class. * Owner Drawn Gauge helper class.
*/ */
@ -58,7 +56,7 @@ public:
* Finish rendering and save the buffer to a texture. * Finish rendering and save the buffer to a texture.
* @param texID name of a gl texture * @param texID name of a gl texture
*/ */
void endCapture(GLuint texID); void endCapture(osg::Texture2D*);
/** /**
* Set the size of the destination texture. * Set the size of the destination texture.
* @param viewSize size of the destination texture * @param viewSize size of the destination texture
@ -75,11 +73,10 @@ public:
* @param name texture filename * @param name texture filename
* @param new_texture dynamic texture to replace the old one * @param new_texture dynamic texture to replace the old one
*/ */
void set_texture(const char * name, GLuint new_texture); void set_texture(const char * name, osg::Texture2D* new_texture);
private: private:
int textureWH; int textureWH;
RenderTexture *rt;
bool rtAvailable; bool rtAvailable;
void allocRT(void); void allocRT(void);

View file

@ -21,13 +21,18 @@
// //
// $Id$ // $Id$
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#ifdef HAVE_WINDOWS_H
# include <windows.h>
#endif
#include <GL/gl.h>
#include "render_area_2d.hxx" #include "render_area_2d.hxx"
//#include <iostream>
#include <plib/ssg.h>
//using namespace std;
static const float dummy_normals[][3] = {{0.0f, 0.0f, 0.0f}, static const float dummy_normals[][3] = {{0.0f, 0.0f, 0.0f},
@ -65,6 +70,7 @@ RenderArea2D::RenderArea2D(int logx, int logy, int sizex, int sizey, int posx, i
} }
void RenderArea2D::draw() { void RenderArea2D::draw() {
#if 0
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
/* /*
glColor3f(1, 1, 0); glColor3f(1, 1, 0);
@ -103,6 +109,7 @@ void RenderArea2D::draw() {
} }
glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);
#endif
} }
// Set clipping region in logical units // Set clipping region in logical units
@ -336,25 +343,34 @@ void RenderArea2D::Flush() {
// ----------------------------------------- // -----------------------------------------
void RenderArea2D::doSetColor( const float *rgba ) { void RenderArea2D::doSetColor( const float *rgba ) {
//OSGFIXME
#if 0
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, rgba); glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, rgba);
glColor4fv( rgba ); glColor4fv( rgba );
#endif
} }
void RenderArea2D::doDrawQuad( const sgVec2 *p, const sgVec3 *normals ) { void RenderArea2D::doDrawQuad( const sgVec2 *p, const sgVec3 *normals ) {
//cout << "doDrawQuad: " << *p[0] << ", " << *(p[0]+1) << ", " << *p[1] << ", " << *(p[1]+1) << ", " << *p[2] << ", " << *p([2]+1) << ", " << *p[3] << ", " << *p([3]+1) <<'\n'; //cout << "doDrawQuad: " << *p[0] << ", " << *(p[0]+1) << ", " << *p[1] << ", " << *(p[1]+1) << ", " << *p[2] << ", " << *p([2]+1) << ", " << *p[3] << ", " << *p([3]+1) <<'\n';
//OSGFIXME
#if 0
glBegin(GL_QUADS); glBegin(GL_QUADS);
glNormal3fv( normals[0] ); glVertex2fv( p[0] ); glNormal3fv( normals[0] ); glVertex2fv( p[0] );
glNormal3fv( normals[1] ); glVertex2fv( p[1] ); glNormal3fv( normals[1] ); glVertex2fv( p[1] );
glNormal3fv( normals[2] ); glVertex2fv( p[2] ); glNormal3fv( normals[2] ); glVertex2fv( p[2] );
glNormal3fv( normals[3] ); glVertex2fv( p[3] ); glNormal3fv( normals[3] ); glVertex2fv( p[3] );
glEnd(); glEnd();
#endif
} }
void RenderArea2D::doDrawQuad( const sgVec2 *p, const sgVec3 *normals, const sgVec4 *color ) { void RenderArea2D::doDrawQuad( const sgVec2 *p, const sgVec3 *normals, const sgVec4 *color ) {
//OSGFIXME
#if 0
glBegin(GL_QUADS); glBegin(GL_QUADS);
glColor4fv( color[0] );glNormal3fv( normals[0] ); glVertex2fv( p[0] ); glColor4fv( color[0] );glNormal3fv( normals[0] ); glVertex2fv( p[0] );
glColor4fv( color[1] );glNormal3fv( normals[1] ); glVertex2fv( p[1] ); glColor4fv( color[1] );glNormal3fv( normals[1] ); glVertex2fv( p[1] );
glColor4fv( color[2] );glNormal3fv( normals[2] ); glVertex2fv( p[2] ); glColor4fv( color[2] );glNormal3fv( normals[2] ); glVertex2fv( p[2] );
glColor4fv( color[3] );glNormal3fv( normals[3] ); glVertex2fv( p[3] ); glColor4fv( color[3] );glNormal3fv( normals[3] ); glVertex2fv( p[3] );
glEnd(); glEnd();
#endif
} }

View file

@ -28,9 +28,9 @@
# include <config.h> # include <config.h>
#endif #endif
#include <plib/sg.h>
#include <simgear/compiler.h> #include <simgear/compiler.h>
#include <plib/ssg.h>
#include <vector> #include <vector>
SG_USING_STD(vector); SG_USING_STD(vector);

View file

@ -87,7 +87,10 @@ wxRadarBg::init ()
SGPath tpath(globals->get_fg_root()); SGPath tpath(globals->get_fg_root());
tpath.append("Aircraft/Instruments/Textures/wxecho.rgb"); tpath.append("Aircraft/Instruments/Textures/wxecho.rgb");
// no mipmap or else alpha will mix with pixels on the border of shapes, ruining the effect // no mipmap or else alpha will mix with pixels on the border of shapes, ruining the effect
wxEcho = new ssgTexture( tpath.c_str(), false, false, false);
// OSGFIXME
// wxEcho = new ssgTexture( tpath.c_str(), false, false, false);
wxEcho = new osg::Texture2D;
_Instrument->setFloatValue("trk", 0.0); _Instrument->setFloatValue("trk", 0.0);
_Instrument->setFloatValue("tilt", 0.0); _Instrument->setFloatValue("tilt", 0.0);
@ -110,6 +113,8 @@ wxRadarBg::init ()
void void
wxRadarBg::update (double delta_time_sec) wxRadarBg::update (double delta_time_sec)
{ {
//OSGFIXME
#if 0
if ( ! sim_init_done ) { if ( ! sim_init_done ) {
if ( ! fgGetBool("sim/sceneryloaded", false) ) if ( ! fgGetBool("sim/sceneryloaded", false) )
return; return;
@ -130,7 +135,7 @@ wxRadarBg::update (double delta_time_sec)
// we must locate them and replace their handle by hand // we must locate them and replace their handle by hand
// only do that when the instrument is turned on // only do that when the instrument is turned on
if ( last_switchKnob == "off" ) if ( last_switchKnob == "off" )
odg->set_texture( odgauge_name, resultTexture->getHandle()); odg->set_texture( odgauge_name, resultTexture.get());
last_switchKnob = switchKnob; last_switchKnob = switchKnob;
} }
FGViewer *current__view = globals->get_current_view(); FGViewer *current__view = globals->get_current_view();
@ -189,7 +194,8 @@ wxRadarBg::update (double delta_time_sec)
const float symbolSize = 1.0f / 8.0f ; const float symbolSize = 1.0f / 8.0f ;
// draw the radar echo, we do that in 3 passes, one for each color level // draw the radar echo, we do that in 3 passes, one for each color level
// this is to 'merge' same colors together // this is to 'merge' same colors together
glBindTexture(GL_TEXTURE_2D, wxEcho->getHandle() ); // OSGFIXME
// glBindTexture(GL_TEXTURE_2D, wxEcho->getHandle() );
glColor3f(1.0f, 1.0f, 1.0f); glColor3f(1.0f, 1.0f, 1.0f);
glBegin( GL_QUADS ); glBegin( GL_QUADS );
@ -335,5 +341,6 @@ wxRadarBg::update (double delta_time_sec)
glEnable(GL_ALPHA_TEST); glEnable(GL_ALPHA_TEST);
} }
glPopMatrix(); glPopMatrix();
odg->endCapture( resultTexture->getHandle() ); odg->endCapture( resultTexture.get() );
#endif
} }

View file

@ -23,14 +23,13 @@
#ifndef _INST_WXRADAR_HXX #ifndef _INST_WXRADAR_HXX
#define _INST_WXRADAR_HXX #define _INST_WXRADAR_HXX
#include <plib/ssg.h> #include <osg/ref_ptr>
#include <osg/Texture2D>
#include <simgear/props/props.hxx> #include <simgear/props/props.hxx>
#include <simgear/structure/subsystem_mgr.hxx> #include <simgear/structure/subsystem_mgr.hxx>
#include <simgear/environment/visual_enviro.hxx> #include <simgear/environment/visual_enviro.hxx>
#include <simgear/structure/ssgSharedPtr.hxx>
class ssgTexture;
class FGODGauge; class FGODGauge;
class wxRadarBg : public SGSubsystem { class wxRadarBg : public SGSubsystem {
@ -52,8 +51,8 @@ private:
SGPropertyNode_ptr _serviceable_node; SGPropertyNode_ptr _serviceable_node;
SGPropertyNode_ptr _Instrument; SGPropertyNode_ptr _Instrument;
ssgSharedPtr<ssgTexture> resultTexture; osg::ref_ptr<osg::Texture2D> resultTexture;
ssgSharedPtr<ssgTexture> wxEcho; osg::ref_ptr<osg::Texture2D> wxEcho;
string last_switchKnob; string last_switchKnob;
bool sim_init_done; bool sim_init_done;
FGODGauge *odg; FGODGauge *odg;

View file

@ -78,8 +78,8 @@ fgfs_LDADD = \
$(top_builddir)/src/Autopilot/libAutopilot.a \ $(top_builddir)/src/Autopilot/libAutopilot.a \
$(top_builddir)/src/Input/libInput.a \ $(top_builddir)/src/Input/libInput.a \
$(top_builddir)/src/Instrumentation/KLN89/libKLN89.a \ $(top_builddir)/src/Instrumentation/KLN89/libKLN89.a \
$(top_builddir)/src/Instrumentation/HUD/libHUD.a \
$(top_builddir)/src/Instrumentation/libInstrumentation.a \ $(top_builddir)/src/Instrumentation/libInstrumentation.a \
$(top_builddir)/src/Instrumentation/HUD/libHUD.a \
$(top_builddir)/src/Model/libModel.a \ $(top_builddir)/src/Model/libModel.a \
$(top_builddir)/src/Network/libNetwork.a \ $(top_builddir)/src/Network/libNetwork.a \
$(top_builddir)/src/Navaids/libNavaids.a \ $(top_builddir)/src/Navaids/libNavaids.a \
@ -97,13 +97,17 @@ fgfs_LDADD = \
-lsgtiming -lsgio -lsgscreen -lsgmath -lsgbucket -lsgprops -lsgdebug \ -lsgtiming -lsgio -lsgscreen -lsgmath -lsgbucket -lsgprops -lsgdebug \
-lsgmagvar -lsgmisc -lsgnasal -lsgxml -lsgsound -lsgserial \ -lsgmagvar -lsgmisc -lsgnasal -lsgxml -lsgsound -lsgserial \
-lsgstructure -lsgenvironment \ -lsgstructure -lsgenvironment \
-lplibpuaux -lplibpu -lplibfnt -lplibjs -lplibnet \
-lplibsg -lplibul \
-losgUtil -losgDB -losgSim -losg -lOpenThreads \
$(THREAD_LIBS) \ $(THREAD_LIBS) \
-lplibpuaux -lplibpu -lplibfnt -lplibjs -lplibnet -lplibssgaux -lplibssg -lplibsg -lplibul \
$(network_LIBS) \ $(network_LIBS) \
-lz \ -lz \
$(opengl_LIBS) \ $(opengl_LIBS) \
$(openal_LIBS) $(openal_LIBS)
# -lplibssgaux -lplibssg
metar_SOURCES = metar_main.cxx metar_SOURCES = metar_main.cxx
metar_LDADD = \ metar_LDADD = \

View file

@ -614,13 +614,12 @@ static void fgMainLoop( void ) {
globals->get_soundmgr()->set_volume(init_volume); globals->get_soundmgr()->set_volume(init_volume);
} }
if (fgGetBool("/sim/rendering/specular-highlight")) { // OSGFIXME: with osg>1.2 remove this, osg::LightModel does the trick...
glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR); // if (fgGetBool("/sim/rendering/specular-highlight")) {
// glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); // glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
} else { // } else {
glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SINGLE_COLOR); // glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SINGLE_COLOR);
// glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE); // }
}
fgRequestRedraw(); fgRequestRedraw();
@ -665,10 +664,6 @@ static void fgIdleFunction ( void ) {
general.set_glDepthBits( tmp ); general.set_glDepthBits( tmp );
SG_LOG ( SG_GENERAL, SG_INFO, "Depth buffer bits = " << tmp ); SG_LOG ( SG_GENERAL, SG_INFO, "Depth buffer bits = " << tmp );
// Initialize ssg (from plib). Needs to come before we do any
// other ssg stuff, but after opengl has been initialized.
ssgInit();
// Initialize the user interface (we need to do this before // Initialize the user interface (we need to do this before
// passing off control to the OS main loop and before // passing off control to the OS main loop and before
// fgInitGeneral to get our fonts !!! // fgInitGeneral to get our fonts !!!
@ -682,21 +677,21 @@ static void fgIdleFunction ( void ) {
fgReadAircraft(); fgReadAircraft();
// get the address of our OpenGL extensions // get the address of our OpenGL extensions
if (SGIsOpenGLExtensionSupported("GL_EXT_point_parameters") ) { // if (SGIsOpenGLExtensionSupported("GL_EXT_point_parameters") ) {
glPointParameterIsSupported = true; // glPointParameterIsSupported = true;
glPointParameterfPtr = (glPointParameterfProc) // glPointParameterfPtr = (glPointParameterfProc)
SGLookupFunction("glPointParameterfEXT"); // SGLookupFunction("glPointParameterfEXT");
glPointParameterfvPtr = (glPointParameterfvProc) // glPointParameterfvPtr = (glPointParameterfvProc)
SGLookupFunction("glPointParameterfvEXT"); // SGLookupFunction("glPointParameterfvEXT");
} else if ( SGIsOpenGLExtensionSupported("GL_ARB_point_parameters") ) { // } else if ( SGIsOpenGLExtensionSupported("GL_ARB_point_parameters") ) {
glPointParameterIsSupported = true; // glPointParameterIsSupported = true;
glPointParameterfPtr = (glPointParameterfProc) // glPointParameterfPtr = (glPointParameterfProc)
SGLookupFunction("glPointParameterfARB"); // SGLookupFunction("glPointParameterfARB");
glPointParameterfvPtr = (glPointParameterfvProc) // glPointParameterfvPtr = (glPointParameterfvProc)
SGLookupFunction("glPointParameterfvARB"); // SGLookupFunction("glPointParameterfvARB");
} else { // } else {
glPointParameterIsSupported = false; // glPointParameterIsSupported = false;
} // }
fgSplashProgress("reading airport & navigation data"); fgSplashProgress("reading airport & navigation data");
@ -838,7 +833,6 @@ static void fgIdleFunction ( void ) {
// lighting->addKid( airport ); // lighting->addKid( airport );
// build our custom render states // build our custom render states
globals->get_renderer()->build_states();
fgSplashProgress("initializing subsystems"); fgSplashProgress("initializing subsystems");
@ -993,7 +987,8 @@ bool fgMainInit( int argc, char **argv ) {
exit(-1); exit(-1);
} }
sgUseDisplayList = fgGetBool( "/sim/rendering/use-display-list", true ); //OSGFIXME
// sgUseDisplayList = fgGetBool( "/sim/rendering/use-display-list", true );
// Load the configuration parameters. (Command line options // Load the configuration parameters. (Command line options
// override config file options. Config file options override // override config file options. Config file options override

File diff suppressed because it is too large Load diff

View file

@ -25,7 +25,6 @@ public:
void init(); void init();
void build_states();
static void resize(int width, int height ); static void resize(int width, int height );
// calling update( refresh_camera_settings = false ) will not // calling update( refresh_camera_settings = false ) will not

View file

@ -28,7 +28,6 @@
#include <string.h> // strcmp #include <string.h> // strcmp
#include <plib/sg.h> #include <plib/sg.h>
#include <plib/ssg.h>
#include <simgear/compiler.h> #include <simgear/compiler.h>

View file

@ -9,15 +9,12 @@
#include <string.h> // for strcmp() #include <string.h> // for strcmp()
#include <plib/sg.h>
#include <plib/ssg.h>
#include <simgear/compiler.h> #include <simgear/compiler.h>
#include <simgear/debug/logstream.hxx> #include <simgear/debug/logstream.hxx>
#include <simgear/structure/exception.hxx> #include <simgear/structure/exception.hxx>
#include <simgear/misc/sg_path.hxx> #include <simgear/misc/sg_path.hxx>
#include <simgear/scene/model/placement.hxx> #include <simgear/scene/model/placement.hxx>
#include <simgear/scene/model/shadowvolume.hxx> #include <simgear/scene/util/SGNodeMasks.hxx>
#include <Main/globals.hxx> #include <Main/globals.hxx>
#include <Main/fg_props.hxx> #include <Main/fg_props.hxx>
@ -30,38 +27,6 @@
#include "acmodel.hxx" #include "acmodel.hxx"
class fgLoaderOptions : ssgLoaderOptions {
public:
virtual void makeTexturePath ( char* path, const char *fname ) const ;
string livery_path;
};
void fgLoaderOptions::makeTexturePath ( char *path, const char *fname ) const
{
/* Remove all leading path information. */
const char* seps = "\\/" ;
const char* fn = & fname [ strlen ( fname ) - 1 ] ;
for ( ; fn != fname && strchr(seps,*fn) == NULL ; fn-- )
/* Search back for a seperator */ ;
if ( strchr(seps,*fn) != NULL )
fn++ ;
fname = fn ;
// if we have a livery path and the texture is found there then we use that
// path in priority, if the texture was not found or we add no additional
// livery path then we use the current model path or model/texture-path
if( livery_path.size() ) {
make_path( path, livery_path.c_str(), fname );
if( ulFileExists( path ) )
return;
}
make_path ( path, texture_dir, fname ) ;
}
static fgLoaderOptions _fgLoaderOptions;
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// Implementation of FGAircraftModel // Implementation of FGAircraftModel
@ -69,8 +34,8 @@ static fgLoaderOptions _fgLoaderOptions;
FGAircraftModel::FGAircraftModel () FGAircraftModel::FGAircraftModel ()
: _aircraft(0), : _aircraft(0),
_selector(new ssgSelector), _selector(new osg::Switch),
_scene(new ssgRoot), _scene(new osg::Group),
_nearplane(0.10f), _nearplane(0.10f),
_farplane(1000.0f) _farplane(1000.0f)
{ {
@ -84,14 +49,13 @@ FGAircraftModel::~FGAircraftModel ()
delete _aircraft; delete _aircraft;
// SSG will delete it // SSG will delete it
globals->get_scenery()->get_aircraft_branch()->removeKid(_selector); globals->get_scenery()->get_aircraft_branch()->removeChild(_selector.get());
} }
void void
FGAircraftModel::init () FGAircraftModel::init ()
{ {
ssgLoaderOptions *currLoaderOptions = ssgGetCurrentOptions(); SGPath liveryPath;
ssgSetCurrentOptions( (ssgLoaderOptions*)&_fgLoaderOptions );
_aircraft = new SGModelPlacement; _aircraft = new SGModelPlacement;
string path = fgGetString("/sim/model/path", "Models/Geometry/glider.ac"); string path = fgGetString("/sim/model/path", "Models/Geometry/glider.ac");
string texture_path = fgGetString("/sim/model/texture-path"); string texture_path = fgGetString("/sim/model/texture-path");
@ -101,41 +65,44 @@ FGAircraftModel::init ()
temp_path = globals->get_fg_root(); temp_path = globals->get_fg_root();
temp_path.append( SGPath( path ).dir() ); temp_path.append( SGPath( path ).dir() );
temp_path.append( texture_path ); temp_path.append( texture_path );
_fgLoaderOptions.livery_path = temp_path.str(); liveryPath = temp_path;
} else } else
_fgLoaderOptions.livery_path = texture_path; liveryPath = texture_path;
} }
try { try {
ssgBranch *model = fgLoad3DModelPanel( globals->get_fg_root(), osg::Node *model = fgLoad3DModelPanel( globals->get_fg_root(),
path, path,
globals->get_props(), globals->get_props(),
globals->get_sim_time_sec() ); globals->get_sim_time_sec(),
liveryPath);
_aircraft->init( model ); _aircraft->init( model );
} catch (const sg_exception &ex) { } catch (const sg_exception &ex) {
SG_LOG(SG_GENERAL, SG_ALERT, "Failed to load aircraft from " << path); SG_LOG(SG_GENERAL, SG_ALERT, "Failed to load aircraft from " << path);
SG_LOG(SG_GENERAL, SG_ALERT, "(Falling back to glider.ac.)"); SG_LOG(SG_GENERAL, SG_ALERT, "(Falling back to glider.ac.)");
ssgBranch *model = fgLoad3DModelPanel( globals->get_fg_root(), osg::Node *model = fgLoad3DModelPanel( globals->get_fg_root(),
"Models/Geometry/glider.ac", "Models/Geometry/glider.ac",
globals->get_props(), globals->get_props(),
globals->get_sim_time_sec() ); globals->get_sim_time_sec(),
liveryPath);
_aircraft->init( model ); _aircraft->init( model );
} }
_scene->addKid(_aircraft->getSceneGraph()); _scene->addChild(_aircraft->getSceneGraph());
_selector->addKid(_aircraft->getSceneGraph()); _selector->addChild(_aircraft->getSceneGraph());
globals->get_scenery()->get_aircraft_branch()->addKid(_selector); // Do not do altitude computations with that model
_selector->setNodeMask(~SG_NODEMASK_TERRAIN_BIT);
globals->get_scenery()->get_aircraft_branch()->addChild(_selector.get());
// Register that one at the scenery manager // Register that one at the scenery manager
globals->get_scenery()->register_placement_transform(_aircraft->getTransform()); globals->get_scenery()->register_placement_transform(_aircraft->getTransform());
ssgSetCurrentOptions( currLoaderOptions );
} }
void void
FGAircraftModel::bind () FGAircraftModel::bind ()
{ {
// No-op // No-op
} }
void void
FGAircraftModel::unbind () FGAircraftModel::unbind ()
{ {
// No-op // No-op
@ -162,27 +129,5 @@ FGAircraftModel::update (double dt)
_aircraft->update(); _aircraft->update();
} }
void
FGAircraftModel::draw ()
{
// OK, now adjust the clip planes and draw
// FIXME: view number shouldn't be
// hard-coded.
bool is_internal = globals->get_current_view()->getInternal();
if (_aircraft->getVisible() && is_internal) {
glClearDepth(1);
glClear(GL_DEPTH_BUFFER_BIT);
FGRenderer::setNearFar(_nearplane, _farplane);
ssgCullAndDraw(_scene);
_selector->select(0);
} else {
_selector->select(1);
// in external view the shadows are drawn before the transparent parts of the ac
_scene->setTravCallback( SSG_CALLBACK_POSTTRAV, SGShadowVolume::ACpostTravCB);
ssgCullAndDraw(_scene);
_scene->setTravCallback( SSG_CALLBACK_POSTTRAV, 0);
}
}
// end of model.cxx // end of model.cxx

View file

@ -1,4 +1,4 @@
// model.hxx - manage a 3D aircraft model. #// model.hxx - manage a 3D aircraft model.
// Written by David Megginson, started 2002. // Written by David Megginson, started 2002.
// //
// This file is in the Public Domain, and comes with no warranty. // This file is in the Public Domain, and comes with no warranty.
@ -16,13 +16,14 @@
SG_USING_STD(string); SG_USING_STD(string);
SG_USING_STD(vector); SG_USING_STD(vector);
#include <osg/ref_ptr>
#include <osg/Group>
#include <osg/Switch>
#include <simgear/structure/subsystem_mgr.hxx> // for SGSubsystem #include <simgear/structure/subsystem_mgr.hxx> // for SGSubsystem
#include <simgear/structure/ssgSharedPtr.hxx>
// Don't pull in the headers, since we don't need them here. // Don't pull in the headers, since we don't need them here.
class ssgRoot;
class ssgSelector;
class SGModelPlacement; class SGModelPlacement;
@ -37,15 +38,14 @@ public:
virtual void bind (); virtual void bind ();
virtual void unbind (); virtual void unbind ();
virtual void update (double dt); virtual void update (double dt);
virtual void draw ();
virtual SGModelPlacement * get3DModel() { return _aircraft; } virtual SGModelPlacement * get3DModel() { return _aircraft; }
void select( bool s ) { _selector->select( s ? 0xffffffff : 0 ); } void select( bool s ) { _selector->setValue( 0, s ); }
private: private:
SGModelPlacement * _aircraft; SGModelPlacement * _aircraft;
ssgSharedPtr<ssgSelector> _selector; osg::ref_ptr<osg::Switch> _selector;
ssgSharedPtr<ssgRoot> _scene; osg::ref_ptr<osg::Group> _scene;
float _nearplane; float _nearplane;
float _farplane; float _farplane;

View file

@ -9,10 +9,11 @@
#include <simgear/compiler.h> #include <simgear/compiler.h>
#include <plib/ssg.h> #include <osg/Geode>
#include <simgear/props/props.hxx> #include <simgear/props/props.hxx>
#include <simgear/scene/model/model.hxx> #include <simgear/scene/model/model.hxx>
#include <simgear/scene/util/SGNodeMasks.hxx>
#include "panelnode.hxx" #include "panelnode.hxx"
@ -21,21 +22,27 @@
SG_USING_STD(vector); SG_USING_STD(vector);
static static
ssgEntity *load_panel(SGPropertyNode *n) osg::Node* load_panel(SGPropertyNode *n)
{ {
return new FGPanelNode(n); osg::Geode* geode = new osg::Geode;
geode->addDrawable(new FGPanelNode(n));
return geode;
} }
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// Global functions. // Global functions.
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
ssgBranch * osg::Node *
fgLoad3DModelPanel( const string &fg_root, const string &path, fgLoad3DModelPanel( const string &fg_root, const string &path,
SGPropertyNode *prop_root, SGPropertyNode *prop_root,
double sim_time_sec ) double sim_time_sec, const SGPath& livery )
{ {
return sgLoad3DModel( fg_root, path, prop_root, sim_time_sec, load_panel ); osg::Node* node = sgLoad3DModel( fg_root, path, prop_root, sim_time_sec,
load_panel, 0, livery );
node->setNodeMask(~SG_NODEMASK_TERRAIN_BIT);
return node;
} }

View file

@ -19,11 +19,6 @@ SG_USING_STD(vector);
// Don't pull in the headers, since we don't need them here. // Don't pull in the headers, since we don't need them here.
class ssgBranch;
class ssgEntity;
class ssgRangeSelector;
class ssgSelector;
class ssgTransform;
class SGInterpTable; class SGInterpTable;
class FGCondition; class FGCondition;
@ -51,9 +46,9 @@ class FGLocation;
* Subsystems should not normally invoke this function directly; * Subsystems should not normally invoke this function directly;
* instead, they should use the SGModelLoader declared in loader.hxx. * instead, they should use the SGModelLoader declared in loader.hxx.
*/ */
ssgBranch *fgLoad3DModelPanel( const string& fg_root, const string &path, osg::Node *fgLoad3DModelPanel( const string& fg_root, const string &path,
SGPropertyNode *prop_root, SGPropertyNode *prop_root,
double sim_time_sec ); double sim_time_sec, const SGPath& livery );
#endif // __MODEL_HXX #endif // __MODEL_HXX

View file

@ -11,11 +11,8 @@
#include <vector> #include <vector>
#include <plib/ssg.h>
#include <simgear/scene/model/placement.hxx> #include <simgear/scene/model/placement.hxx>
#include <simgear/scene/model/modellib.hxx> #include <simgear/scene/model/modellib.hxx>
#include <simgear/scene/model/shadowvolume.hxx>
#include <simgear/structure/exception.hxx> #include <simgear/structure/exception.hxx>
#include <Main/fg_props.hxx> #include <Main/fg_props.hxx>
@ -26,7 +23,8 @@
SG_USING_STD(vector); SG_USING_STD(vector);
extern SGShadowVolume *shadows; // OSGFIXME
// extern SGShadowVolume *shadows;
FGModelMgr::FGModelMgr () FGModelMgr::FGModelMgr ()
@ -43,7 +41,7 @@ FGModelMgr::~FGModelMgr ()
for (unsigned int i = 0; i < _instances.size(); i++) { for (unsigned int i = 0; i < _instances.size(); i++) {
globals->get_scenery()->get_scene_graph() globals->get_scenery()->get_scene_graph()
->removeKid(_instances[i]->model->getSceneGraph()); ->removeChild(_instances[i]->model->getSceneGraph());
delete _instances[i]; delete _instances[i];
} }
} }
@ -72,7 +70,7 @@ FGModelMgr::add_model (SGPropertyNode * node)
instance->model = model; instance->model = model;
instance->node = node; instance->node = node;
SGModelLib *model_lib = globals->get_model_lib(); SGModelLib *model_lib = globals->get_model_lib();
ssgBranch *object = (ssgBranch *)model_lib->load_model( osg::Node *object = model_lib->load_model(
globals->get_fg_root(), globals->get_fg_root(),
node->getStringValue("path", node->getStringValue("path",
"Models/Geometry/glider.ac"), "Models/Geometry/glider.ac"),
@ -121,7 +119,7 @@ FGModelMgr::add_model (SGPropertyNode * node)
model->setHeadingDeg(node->getDoubleValue("heading-deg")); model->setHeadingDeg(node->getDoubleValue("heading-deg"));
// Add this model to the global scene graph // Add this model to the global scene graph
globals->get_scenery()->get_scene_graph()->addKid(model->getSceneGraph()); globals->get_scenery()->get_scene_graph()->addChild(model->getSceneGraph());
// Register that one at the scenery manager // Register that one at the scenery manager
globals->get_scenery()->register_placement_transform(model->getTransform()); globals->get_scenery()->register_placement_transform(model->getTransform());
@ -166,11 +164,12 @@ FGModelMgr::update (double dt)
instance->model->update(); instance->model->update();
if (shadows && !instance->shadow) { // OSGFIXME
ssgBranch *branch = (ssgBranch *)instance->model->getSceneGraph(); // if (shadows && !instance->shadow) {
shadows->addOccluder(branch, SGShadowVolume::occluderTypeTileObject); // osg::Node *branch = instance->model->getSceneGraph();
instance->shadow = true; // shadows->addOccluder(branch, SGShadowVolume::occluderTypeTileObject);
} // instance->shadow = true;
// }
} }
} }
@ -193,14 +192,6 @@ FGModelMgr::remove_instance (Instance * instance)
} }
} }
void
FGModelMgr::draw ()
{
// ssgSetNearFar(_nearplane, _farplane);
// ssgCullAndDraw(_scene);
}
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// Implementation of FGModelMgr::Instance // Implementation of FGModelMgr::Instance
@ -262,10 +253,11 @@ FGModelMgr::Listener::childRemoved(SGPropertyNode * parent, SGPropertyNode * chi
continue; continue;
_mgr->_instances.erase(it); _mgr->_instances.erase(it);
ssgBranch *branch = (ssgBranch *)instance->model->getSceneGraph(); osg::Node *branch = instance->model->getSceneGraph();
if (shadows && instance->shadow) // OSGFIXME
shadows->deleteOccluder(branch); // if (shadows && instance->shadow)
globals->get_scenery()->get_scene_graph()->removeKid(branch); // shadows->deleteOccluder(branch);
globals->get_scenery()->get_scene_graph()->removeChild(branch);
delete instance; delete instance;
break; break;

View file

@ -87,9 +87,6 @@ public:
*/ */
virtual void remove_instance (Instance * instance); virtual void remove_instance (Instance * instance);
virtual void draw ();
private: private:
/** /**

View file

@ -14,8 +14,9 @@
SG_USING_STD(vector); SG_USING_STD(vector);
// Static (!) handling for all 3D panels in the program. Very // Static (!) handling for all 3D panels in the program.
// clumsy. Replace with per-aircraft handling. // OSGFIXME: Put the panel as different elements in the scenegraph.
// Then just pick in that scenegraph.
vector<FGPanelNode*> all_3d_panels; vector<FGPanelNode*> all_3d_panels;
bool fgHandle3DPanelMouseEvent( int button, int updown, int x, int y ) bool fgHandle3DPanelMouseEvent( int button, int updown, int x, int y )
{ {
@ -45,17 +46,11 @@ FGPanelNode::FGPanelNode(SGPropertyNode* props)
// Never mind. We *have* to call init to make sure the static // Never mind. We *have* to call init to make sure the static
// state is initialized (it's not, if there aren't any 2D // state is initialized (it's not, if there aren't any 2D
// panels). This is a memory leak and should be fixed!` // panels). This is a memory leak and should be fixed!`
// FIXME
_panel->init(); _panel->init();
_panel->setDepthTest( props->getBoolValue("depth-test") ); _panel->setDepthTest( props->getBoolValue("depth-test") );
// Initialize the matrices to the identity. PLib prints warnings
// when trying to invert singular matrices (e.g. when not using a
// 3D panel).
for(i=0; i<4; i++)
for(int j=0; j<4; j++)
_lastModelview[4*i+j] = _lastProjection[4*i+j] = i==j ? 1 : 0;
// Read out the pixel-space info // Read out the pixel-space info
_xmax = _panel->getWidth(); _xmax = _panel->getWidth();
_ymax = _panel->getHeight(); _ymax = _panel->getHeight();
@ -80,44 +75,38 @@ FGPanelNode::FGPanelNode(SGPropertyNode* props)
// "a", "b", and "c" as our corners and "m" as the matrix. The // "a", "b", and "c" as our corners and "m" as the matrix. The
// vector u goes from a to b, v from a to c, and w is a // vector u goes from a to b, v from a to c, and w is a
// perpendicular cross product. // perpendicular cross product.
float *a = _bottomLeft, *b = _bottomRight, *c = _topLeft, *m = _xform; osg::Vec3 a = _bottomLeft;
float u[3], v[3], w[3]; osg::Vec3 b = _bottomRight;
for(i=0; i<3; i++) u[i] = b[i] - a[i]; // U = B - A osg::Vec3 c = _topLeft;
for(i=0; i<3; i++) v[i] = c[i] - a[i]; // V = C - A osg::Vec3 u = b - a;
osg::Vec3 v = c - a;
w[0] = u[1]*v[2] - v[1]*u[2]; // W = U x V osg::Vec3 w = u^v;
w[1] = u[2]*v[0] - v[2]*u[0];
w[2] = u[0]*v[1] - v[0]*u[1];
osg::Matrix& m = _xform;
// Now generate a trivial basis transformation matrix. If we want // Now generate a trivial basis transformation matrix. If we want
// to map the three unit vectors to three arbitrary vectors U, V, // to map the three unit vectors to three arbitrary vectors U, V,
// and W, then those just become the columns of the 3x3 matrix. // and W, then those just become the columns of the 3x3 matrix.
m[0] = u[0]; m[4] = v[0]; m[8] = w[0]; m[12] = a[0]; // |Ux Vx Wx| m(0,0) = u[0]; m(1,0) = v[0]; m(2,0) = w[0]; m(3,0) = a[0];// |Ux Vx Wx|
m[1] = u[1]; m[5] = v[1]; m[9] = w[1]; m[13] = a[1]; // m = |Uy Vy Wy| m(0,1) = u[1]; m(1,1) = v[1]; m(2,1) = w[1]; m(3,1) = a[1];//m = |Uy Vy Wy|
m[2] = u[2]; m[6] = v[2]; m[10] = w[2]; m[14] = a[2]; // |Uz Vz Wz| m(0,2) = u[2]; m(1,2) = v[2]; m(2,2) = w[2]; m(3,2) = a[2];// |Uz Vz Wz|
m[3] = 0; m[7] = 0; m[11] = 0; m[15] = 1; m(0,3) = 0; m(1,3) = 0; m(2,3) = 0; m(3,3) = 1;
// The above matrix maps the unit (!) square to the panel // The above matrix maps the unit (!) square to the panel
// rectangle. Postmultiply scaling factors that match the // rectangle. Postmultiply scaling factors that match the
// pixel-space size of the panel. // pixel-space size of the panel.
for(i=0; i<4; i++) { for(i=0; i<4; ++i) {
m[0+i] *= 1.0/_xmax; m(0,i) *= 1.0/_xmax;
m[4+i] *= 1.0/_ymax; m(1,i) *= 1.0/_ymax;
} }
// Now plib initialization. The bounding sphere is defined nicely dirtyBound();
// by our corner points:
float cx = (b[0]+c[0])/2;
float cy = (b[1]+c[1])/2;
float cz = (b[2]+c[2])/2;
float r = sqrt((cx-a[0])*(cx-a[0]) +
(cy-a[1])*(cy-a[1]) +
(cz-a[2])*(cz-a[2]));
bsphere.setCenter(cx, cy, cz);
bsphere.setRadius(r);
// All done. Add us to the list // All done. Add us to the list
all_3d_panels.push_back(this); all_3d_panels.push_back(this);
setUseDisplayList(false);
getOrCreateStateSet()->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
getOrCreateStateSet()->setMode(GL_BLEND, osg::StateAttribute::ON);
} }
FGPanelNode::~FGPanelNode() FGPanelNode::~FGPanelNode()
@ -125,29 +114,35 @@ FGPanelNode::~FGPanelNode()
delete _panel; delete _panel;
} }
void FGPanelNode::draw() void
FGPanelNode::drawImplementation(osg::State& state) const
{ {
// What's the difference? osg::ref_ptr<osg::RefMatrix> mv = new osg::RefMatrix;
draw_geometry(); mv->set(_xform*state.getModelViewMatrix());
state.applyModelViewMatrix(mv.get());
// Grab the matrix state, so that we can get back from screen
// coordinates to panel coordinates when the user clicks the
// mouse.
// OSGFIXME: we don't need that when we can really pick
const_cast<osg::Matrix&>(_lastModelview) = state.getModelViewMatrix();
const_cast<osg::Matrix&>(_lastProjection) = state.getProjectionMatrix();
state.getCurrentViewport()->getViewport(const_cast<int&>(_lastViewport[0]),
const_cast<int&>(_lastViewport[1]),
const_cast<int&>(_lastViewport[2]),
const_cast<int&>(_lastViewport[3]));
_panel->draw(state);
} }
void FGPanelNode::draw_geometry() osg::BoundingBox
FGPanelNode::computeBound() const
{ {
glMatrixMode(GL_MODELVIEW); osg::BoundingBox bb;
glPushMatrix(); bb.expandBy(_bottomLeft);
glMultMatrixf(_xform); bb.expandBy(_bottomRight);
bb.expandBy(_topLeft);
// Grab the matrix state, so that we can get back from screen return bb;
// coordinates to panel coordinates when the user clicks the
// mouse.
glGetFloatv(GL_MODELVIEW_MATRIX, _lastModelview);
glGetFloatv(GL_PROJECTION_MATRIX, _lastProjection);
glGetIntegerv(GL_VIEWPORT, _lastViewport);
_panel->draw();
glPopMatrix();
} }
bool FGPanelNode::doMouseAction(int button, int updown, int x, int y) bool FGPanelNode::doMouseAction(int button, int updown, int x, int y)
@ -162,7 +157,7 @@ bool FGPanelNode::doMouseAction(int button, int updown, int x, int y)
// Make two vectors in post-projection coordinates at the given // Make two vectors in post-projection coordinates at the given
// screen, one in the near field and one in the far field. // screen, one in the near field and one in the far field.
sgVec3 a, b; osg::Vec3 a, b;
a[0] = b[0] = vx; a[0] = b[0] = vx;
a[1] = b[1] = vy; a[1] = b[1] = vy;
a[2] = 0.75; // "Near" Z value a[2] = 0.75; // "Near" Z value
@ -170,12 +165,11 @@ bool FGPanelNode::doMouseAction(int button, int updown, int x, int y)
// Run both vectors "backwards" through the OpenGL matrix // Run both vectors "backwards" through the OpenGL matrix
// transformation. Remember to w-normalize the vectors! // transformation. Remember to w-normalize the vectors!
sgMat4 m; osg::Matrix m = _lastModelview*_lastProjection;
sgMultMat4(m, *(sgMat4*)_lastProjection, *(sgMat4*)_lastModelview); m = osg::Matrix::inverse(m);
sgInvertMat4(m);
sgFullXformPnt3(a, m); a = m.preMult(a);
sgFullXformPnt3(b, m); b = m.preMult(b);
// And find their intersection on the z=0 plane. The resulting X // And find their intersection on the z=0 plane. The resulting X
// and Y coordinates are the hit location in panel coordinates. // and Y coordinates are the hit location in panel coordinates.
@ -187,9 +181,3 @@ bool FGPanelNode::doMouseAction(int button, int updown, int x, int y)
return _panel->doLocalMouseAction(button, updown, panelX, panelY); return _panel->doLocalMouseAction(button, updown, panelX, panelY);
} }
void FGPanelNode::die()
{
SG_LOG(SG_ALL,SG_ALERT,"Unimplemented function called on FGPanelNode");
exit(1);
}

View file

@ -1,8 +1,9 @@
#ifndef FG_PANELNODE_HXX #ifndef FG_PANELNODE_HXX
#define FG_PANELNODE_HXX #define FG_PANELNODE_HXX
#include <osg/Vec3>
#include <plib/ssg.h> #include <osg/Matrix>
#include <osg/Drawable>
class FGPanel; class FGPanel;
class SGPropertyNode; class SGPropertyNode;
@ -18,52 +19,28 @@ class SGPropertyNode;
bool fgHandle3DPanelMouseEvent(int button, int updown, int x, int y); bool fgHandle3DPanelMouseEvent(int button, int updown, int x, int y);
void fgUpdate3DPanels(); void fgUpdate3DPanels();
class FGPanelNode : public ssgLeaf class FGPanelNode : public osg::Drawable // OSGFIXME
{ {
protected:
virtual void draw_geometry();
public: public:
FGPanelNode(SGPropertyNode* props); FGPanelNode(SGPropertyNode* props);
virtual ~FGPanelNode(); virtual ~FGPanelNode();
virtual void draw(); // OSGFIXME
virtual osg::Object* cloneType() const { return 0; }
virtual osg::Object* clone(const osg::CopyOp& copyop) const { return 0; }
bool doMouseAction(int button, int updown, int x, int y); bool doMouseAction(int button, int updown, int x, int y);
FGPanel* getPanel() { return _panel; } FGPanel* getPanel() { return _panel; }
virtual void recalcBSphere() { bsphere_is_invalid = 0; } virtual void drawImplementation(osg::State& state) const;
virtual osg::BoundingBox computeBound() const;
//
// A bunch of Plib functions that aren't implemented. I don't
// even know what many of them do, but they're pure virtual and
// require implementation.
//
virtual int getNumTriangles() { return 0; }
virtual void getTriangle(int n, short* v1, short* v2, short* v3) { die(); }
virtual int getNumLines() { die(); return 0; }
virtual void getLine(int n, short* v1, short* v2) { die(); }
virtual void drawHighlight(sgVec4 colour) { die(); }
virtual void drawHighlight(sgVec4 colour, int i) { die(); }
virtual float* getVertex(int i) { die(); return 0; }
virtual float* getNormal(int i) { die(); return 0; }
virtual float* getColour(int i) { die(); return 0; }
virtual float* getTexCoord(int i) { die(); return 0; }
virtual void pick(int baseName) { die(); }
virtual void isect_triangles(sgSphere* s, sgMat4 m, int testNeeded) { die(); }
virtual void hot_triangles(sgVec3 s, sgMat4 m, int testNeeded) { die(); }
virtual void los_triangles(sgVec3 s, sgMat4 m, int testNeeded) { die(); }
virtual void transform(const sgMat4 m) { die(); }
private: private:
// Handler for all the unimplemented methods above
void die();
FGPanel* _panel; FGPanel* _panel;
// Panel corner coordinates // Panel corner coordinates
float _bottomLeft[3], _topLeft[3], _bottomRight[3]; osg::Vec3 _bottomLeft, _topLeft, _bottomRight;
// The input range expected in the panel definition. These x/y // The input range expected in the panel definition. These x/y
// coordinates will map to the right/top sides. // coordinates will map to the right/top sides.
@ -71,14 +48,14 @@ private:
// The matrix that results, which transforms 2D x/y panel // The matrix that results, which transforms 2D x/y panel
// coordinates into 3D coordinates of the panel quadrilateral. // coordinates into 3D coordinates of the panel quadrilateral.
GLfloat _xform[16]; osg::Matrix _xform;
// The matrix transformation state that was active the last time // The matrix transformation state that was active the last time
// we were rendered. Used by the mouse code to compute // we were rendered. Used by the mouse code to compute
// intersections. // intersections.
GLfloat _lastModelview[16]; osg::Matrix _lastModelview;
GLfloat _lastProjection[16]; osg::Matrix _lastProjection;
GLint _lastViewport[4]; int _lastViewport[4];
}; };

View file

@ -23,30 +23,14 @@
# include <config.h> # include <config.h>
#endif #endif
#ifdef _MSC_VER
# define _USE_MATH_DEFINES
#endif
#include <math.h> #include <math.h>
#include <algorithm> #include <algorithm>
#include <simgear/compiler.h> #include <simgear/compiler.h>
//#include <plib/sg.h>
//#include <plib/ul.h>
//#include <Environment/environment_mgr.hxx>
//#include <Environment/environment.hxx>
//#include <simgear/misc/sg_path.hxx>
//#include <simgear/props/props.hxx>
//#include <simgear/structure/subsystem_mgr.hxx>
#include <simgear/debug/logstream.hxx> #include <simgear/debug/logstream.hxx>
#include <simgear/misc/sgstream.hxx> #include <simgear/misc/sgstream.hxx>
#include <simgear/route/waypoint.hxx> #include <simgear/route/waypoint.hxx>
//#include <Main/globals.hxx>
//#include <Main/fg_props.hxx>
//#include <Airports/runways.hxx>
//#include STL_STRING
#include "awynet.hxx" #include "awynet.hxx"

View file

@ -2,7 +2,6 @@ noinst_LIBRARIES = libScenery.a
libScenery_a_SOURCES = \ libScenery_a_SOURCES = \
FGTileLoader.cxx FGTileLoader.hxx \ FGTileLoader.cxx FGTileLoader.hxx \
hitlist.cxx hitlist.hxx \
newcache.cxx newcache.hxx \ newcache.cxx newcache.hxx \
scenery.cxx scenery.hxx \ scenery.cxx scenery.hxx \
tileentry.cxx tileentry.hxx \ tileentry.cxx tileentry.hxx \

View file

@ -10,7 +10,6 @@
#include <math.h> #include <math.h>
#include <plib/sg.h> #include <plib/sg.h>
#include <plib/ssg.h>
#include <simgear/sg_inlines.h> #include <simgear/sg_inlines.h>
#include <simgear/debug/logstream.hxx> #include <simgear/debug/logstream.hxx>

View file

@ -14,10 +14,9 @@
#include <vector> #include <vector>
SG_USING_STD(vector); SG_USING_STD(vector);
#include <plib/ssg.h>
class ssgEntity; class ssgEntity;
class ssgBranch; class ssgBranch;
class ssgLeaf;
class FGHitRec { class FGHitRec {

View file

@ -25,8 +25,6 @@
# include <config.h> # include <config.h>
#endif #endif
#include <plib/ssg.h> // plib include
#include <simgear/bucket/newbucket.hxx> #include <simgear/bucket/newbucket.hxx>
#include <simgear/debug/logstream.hxx> #include <simgear/debug/logstream.hxx>
#include <simgear/misc/sg_path.hxx> #include <simgear/misc/sg_path.hxx>
@ -246,7 +244,8 @@ void FGNewCache::clear_cache() {
} }
// and ... just in case we missed something ... // and ... just in case we missed something ...
globals->get_scenery()->get_terrain_branch()->removeAllKids(); osg::Group* group = globals->get_scenery()->get_terrain_branch();
group->removeChildren(0, group->getNumChildren());
} }

View file

@ -28,15 +28,17 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <osgUtil/IntersectVisitor>
#include <simgear/debug/logstream.hxx> #include <simgear/debug/logstream.hxx>
#include <simgear/scene/tgdb/userdata.hxx> #include <simgear/scene/tgdb/userdata.hxx>
#include <simgear/math/sg_geodesy.hxx> #include <simgear/math/sg_geodesy.hxx>
#include <simgear/scene/model/placementtrans.hxx> #include <simgear/scene/model/placementtrans.hxx>
#include <simgear/scene/material/matlib.hxx> #include <simgear/scene/material/matlib.hxx>
#include <simgear/scene/util/SGNodeMasks.hxx>
#include <Main/fg_props.hxx> #include <Main/fg_props.hxx>
#include "hitlist.hxx"
#include "scenery.hxx" #include "scenery.hxx"
@ -55,33 +57,33 @@ FGScenery::~FGScenery() {
void FGScenery::init() { void FGScenery::init() {
// Scene graph root // Scene graph root
scene_graph = new ssgRoot; scene_graph = new osg::Group;
scene_graph->setName( "Scene" ); scene_graph->setName( "Scene" );
// Terrain branch // Terrain branch
terrain_branch = new ssgBranch; terrain_branch = new osg::Group;
terrain_branch->setName( "Terrain" ); terrain_branch->setName( "Terrain" );
scene_graph->addKid( terrain_branch ); scene_graph->addChild( terrain_branch.get() );
models_branch = new ssgBranch; models_branch = new osg::Group;
models_branch->setName( "Models" ); models_branch->setName( "Models" );
scene_graph->addKid( models_branch ); scene_graph->addChild( models_branch.get() );
aircraft_branch = new ssgBranch; aircraft_branch = new osg::Group;
aircraft_branch->setName( "Aircraft" ); aircraft_branch->setName( "Aircraft" );
scene_graph->addKid( aircraft_branch ); scene_graph->addChild( aircraft_branch.get() );
// Lighting // Lighting
gnd_lights_root = new ssgRoot; gnd_lights_root = new osg::Group;
gnd_lights_root->setName( "Ground Lighting Root" ); gnd_lights_root->setName( "Ground Lighting Root" );
vasi_lights_root = new ssgRoot; vasi_lights_root = new osg::Group;
vasi_lights_root->setName( "VASI/PAPI Lighting Root" ); vasi_lights_root->setName( "VASI/PAPI Lighting Root" );
rwy_lights_root = new ssgRoot; rwy_lights_root = new osg::Group;
rwy_lights_root->setName( "Runway Lighting Root" ); rwy_lights_root->setName( "Runway Lighting Root" );
taxi_lights_root = new ssgRoot; taxi_lights_root = new osg::Group;
taxi_lights_root->setName( "Taxi Lighting Root" ); taxi_lights_root->setName( "Taxi Lighting Root" );
// Initials values needed by the draw-time object loader // Initials values needed by the draw-time object loader
@ -107,17 +109,17 @@ void FGScenery::set_center( const SGVec3d& p ) {
center = p; center = p;
placement_list_type::iterator it = _placement_list.begin(); placement_list_type::iterator it = _placement_list.begin();
while (it != _placement_list.end()) { while (it != _placement_list.end()) {
(*it)->setSceneryCenter(center.sg()); (*it)->setSceneryCenter(center);
++it; ++it;
} }
} }
void FGScenery::register_placement_transform(ssgPlacementTransform *trans) { void FGScenery::register_placement_transform(SGPlacementTransform *trans) {
_placement_list.push_back(trans); _placement_list.push_back(trans);
trans->setSceneryCenter(center.sg()); trans->setSceneryCenter(center);
} }
void FGScenery::unregister_placement_transform(ssgPlacementTransform *trans) { void FGScenery::unregister_placement_transform(SGPlacementTransform *trans) {
placement_list_type::iterator it = _placement_list.begin(); placement_list_type::iterator it = _placement_list.begin();
while (it != _placement_list.end()) { while (it != _placement_list.end()) {
if ((*it) == trans) { if ((*it) == trans) {
@ -154,29 +156,32 @@ FGScenery::get_cart_elevation_m(const SGVec3d& pos, double max_altoff,
} }
} }
// overridden with actual values if a terrain intersection is
// found SGVec3d start = pos + max_altoff*normalize(pos) - center;
int this_hit; SGVec3d end = - center;
double hit_radius = 0.0;
SGVec3d hit_normal(0, 0, 0);
SGVec3d sc = center; osgUtil::IntersectVisitor intersectVisitor;
SGVec3d ncpos = pos; intersectVisitor.setTraversalMask(SG_NODEMASK_TERRAIN_BIT);
osg::ref_ptr<osg::LineSegment> lineSegment;
FGHitList hit_list; lineSegment = new osg::LineSegment(start.osg(), end.osg());
// scenery center has been properly defined so any hit should intersectVisitor.addLineSegment(lineSegment.get());
// be valid (and not just luck) get_scene_graph()->accept(intersectVisitor);
bool hit = fgCurrentElev(ncpos.sg(), max_altoff+length(pos), sc.sg(), bool hits = intersectVisitor.hits();
get_scene_graph(), &hit_list, &alt, if (hits) {
&hit_radius, hit_normal.sg(), this_hit); int nHits = intersectVisitor.getNumHits(lineSegment.get());
alt = -SGLimitsd::max();
if (material) { for (int i = 0; i < nHits; ++i) {
*material = 0; const osgUtil::Hit& hit
if (hit) { = intersectVisitor.getHitList(lineSegment.get())[i];
ssgEntity *entity = hit_list.get_entity( this_hit ); SGVec3d point;
if (entity && entity->isAKindOf(ssgTypeLeaf())) { point.osg() = hit.getWorldIntersectPoint();
ssgLeaf* leaf = static_cast<ssgLeaf*>(entity); point += center;
*material = globals->get_matlib()->findMaterial(leaf); SGGeod geod = SGGeod::fromCart(point);
double elevation = geod.getElevationM();
if (alt < elevation) {
alt = elevation;
if (material)
*material = globals->get_matlib()->findMaterial(hit.getGeode());
} }
} }
} }
@ -184,7 +189,7 @@ FGScenery::get_cart_elevation_m(const SGVec3d& pos, double max_altoff,
if (replaced_center) if (replaced_center)
set_center( saved_center ); set_center( saved_center );
return hit; return hits;
} }
bool bool
@ -207,43 +212,37 @@ FGScenery::get_cart_ground_intersection(const SGVec3d& pos, const SGVec3d& dir,
} }
} }
// Not yet found any hit ...
bool result = false;
// Make really sure the direction is normalized, is really cheap compared to // Make really sure the direction is normalized, is really cheap compared to
// computation of ground intersection. // computation of ground intersection.
SGVec3d normalizedDir = normalize(dir); SGVec3d start = pos - center;
SGVec3d relativePos = pos - center; SGVec3d end = start + 1e5*dir;
// At the moment only intersection with the terrain? osgUtil::IntersectVisitor intersectVisitor;
FGHitList hit_list; intersectVisitor.setTraversalMask(SG_NODEMASK_TERRAIN_BIT);
hit_list.Intersect(globals->get_scenery()->get_terrain_branch(), osg::ref_ptr<osg::LineSegment> lineSegment;
relativePos.sg(), normalizedDir.sg()); lineSegment = new osg::LineSegment(start.osg(), end.osg());
intersectVisitor.addLineSegment(lineSegment.get());
double dist = DBL_MAX; get_scene_graph()->accept(intersectVisitor);
int hitcount = hit_list.num_hits(); bool hits = intersectVisitor.hits();
for (int i = 0; i < hitcount; ++i) { if (hits) {
// Check for the nearest hit int nHits = intersectVisitor.getNumHits(lineSegment.get());
SGVec3d diff = SGVec3d(hit_list.get_point(i)) - relativePos; double dist = SGLimitsd::max();
for (int i = 0; i < nHits; ++i) {
// We only want hits in front of us ... const osgUtil::Hit& hit
if (dot(normalizedDir, diff) < 0) = intersectVisitor.getHitList(lineSegment.get())[i];
continue; SGVec3d point;
point.osg() = hit.getWorldIntersectPoint();
// find the nearest hit double newdist = length(start - point);
double nDist = dot(diff, diff); if (newdist < dist) {
if (dist < nDist) dist = newdist;
continue; nearestHit = point + center;
}
// Store the hit point }
dist = nDist;
nearestHit = SGVec3d(hit_list.get_point(i)) + center;
result = true;
} }
if (replaced_center) if (replaced_center)
set_center( saved_center ); set_center( saved_center );
return result; return hits;
} }

View file

@ -31,18 +31,16 @@
#include <list> #include <list>
#include <plib/sg.h> #include <osg/ref_ptr>
#include <osg/Group>
#include <simgear/compiler.h> #include <simgear/compiler.h>
#include <simgear/structure/subsystem_mgr.hxx> #include <simgear/structure/subsystem_mgr.hxx>
#include <simgear/math/point3d.hxx> #include <simgear/math/point3d.hxx>
#include <simgear/scene/model/placementtrans.hxx> #include <simgear/scene/model/placementtrans.hxx>
#include <simgear/structure/ssgSharedPtr.hxx>
SG_USING_STD(list); SG_USING_STD(list);
class ssgRoot;
class ssgBranch;
class SGMaterial; class SGMaterial;
@ -56,17 +54,17 @@ class FGScenery : public SGSubsystem {
double sun_angle; double sun_angle;
// SSG scene graph // SSG scene graph
ssgSharedPtr<ssgRoot> scene_graph; osg::ref_ptr<osg::Group> scene_graph;
ssgSharedPtr<ssgBranch> terrain_branch; osg::ref_ptr<osg::Group> terrain_branch;
ssgSharedPtr<ssgRoot> gnd_lights_root; osg::ref_ptr<osg::Group> gnd_lights_root;
ssgSharedPtr<ssgRoot> vasi_lights_root; osg::ref_ptr<osg::Group> vasi_lights_root;
ssgSharedPtr<ssgRoot> rwy_lights_root; osg::ref_ptr<osg::Group> rwy_lights_root;
ssgSharedPtr<ssgRoot> taxi_lights_root; osg::ref_ptr<osg::Group> taxi_lights_root;
ssgSharedPtr<ssgBranch> models_branch; osg::ref_ptr<osg::Group> models_branch;
ssgSharedPtr<ssgBranch> aircraft_branch; osg::ref_ptr<osg::Group> aircraft_branch;
// list of all placement transform, used to move the scenery center on the fly. // list of all placement transform, used to move the scenery center on the fly.
typedef list<ssgSharedPtr<ssgPlacementTransform> > placement_list_type; typedef list<osg::ref_ptr<SGPlacementTransform> > placement_list_type;
placement_list_type _placement_list; placement_list_type _placement_list;
public: public:
@ -120,56 +118,56 @@ public:
const SGVec3d& get_center() const { return center; } const SGVec3d& get_center() const { return center; }
void set_center( const SGVec3d& p ); void set_center( const SGVec3d& p );
inline ssgRoot *get_scene_graph () const { return scene_graph; } osg::Group *get_scene_graph () const { return scene_graph.get(); }
inline void set_scene_graph (ssgRoot * s) { scene_graph = s; } inline void set_scene_graph (osg::Group * s) { scene_graph = s; }
inline ssgBranch *get_terrain_branch () const { return terrain_branch; } osg::Group *get_terrain_branch () const { return terrain_branch.get(); }
inline void set_terrain_branch (ssgBranch * t) { terrain_branch = t; } inline void set_terrain_branch (osg::Group * t) { terrain_branch = t; }
inline ssgRoot *get_gnd_lights_root () const { inline osg::Group *get_gnd_lights_root () const {
return gnd_lights_root; return gnd_lights_root.get();
} }
inline void set_gnd_lights_root (ssgRoot *r) { inline void set_gnd_lights_root (osg::Group *r) {
gnd_lights_root = r; gnd_lights_root = r;
} }
inline ssgRoot *get_vasi_lights_root () const { inline osg::Group *get_vasi_lights_root () const {
return vasi_lights_root; return vasi_lights_root.get();
} }
inline void set_vasi_lights_root (ssgRoot *r) { inline void set_vasi_lights_root (osg::Group *r) {
vasi_lights_root = r; vasi_lights_root = r;
} }
inline ssgRoot *get_rwy_lights_root () const { inline osg::Group *get_rwy_lights_root () const {
return rwy_lights_root; return rwy_lights_root.get();
} }
inline void set_rwy_lights_root (ssgRoot *r) { inline void set_rwy_lights_root (osg::Group *r) {
rwy_lights_root = r; rwy_lights_root = r;
} }
inline ssgRoot *get_taxi_lights_root () const { inline osg::Group *get_taxi_lights_root () const {
return taxi_lights_root; return taxi_lights_root.get();
} }
inline void set_taxi_lights_root (ssgRoot *r) { inline void set_taxi_lights_root (osg::Group *r) {
taxi_lights_root = r; taxi_lights_root = r;
} }
inline ssgBranch *get_models_branch () const { inline osg::Group *get_models_branch () const {
return models_branch; return models_branch.get();
} }
inline void set_models_branch (ssgBranch *t) { inline void set_models_branch (osg::Group *t) {
models_branch = t; models_branch = t;
} }
inline ssgBranch *get_aircraft_branch () const { inline osg::Group *get_aircraft_branch () const {
return aircraft_branch; return aircraft_branch.get();
} }
inline void set_aircraft_branch (ssgBranch *t) { inline void set_aircraft_branch (osg::Group *t) {
aircraft_branch = t; aircraft_branch = t;
} }
void register_placement_transform(ssgPlacementTransform *trans); void register_placement_transform(SGPlacementTransform *trans);
void unregister_placement_transform(ssgPlacementTransform *trans); void unregister_placement_transform(SGPlacementTransform *trans);
}; };

File diff suppressed because it is too large Load diff

View file

@ -42,7 +42,13 @@
#include <simgear/math/point3d.hxx> #include <simgear/math/point3d.hxx>
#include <simgear/misc/sg_path.hxx> #include <simgear/misc/sg_path.hxx>
#include <simgear/scene/model/placementtrans.hxx> #include <simgear/scene/model/placementtrans.hxx>
#include <simgear/structure/ssgSharedPtr.hxx>
#include <osg/ref_ptr>
#include <osg/Array>
#include <osg/Group>
#include <osg/LOD>
#include <osg/MatrixTransform>
#include <osg/Switch>
#if defined( sgi ) #if defined( sgi )
#include <strings.h> #include <strings.h>
@ -57,12 +63,6 @@ typedef point_list::iterator point_list_iterator;
typedef point_list::const_iterator const_point_list_iterator; typedef point_list::const_iterator const_point_list_iterator;
class ssgLeaf;
class ssgBranch;
class ssgTransform;
class ssgSelector;
class ssgRangeSelector;
class ssgVertexArray;
class FGTileEntry; class FGTileEntry;
@ -76,7 +76,7 @@ private:
string model_path; string model_path;
string texture_path; string texture_path;
FGTileEntry *tile; FGTileEntry *tile;
ssgSharedPtr<ssgTransform> obj_trans; osg::ref_ptr<osg::MatrixTransform> obj_trans;
SGBucket bucket; SGBucket bucket;
bool cache_obj; bool cache_obj;
@ -85,7 +85,7 @@ public:
inline FGDeferredModel() { } inline FGDeferredModel() { }
inline FGDeferredModel( const string& mp, const string& tp, SGBucket b, inline FGDeferredModel( const string& mp, const string& tp, SGBucket b,
FGTileEntry *t, ssgTransform *ot, bool co ) FGTileEntry *t, osg::MatrixTransform *ot, bool co )
{ {
model_path = mp; model_path = mp;
texture_path = tp; texture_path = tp;
@ -100,7 +100,7 @@ public:
inline const SGBucket& get_bucket() const { return bucket; } inline const SGBucket& get_bucket() const { return bucket; }
inline const bool get_cache_state() const { return cache_obj; } inline const bool get_cache_state() const { return cache_obj; }
inline FGTileEntry *get_tile() const { return tile; } inline FGTileEntry *get_tile() const { return tile; }
inline ssgTransform *get_obj_trans() const { return obj_trans; } inline osg::MatrixTransform *get_obj_trans() const { return obj_trans.get(); }
}; };
@ -121,10 +121,10 @@ public:
private: private:
// ssg tree structure for this tile is as follows: // ssg tree structure for this tile is as follows:
// ssgRoot(scene) // osg::Group(scene)
// - ssgBranch(terrain) // - osg::Group(terrain)
// - ssgTransform(tile) // - SGPlacementTransform(tile)
// - ssgRangeSelector(tile) // - osg::LOD(tile)
// - ssgEntity(tile) // - ssgEntity(tile)
// - kid1(fan) // - kid1(fan)
// - kid2(fan) // - kid2(fan)
@ -132,27 +132,27 @@ private:
// - kidn(fan) // - kidn(fan)
// pointer to ssg transform for this tile // pointer to ssg transform for this tile
ssgSharedPtr<ssgPlacementTransform> terra_transform; osg::ref_ptr<SGPlacementTransform> terra_transform;
ssgSharedPtr<ssgPlacementTransform> vasi_lights_transform; osg::ref_ptr<SGPlacementTransform> vasi_lights_transform;
ssgSharedPtr<ssgPlacementTransform> rwy_lights_transform; osg::ref_ptr<SGPlacementTransform> rwy_lights_transform;
ssgSharedPtr<ssgPlacementTransform> taxi_lights_transform; osg::ref_ptr<SGPlacementTransform> taxi_lights_transform;
ssgSharedPtr<ssgPlacementTransform> gnd_lights_transform; osg::ref_ptr<SGPlacementTransform> gnd_lights_transform;
// pointer to ssg range selector for this tile // pointer to ssg range selector for this tile
ssgSharedPtr<ssgRangeSelector> terra_range; osg::ref_ptr<osg::LOD> terra_range;
ssgSharedPtr<ssgRangeSelector> gnd_lights_range; osg::ref_ptr<osg::LOD> gnd_lights_range;
// we create several preset brightness and can choose which one we // we create several preset brightness and can choose which one we
// want based on lighting conditions. // want based on lighting conditions.
ssgSharedPtr<ssgSelector> gnd_lights_brightness; osg::ref_ptr<osg::Switch> gnd_lights_brightness;
// we need to be able to turn runway lights on or off (doing this // we need to be able to turn runway lights on or off (doing this
// via a call back would be nifty, but then the call back needs to // via a call back would be nifty, but then the call back needs to
// know about the higher level application's global state which is // know about the higher level application's global state which is
// a problem if we move the code into simgear.) // a problem if we move the code into simgear.)
ssgSharedPtr<ssgSelector> vasi_lights_selector; osg::ref_ptr<osg::Switch> vasi_lights_selector;
ssgSharedPtr<ssgSelector> rwy_lights_selector; osg::ref_ptr<osg::Switch> rwy_lights_selector;
ssgSharedPtr<ssgSelector> taxi_lights_selector; osg::ref_ptr<osg::Switch> taxi_lights_selector;
/** /**
* Indicates this tile has been loaded from a file and connected * Indicates this tile has been loaded from a file and connected
@ -169,15 +169,15 @@ private:
volatile int pending_models; volatile int pending_models;
bool obj_load( const string& path, bool obj_load( const string& path,
ssgBranch* geometry, osg::Group* geometry,
ssgBranch* vasi_lights, osg::Group* vasi_lights,
ssgBranch* rwy_lights, osg::Group* rwy_lights,
ssgBranch* taxi_lights, osg::Group* taxi_lights,
ssgVertexArray* gound_lights, osg::Vec3Array* gound_lights,
bool is_base ); bool is_base );
ssgLeaf* gen_lights( SGMaterialLib *matlib, ssgVertexArray *lights, osg::Node* gen_lights( SGMaterialLib *matlib, osg::Vec3Array *lights,
int inc, float bright ); int inc, float bright );
double timestamp; double timestamp;
@ -254,19 +254,14 @@ public:
*/ */
inline const SGBucket& get_tile_bucket() const { return tile_bucket; } inline const SGBucket& get_tile_bucket() const { return tile_bucket; }
/**
* Apply ssgLeaf::makeDList to all leaf of a branch
*/
void makeDList( ssgBranch *b );
/** /**
* Add terrain mesh and ground lighting to scene graph. * Add terrain mesh and ground lighting to scene graph.
*/ */
void add_ssg_nodes( ssgBranch *terrain_branch, void add_ssg_nodes( osg::Group *terrain_branch,
ssgBranch *gnd_lights_branch, osg::Group *gnd_lights_branch,
ssgBranch *vasi_lights_branch, osg::Group *vasi_lights_branch,
ssgBranch *rwy_lights_branch, osg::Group *rwy_lights_branch,
ssgBranch *taxi_lights_branch ); osg::Group *taxi_lights_branch );
/** /**
* disconnect terrain mesh and ground lighting nodes from scene * disconnect terrain mesh and ground lighting nodes from scene
@ -278,7 +273,7 @@ public:
/** /**
* return the SSG Transform node for the terrain * return the SSG Transform node for the terrain
*/ */
inline ssgPlacementTransform *get_terra_transform() const { return terra_transform; } inline SGPlacementTransform *get_terra_transform() const { return terra_transform.get(); }
inline double get_timestamp() const { return timestamp; } inline double get_timestamp() const { return timestamp; }
inline void set_timestamp( double time_ms ) { timestamp = time_ms; } inline void set_timestamp( double time_ms ) { timestamp = time_ms; }

View file

@ -25,8 +25,6 @@
# include <config.h> # include <config.h>
#endif #endif
#include <plib/ssg.h>
#include <simgear/constants.h> #include <simgear/constants.h>
#include <simgear/debug/logstream.hxx> #include <simgear/debug/logstream.hxx>
#include <simgear/math/point3d.hxx> #include <simgear/math/point3d.hxx>
@ -35,7 +33,6 @@
#include <simgear/math/vector.hxx> #include <simgear/math/vector.hxx>
#include <simgear/structure/exception.hxx> #include <simgear/structure/exception.hxx>
#include <simgear/scene/model/modellib.hxx> #include <simgear/scene/model/modellib.hxx>
#include <simgear/scene/model/shadowvolume.hxx>
#include <Main/globals.hxx> #include <Main/globals.hxx>
#include <Main/fg_props.hxx> #include <Main/fg_props.hxx>
@ -59,8 +56,6 @@ queue<FGTileEntry *> FGTileMgr::delete_queue;
bool FGTileMgr::tile_filter = true; bool FGTileMgr::tile_filter = true;
extern SGShadowVolume *shadows;
// Constructor // Constructor
FGTileMgr::FGTileMgr(): FGTileMgr::FGTileMgr():
state( Start ), state( Start ),
@ -126,7 +121,8 @@ void FGTileMgr::sched_tile( const SGBucket& b, const bool is_inner_ring ) {
long index = tile_cache.get_oldest_tile(); long index = tile_cache.get_oldest_tile();
if ( index >= 0 ) { if ( index >= 0 ) {
FGTileEntry *old = tile_cache.get_tile( index ); FGTileEntry *old = tile_cache.get_tile( index );
shadows->deleteOccluderFromTile( (ssgBranch *) old->get_terra_transform() ); // OSGFIXME
// shadows->deleteOccluderFromTile( (ssgBranch *) old->get_terra_transform() );
old->disconnect_ssg_nodes(); old->disconnect_ssg_nodes();
delete_queue.push( old ); delete_queue.push( old );
tile_cache.clear_entry( index ); tile_cache.clear_entry( index );
@ -310,9 +306,10 @@ void FGTileMgr::update_queues()
// tile cache // tile cache
FGTileEntry *t = tile_cache.get_tile( dm->get_bucket() ); FGTileEntry *t = tile_cache.get_tile( dm->get_bucket() );
if ( t != NULL ) { if ( t != NULL ) {
ssgTexturePath( (char *)(dm->get_texture_path().c_str()) ); //OSGFIXME
// ssgTexturePath( (char *)(dm->get_texture_path().c_str()) );
try { try {
ssgEntity *obj_model = osg::Node *obj_model =
globals->get_model_lib()->load_model( ".", globals->get_model_lib()->load_model( ".",
dm->get_model_path(), dm->get_model_path(),
globals->get_props(), globals->get_props(),
@ -320,10 +317,11 @@ void FGTileMgr::update_queues()
dm->get_cache_state(), dm->get_cache_state(),
new FGNasalModelData ); new FGNasalModelData );
if ( obj_model != NULL ) { if ( obj_model != NULL ) {
dm->get_obj_trans()->addKid( obj_model ); dm->get_obj_trans()->addChild( obj_model );
shadows->addOccluder( (ssgBranch *) obj_model->getParent(0), //OSGFIXME
SGShadowVolume::occluderTypeTileObject, // shadows->addOccluder( (ssgBranch *) obj_model->getParent(0),
(ssgBranch *) dm->get_tile()->get_terra_transform()); // SGShadowVolume::occluderTypeTileObject,
// (ssgBranch *) dm->get_tile()->get_terra_transform());
} }
} catch (const sg_io_exception& exc) { } catch (const sg_io_exception& exc) {
string m(exc.getMessage()); string m(exc.getMessage());

View file

@ -740,7 +740,7 @@ void FGNasalListener::valueChanged(SGPropertyNode* node)
// is removed from the scene graph. // is removed from the scene graph.
void FGNasalModelData::modelLoaded(const string& path, SGPropertyNode *prop, void FGNasalModelData::modelLoaded(const string& path, SGPropertyNode *prop,
ssgBranch *) osg::Node *)
{ {
SGPropertyNode *n = prop->getNode("nasal"), *load; SGPropertyNode *n = prop->getNode("nasal"), *load;
if (!n) if (!n)

View file

@ -149,7 +149,7 @@ class FGNasalModelData : public SGModelData {
public: public:
FGNasalModelData() : _unload(0) {} FGNasalModelData() : _unload(0) {}
~FGNasalModelData(); ~FGNasalModelData();
void modelLoaded(const string& path, SGPropertyNode *prop, ssgBranch *); void modelLoaded(const string& path, SGPropertyNode *prop, osg::Node *);
private: private:
string _module; string _module;

View file

@ -68,6 +68,8 @@ FGLight::FGLight ()
_diffuse_tbl( NULL ), _diffuse_tbl( NULL ),
_specular_tbl( NULL ), _specular_tbl( NULL ),
_sky_tbl( NULL ), _sky_tbl( NULL ),
_sun_angle(0),
_moon_angle(0),
_prev_sun_angle(-9999.0), _prev_sun_angle(-9999.0),
_sun_rotation( 0.0 ), _sun_rotation( 0.0 ),
_dt_total( 0.0 ) _dt_total( 0.0 )
@ -227,7 +229,7 @@ void FGLight::update_sky_color () {
} }
gamma_correct_rgb( _cloud_color ); gamma_correct_rgb( _cloud_color );
float *sun_color = thesky->get_sun_color(); SGVec4f sun_color = thesky->get_sun_color();
_scene_ambient[0] = ((sun_color[0]*0.25 + _cloud_color[0]*0.75) + ambient) / 2; _scene_ambient[0] = ((sun_color[0]*0.25 + _cloud_color[0]*0.75) + ambient) / 2;
_scene_ambient[1] = ((sun_color[1]*0.25 + _cloud_color[1]*0.75) + ambient) / 2; _scene_ambient[1] = ((sun_color[1]*0.25 + _cloud_color[1]*0.75) + ambient) / 2;
@ -289,7 +291,7 @@ void FGLight::update_adj_fog_color () {
// revert to unmodified values before usign them. // revert to unmodified values before usign them.
// //
float *sun_color = thesky->get_sun_color(); SGVec4f sun_color = thesky->get_sun_color();
gamma_restore_rgb( _fog_color ); gamma_restore_rgb( _fog_color );