/
wmigor
/
z-plane
Обзор
Документация
Войти
/
wmigor
/
z-plane
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
app/src/main.cpp
100 строк
3 KB
wmigor
сохранение/загрузка
11 часов назад
11 часов назад
81be381
Код
Авторство
О чём код?
#include <osgViewer/Viewer> #include <osg/Geode> #include <osg/ShapeDrawable> #include <osg/Light> #include <osgGA/GUIEventHandler> #include <asimio/AircraftIo.h> #include "AircraftDebugView.h" // #include "aircrafts.h" #include "AirfoilPlot.h" #include "Simulation.h" #include "AircraftCameraManipulator.h" #include "PlayerAircraftInput.h" #include "Grid.h" #include "Hud.h" #include "Ground.h" using namespace asim; class DebugViewModeSwitcher: public osgGA::GUIEventHandler { public: DebugViewModeSwitcher(AircraftDebugView *aircraftDebugView): _aircraftDebugView(aircraftDebugView) {} virtual bool handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &) override { if (ea.getEventType() == osgGA::GUIEventAdapter::KEYDOWN && ea.getKey() == osgGA::GUIEventAdapter::KEY_F1) { _aircraftDebugView->switchMode(); return true; } return false; } private: osg::ref_ptr<AircraftDebugView> _aircraftDebugView; }; void setCameraFov(osg::Camera *camera, double fov, double near, double far) { double currentFov, aspectRatio, currentNear, currentFar; if (camera->getProjectionMatrixAsPerspective(currentFov, aspectRatio, currentNear, currentFar)) { camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR); camera->setProjectionMatrixAsPerspective(fov, aspectRatio, near, far); } } osg::LightSource *createLight() { auto light = new osg::Light(); light ->setLightNum(0); light ->setPosition(osg::Vec4(0.0, 1.0, 0.0, 0.0)); light ->setDiffuse(osg::Vec4(1.0, 1.0, 1.0, 1.0)); light ->setAmbient(osg::Vec4(0.2, 0.2, 0.2, 1.0)); light ->setDirection(osg::Vec3d(0.0, -1.0, 0.0)); auto source = new osg::LightSource(); source->setLight(light); source->setLocalStateSetModes(osg::StateAttribute::ON); return source; } int main() { osgViewer::Viewer viewer; viewer.setUpViewInWindow(100, 100, 1280, 720); // auto tmpAircraft = createC172(); // asimio::AircraftIo::save("c172.yaml", tmpAircraft->getPhysics()); auto aircraft = new Aircraft(asimio::AircraftIo::load("data/c172.yaml")); aircraft->getBody()->position.y = 2.0; auto aircraftDebugView = new AircraftDebugView(aircraft); auto simulation = new Simulation(60); simulation->addAircraft(aircraft); auto root = new osg::Group(); root->addUpdateCallback(simulation); root->addChild(aircraftDebugView); root->addChild(new Hud(aircraft)); root->addChild(new Ground(aircraftDebugView)); root->addChild(new Grid(aircraft, 100.0, 8, 1.0)); root->addChild(createLight()); viewer.setSceneData(root); viewer.addEventHandler(new DebugViewModeSwitcher(aircraftDebugView)); viewer.addEventHandler(new PlayerAircraftInput(aircraft)); viewer.setCameraManipulator(new AircraftCameraManipulator(aircraft)); setCameraFov(viewer.getCamera(), 75.0, 0.5, 10000.0); plotAirfoil(); return viewer.run(); }