Make LOD properties of AI/MP aircraft run-time configurable.
This commit is contained in:
parent
465557cfa7
commit
3451012bca
4 changed files with 59 additions and 17 deletions
|
@ -179,6 +179,27 @@ void FGAIBase::update(double dt) {
|
|||
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() {
|
||||
|
||||
if (!invisible) {
|
||||
|
@ -226,23 +247,22 @@ bool FGAIBase::init(bool search_in_AI_path) {
|
|||
_installed = true;
|
||||
|
||||
osg::Node * mdl = SGModelLib::loadPagedModel(f, props, new FGNasalModelData(props));
|
||||
model = mdl;
|
||||
|
||||
double aiModelMaxRange = fgGetDouble("/sim/rendering/static-lod/ai", 0.0);
|
||||
if( aiModelMaxRange > 0.0 ) {
|
||||
osg::LOD * lod = new osg::LOD;
|
||||
lod->setName("AI-model range animation node");
|
||||
_model = new osg::LOD;
|
||||
_model->setName("AI-model range animation node");
|
||||
|
||||
lod->addChild( mdl, 0, aiModelMaxRange );
|
||||
lod->setCenterMode(osg::LOD::USE_BOUNDING_SPHERE_CENTER);
|
||||
lod->setRangeMode(osg::LOD::DISTANCE_FROM_EYE_POINT);
|
||||
|
||||
model = lod;
|
||||
}
|
||||
_model->addChild( mdl, 0, FLT_MAX );
|
||||
_model->setCenterMode(osg::LOD::USE_BOUNDING_SPHERE_CENTER);
|
||||
_model->setRangeMode(osg::LOD::DISTANCE_FROM_EYE_POINT);
|
||||
// We really need low-resolution versions of AI/MP aircraft.
|
||||
// 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);
|
||||
if (model.valid() && _initialized == false) {
|
||||
aip.init( model.get() );
|
||||
if (_model.valid() && _initialized == false) {
|
||||
aip.init( _model.get() );
|
||||
aip.setVisible(true);
|
||||
invisible = false;
|
||||
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)
|
||||
{
|
||||
if (model.valid()) {
|
||||
if (_model.valid()) {
|
||||
|
||||
if( _path != ""){
|
||||
props->setStringValue("submodels/path", _path.c_str());
|
||||
|
@ -523,7 +543,7 @@ SGVec3d FGAIBase::getCartPos() const {
|
|||
bool FGAIBase::getGroundElevationM(const SGGeod& pos, double& elev,
|
||||
const SGMaterial** material) const {
|
||||
return globals->get_scenery()->get_elevation_m(pos, elev, material,
|
||||
model.get());
|
||||
_model.get());
|
||||
}
|
||||
|
||||
double FGAIBase::_getCartPosX() const {
|
||||
|
|
|
@ -64,6 +64,7 @@ public:
|
|||
virtual void unbind();
|
||||
virtual void reinit() {}
|
||||
|
||||
void updateLOD();
|
||||
void setManager(FGAIManager* mgr, SGPropertyNode* p);
|
||||
void setPath( const char* model );
|
||||
void setSMPath( const string& p );
|
||||
|
@ -186,7 +187,6 @@ protected:
|
|||
double ht_diff; // value used by radar display instrument
|
||||
|
||||
string model_path; //Path to the 3D model
|
||||
osg::ref_ptr<osg::Node> model; //The 3D model object
|
||||
SGModelPlacement aip;
|
||||
|
||||
bool delete_me;
|
||||
|
@ -222,6 +222,7 @@ private:
|
|||
int _refID;
|
||||
object_type _otype;
|
||||
bool _initialized;
|
||||
osg::ref_ptr<osg::LOD> _model; //The 3D model LOD object
|
||||
|
||||
public:
|
||||
object_type getType();
|
||||
|
|
|
@ -43,7 +43,12 @@
|
|||
#include "AIGroundVehicle.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;
|
||||
mNumAiModels = 0;
|
||||
|
||||
|
@ -181,6 +186,18 @@ FGAIManager::update(double dt) {
|
|||
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
|
||||
FGAIManager::attach(FGAIBase *model)
|
||||
{
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
|
||||
#include <simgear/structure/subsystem_mgr.hxx>
|
||||
#include <simgear/structure/SGSharedPtr.hxx>
|
||||
#include <simgear/props/props_io.hxx>
|
||||
|
||||
#include <Main/fg_props.hxx>
|
||||
|
||||
|
@ -66,6 +67,7 @@ public:
|
|||
void bind();
|
||||
void unbind();
|
||||
void update(double dt);
|
||||
void updateLOD(SGPropertyNode* node);
|
||||
void attach(FGAIBase *model);
|
||||
|
||||
void destroyObject( int ID );
|
||||
|
@ -135,6 +137,8 @@ private:
|
|||
double strength;
|
||||
void processThermal( FGAIThermal* thermal );
|
||||
|
||||
SGPropertyChangeCallback<FGAIManager> cb_ai_bare;
|
||||
SGPropertyChangeCallback<FGAIManager> cb_ai_detailed;
|
||||
};
|
||||
|
||||
#endif // _FG_AIMANAGER_HXX
|
||||
|
|
Loading…
Reference in a new issue