/***组合实体***/
{
/船舰
std::string marineID = "ship02";
osg::ref_ptr<FxSceneObject::MarineOption> marineOption = m_objectManager->createOption<FxSceneObject::MarineOption>(FxSceneObject::MARINE, marineID);
if (marineOption.valid())
{
// 通用信息设置
marineOption->position() = osg::Vec3d(125.0, 23.5, 0.0);
// 使用默认的模型和图片参数,这里就不再设置了,默认为054舰,
// 但由于图片的船头与模型的船头方向相差135°,这里需要调整图片的默认姿态
FxSceneObject::MarineGraphicOption* graphicOption = marineOption->graphicOption<FxSceneObject::MarineGraphicOption>();
graphicOption->imageOption()->attitude() = osg::Vec3(0.0, 0.0, 135.0);
graphicOption->imageOption()->visibleRange() = osg::Vec2(0, 10000);
graphicOption->modelOption()->visibleRange() = osg::Vec2(0, 10000);
graphicOption->billboardOption()->labelText() = std::string("054ship02");
graphicOption->billboardOption()->visible() = false;
// 这里使用实时数据来驱动舰船运动
marineOption->pathModelOption()->driveMode() = FxSceneObject::PathModel::E_REAL_TIME_DATA;
}
FxSceneObject::SceneObject* ship = m_objectManager->addObject(marineOption.get());
///添加飞机对象
std::string objId = "aircraft2";
// 飞行器配置项
osg::ref_ptr<FxSceneObject::AircraftOption> aircraftOption = m_objectManager->createOption<FxSceneObject::AircraftOption>(FxSceneObject::AIRCRAFT, objId);
aircraftOption->dynamic() = true;
aircraftOption->position() = osg::Vec3d(125.0, 23.5,20);
aircraftOption->attitude() = osg::Vec3(0, 0, 0);
aircraftOption->visible() = true;
// 设置对象使用模型和图片参数
FxSceneObject::AircraftGraphicOption* graphicOption = aircraftOption->graphicOption<FxSceneObject::AircraftGraphicOption>();
graphicOption->modelOption()->modelPath() = FxUtil::FilePath("|:System/Models/F-22.ive");
graphicOption->imageOption()->imageSize() = osg::Vec2(64, 64);
graphicOption->imageOption()->imagePath() = FxUtil::FilePath("|:System/Images/models/F-18.png");
graphicOption->billboardOption()->visible() = false;
graphicOption->imageOption()->visible() = false;
graphicOption->billboardOption()->labelText() = std::string("aircraft2");
graphicOption->pathLineOption()->color() = osg::Vec4(0.8, 0.0, 0.7, 0.9);
graphicOption->pathLineOption()->width() = 4.f;
graphicOption->pathLineOption()->visible() = true;
graphicOption->modelOption()->autoScaleRadio() = 5.0;
graphicOption->modelOption()->visibleRange() = osg::Vec2(0.0, 100000.0);
graphicOption->imageOption()->visibleRange() = osg::Vec2(0.0, 100000.0);
// 这里使用实时数据来驱动飞行器运动
aircraftOption->pathModelOption()->driveMode() = FxSceneObject::PathModel::E_REAL_TIME_DATA;
FxSceneObject::SceneObject* aircraft = m_objectManager->addObject(aircraftOption.get());
// 组合实体
std::string combinationOptionId = "combinationOption";
// 组合实体配置项
osg::ref_ptr<FxSceneObject::CombinationOption> combinationOption = m_objectManager->createOption<FxSceneObject::CombinationOption>(FxSceneObject::COMBINATION, combinationOptionId);
combinationOption->dynamic() = true;
combinationOption->position() = osg::Vec3d(125.0, 23.5, .0);
combinationOption->attitude() = osg::Vec3(0, 0, 0);
combinationOption->visible() = true;
combinationOption->pathModelOption()->driveMode() = FxSceneObject::PathModel::E_REAL_TIME_DATA;
FxSceneObject::CombinationGraphicOption* combinationGraphicOption = aircraftOption->graphicOption<FxSceneObject::CombinationGraphicOption>();
combinationGraphicOption->billboardOption()->visible() = true;
combinationGraphicOption->billboardOption()->labelText() = std::string("Timi");
combinationGraphicOption->imageOption()->imageSize() = osg::Vec2(64, 64);
combinationGraphicOption->imageOption()->imagePath() = FxUtil::FilePath("|:System/Images/models/054.png");
combinationGraphicOption->imageOption()->visibleRange() = osg::Vec2(0.0, 5000000.0);
std::vector<FxSceneObject::CombinationOption::AttachSceneObjectID> m_vector;
m_vector.push_back("aircraft2");
std::map<FxSceneObject::CombinationOption::ParentSceneObjectID, std::vector<FxSceneObject::CombinationOption::AttachSceneObjectID>> m_map;
m_map.insert(std::pair<FxSceneObject::CombinationOption::ParentSceneObjectID, std::vector<FxSceneObject::CombinationOption::AttachSceneObjectID>>("ship02", m_vector));
combinationOption->attachMap() = m_map;
FxSceneObject::SceneObject* combination = m_objectManager->addObject(combinationOption.get());
}
Chapter 1 组合实体
最新推荐文章于 2024-11-12 15:18:48 发布