1
0
Fork 0

Make LOD properties of AI/MP aircraft run-time configurable.

This commit is contained in:
ThorstenB 2011-10-03 12:01:58 +02:00
parent 465557cfa7
commit 3451012bca
4 changed files with 59 additions and 17 deletions

View file

@ -179,6 +179,27 @@ void FGAIBase::update(double dt) {
ft_per_deg_lon = 365228.16 * cos(pos.getLatitudeRad()); ft_per_deg_lon = 365228.16 * cos(pos.getLatitudeRad());
} }
/** update LOD properties of the model */
void FGAIBase::updateLOD()
{
double maxRangeDetail = fgGetDouble("/sim/rendering/static-lod/ai-detailed", 10000.0);
double maxRangeBare = fgGetDouble("/sim/rendering/static-lod/ai-bare", 20000.0);
if (_model.valid())
{
if( maxRangeDetail == 0.0 )
{
// disable LOD
_model->setRange(0, 0.0, FLT_MAX);
_model->setRange(1, FLT_MAX, FLT_MAX);
}
else
{
_model->setRange(0, 0.0, maxRangeDetail);
_model->setRange(1, maxRangeDetail,maxRangeBare);
}
}
}
void FGAIBase::Transform() { void FGAIBase::Transform() {
if (!invisible) { if (!invisible) {
@ -226,23 +247,22 @@ bool FGAIBase::init(bool search_in_AI_path) {
_installed = true; _installed = true;
osg::Node * mdl = SGModelLib::loadPagedModel(f, props, new FGNasalModelData(props)); osg::Node * mdl = SGModelLib::loadPagedModel(f, props, new FGNasalModelData(props));
model = mdl;
double aiModelMaxRange = fgGetDouble("/sim/rendering/static-lod/ai", 0.0); _model = new osg::LOD;
if( aiModelMaxRange > 0.0 ) { _model->setName("AI-model range animation node");
osg::LOD * lod = new osg::LOD;
lod->setName("AI-model range animation node");
lod->addChild( mdl, 0, aiModelMaxRange ); _model->addChild( mdl, 0, FLT_MAX );
lod->setCenterMode(osg::LOD::USE_BOUNDING_SPHERE_CENTER); _model->setCenterMode(osg::LOD::USE_BOUNDING_SPHERE_CENTER);
lod->setRangeMode(osg::LOD::DISTANCE_FROM_EYE_POINT); _model->setRangeMode(osg::LOD::DISTANCE_FROM_EYE_POINT);
// We really need low-resolution versions of AI/MP aircraft.
model = lod; // Or at least dummy "stubs" with some default silhouette.
} // _model->addChild( SGModelLib::loadPagedModel(fgGetString("/sim/multiplay/default-model", default_model),
// props, new FGNasalModelData(props)), FLT_MAX, FLT_MAX);
updateLOD();
initModel(mdl); initModel(mdl);
if (model.valid() && _initialized == false) { if (_model.valid() && _initialized == false) {
aip.init( model.get() ); aip.init( _model.get() );
aip.setVisible(true); aip.setVisible(true);
invisible = false; invisible = false;
globals->get_scenery()->get_scene_graph()->addChild(aip.getSceneGraph()); globals->get_scenery()->get_scene_graph()->addChild(aip.getSceneGraph());
@ -260,7 +280,7 @@ bool FGAIBase::init(bool search_in_AI_path) {
void FGAIBase::initModel(osg::Node *node) void FGAIBase::initModel(osg::Node *node)
{ {
if (model.valid()) { if (_model.valid()) {
if( _path != ""){ if( _path != ""){
props->setStringValue("submodels/path", _path.c_str()); props->setStringValue("submodels/path", _path.c_str());
@ -523,7 +543,7 @@ SGVec3d FGAIBase::getCartPos() const {
bool FGAIBase::getGroundElevationM(const SGGeod& pos, double& elev, bool FGAIBase::getGroundElevationM(const SGGeod& pos, double& elev,
const SGMaterial** material) const { const SGMaterial** material) const {
return globals->get_scenery()->get_elevation_m(pos, elev, material, return globals->get_scenery()->get_elevation_m(pos, elev, material,
model.get()); _model.get());
} }
double FGAIBase::_getCartPosX() const { double FGAIBase::_getCartPosX() const {

View file

@ -64,6 +64,7 @@ public:
virtual void unbind(); virtual void unbind();
virtual void reinit() {} virtual void reinit() {}
void updateLOD();
void setManager(FGAIManager* mgr, SGPropertyNode* p); void setManager(FGAIManager* mgr, SGPropertyNode* p);
void setPath( const char* model ); void setPath( const char* model );
void setSMPath( const string& p ); void setSMPath( const string& p );
@ -186,7 +187,6 @@ 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
osg::ref_ptr<osg::Node> model; //The 3D model object
SGModelPlacement aip; SGModelPlacement aip;
bool delete_me; bool delete_me;
@ -222,6 +222,7 @@ private:
int _refID; int _refID;
object_type _otype; object_type _otype;
bool _initialized; bool _initialized;
osg::ref_ptr<osg::LOD> _model; //The 3D model LOD object
public: public:
object_type getType(); object_type getType();

View file

@ -43,7 +43,12 @@
#include "AIGroundVehicle.hxx" #include "AIGroundVehicle.hxx"
#include "AIEscort.hxx" #include "AIEscort.hxx"
FGAIManager::FGAIManager() { FGAIManager::FGAIManager() :
cb_ai_bare(SGPropertyChangeCallback<FGAIManager>(this,&FGAIManager::updateLOD,
fgGetNode("/sim/rendering/static-lod/ai-bare", true))),
cb_ai_detailed(SGPropertyChangeCallback<FGAIManager>(this,&FGAIManager::updateLOD,
fgGetNode("/sim/rendering/static-lod/ai-detailed", true)))
{
_dt = 0.0; _dt = 0.0;
mNumAiModels = 0; mNumAiModels = 0;
@ -181,6 +186,18 @@ FGAIManager::update(double dt) {
thermal_lift_node->setDoubleValue( strength ); // for thermals thermal_lift_node->setDoubleValue( strength ); // for thermals
} }
/** update LOD settings of all AI/MP models */
void
FGAIManager::updateLOD(SGPropertyNode* node)
{
ai_list_iterator ai_list_itr = ai_list.begin();
while(ai_list_itr != ai_list.end())
{
(*ai_list_itr)->updateLOD();
++ai_list_itr;
}
}
void void
FGAIManager::attach(FGAIBase *model) FGAIManager::attach(FGAIBase *model)
{ {

View file

@ -27,6 +27,7 @@
#include <simgear/structure/subsystem_mgr.hxx> #include <simgear/structure/subsystem_mgr.hxx>
#include <simgear/structure/SGSharedPtr.hxx> #include <simgear/structure/SGSharedPtr.hxx>
#include <simgear/props/props_io.hxx>
#include <Main/fg_props.hxx> #include <Main/fg_props.hxx>
@ -66,6 +67,7 @@ public:
void bind(); void bind();
void unbind(); void unbind();
void update(double dt); void update(double dt);
void updateLOD(SGPropertyNode* node);
void attach(FGAIBase *model); void attach(FGAIBase *model);
void destroyObject( int ID ); void destroyObject( int ID );
@ -135,6 +137,8 @@ private:
double strength; double strength;
void processThermal( FGAIThermal* thermal ); void processThermal( FGAIThermal* thermal );
SGPropertyChangeCallback<FGAIManager> cb_ai_bare;
SGPropertyChangeCallback<FGAIManager> cb_ai_detailed;
}; };
#endif // _FG_AIMANAGER_HXX #endif // _FG_AIMANAGER_HXX