/
wmigor
/
z-plane
Обзор
Документация
Войти
/
wmigor
/
z-plane
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
app/src/AircraftGizmo.cpp
155 строк
5 KB
wmigor
Добавлена простая физика жесткого тела RigidBody для отладки полета
27 май 2026, 09:43
Верифицирован
27 май 2026, 09:43
3b37c0b
Код
Авторство
О чём код?
#include "AircraftGizmo.h" #include "converters.h" #include <asim/Constants.h> #include <glm/gtx/rotate_vector.hpp> #include <osg/Geometry> using namespace asim; AircraftGizmo::AircraftGizmo(Aircraft *aircraft): osg::Geode(), _aircraft(aircraft) { auto vertices = new osg::Vec3Array(); auto colors = new osg::Vec4Array(); addAxles(5.0, 5.0, 5.0, vertices, colors); for (const auto wing : _aircraft->getPhysics()->getWings()) addWing(wing, vertices, colors, true); auto geometry = new osg::Geometry(); geometry->setVertexArray(vertices); geometry->setColorArray(colors); geometry->setColorBinding(osg::Geometry::BIND_PER_VERTEX); geometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES, 0, vertices->size())); getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF); addDrawable(geometry); } void AircraftGizmo::addWing( const asim::Wing *wing, osg::Vec3Array *vertices, osg::Vec4Array *colors, bool withMac) { auto offset = -wing->getMeanChordForwardPosition() * Constants::Forward; for (const auto &wingSection : wing->getSections()) { if (!wingSection.isValid()) { continue; } auto wingColor = osg::Vec4d(1.0, 1.0, 1.0, 1.0); auto focusColor = osg::Vec4d(1.0, 0.0, 1.0, 1.0); auto startCount = vertices->size(); addPoint(toVec3(offset + getWingPoint(wingSection, 0.0, -0.75)), wingColor, vertices, colors); addPoint(toVec3(offset + getWingPoint(wingSection, 0.0, 0.25)), wingColor, vertices, colors); addPoint(vertices->at(vertices->size() - 1), wingColor, vertices, colors); addPoint(toVec3(offset + getWingPoint(wingSection, 1.0, 0.25)), wingColor, vertices, colors); addPoint(vertices->at(vertices->size() - 1), wingColor, vertices, colors); addPoint(toVec3(offset + getWingPoint(wingSection, 1.0, -0.75)), wingColor, vertices, colors); addPoint(vertices->at(vertices->size() - 1), wingColor, vertices, colors); addPoint(vertices->at(startCount), wingColor, vertices, colors); addPoint(toVec3(offset + getWingPoint(wingSection, 0.0, 0.0)), focusColor, vertices, colors); addPoint(toVec3(offset + getWingPoint(wingSection, 1.0, 0.0)), focusColor, vertices, colors); if (withMac) { auto macColor = osg::Vec4d(1.0, 1.0, 0.0, 1.0); auto mac = wingSection.getMeanChord(); auto macPosition = wingSection.getMeanChordPosition(); auto macFraction = wingSection.getMeanChordForwardPosition() / mac; auto macRotation = wingSection.getRotation(macFraction); addPoint(toVec3(offset + macPosition - macRotation * Constants::Forward * mac * 0.75), macColor, vertices, colors); addPoint(toVec3(offset + macPosition + macRotation * Constants::Forward * mac * 0.25), macColor, vertices, colors); addPoint(toVec3(offset + macPosition - (Constants::Right + Constants::Up) * 0.1), focusColor, vertices, colors); addPoint(toVec3(offset + macPosition + (Constants::Right + Constants::Up) * 0.1), focusColor, vertices, colors); addPoint(toVec3(offset + macPosition - (Constants::Right - Constants::Up) * 0.1), focusColor, vertices, colors); addPoint(toVec3(offset + macPosition + (Constants::Right - Constants::Up) * 0.1), focusColor, vertices, colors); } if (!wingSection.mirror) continue; auto count = vertices->size(); for (auto i = startCount; i < count; i++) { auto vertex = vertices->at(i); auto point = glm::dvec3(vertex.x(), vertex.y(), vertex.z()); addPoint(toVec3(glm::reflect(point, Constants::Right)), colors->at(i), vertices, colors); } } } glm::dvec3 AircraftGizmo::getWingPoint( const asim::WingSection &wingSection, double spanFraction, double chordFraction) { auto point = wingSection.getPosition(spanFraction); auto incidence = wingSection.getTwist(spanFraction); auto twistDir = glm::rotate(Constants::Forward, incidence, Constants::Right); auto chord = wingSection.getChord(spanFraction); point += twistDir * chord * chordFraction; return point; } void AircraftGizmo::addAxles( double forwardSize, double rightSize, double upSize, osg::Vec3Array *vertices, osg::Vec4Array *colors) { addLine( toVec3(0.5 * Constants::Forward * forwardSize), toVec3(-0.5 * Constants::Forward * forwardSize), osg::Vec4d(0.0, 1.0, 1.0, 1.0), vertices, colors); addLine( toVec3(0.5 * Constants::Right * rightSize), toVec3(-0.5 * Constants::Right * rightSize), osg::Vec4d(1.0, 0.0, 0.0, 1.0), vertices, colors); addLine( toVec3(0.5 * Constants::Up * upSize), toVec3(-0.5 * Constants::Up * upSize), osg::Vec4d(0.0, 1.0, 0.0, 1.0), vertices, colors); } void AircraftGizmo::addPoint( const osg::Vec3d &point, const osg::Vec4d &color, osg::Vec3Array *vertices, osg::Vec4Array *colors) { vertices->push_back(point); colors->push_back(color); } void AircraftGizmo::addLine( const osg::Vec3d &point1, const osg::Vec3d &point2, const osg::Vec4d &color, osg::Vec3Array *vertices, osg::Vec4Array *colors) { vertices->push_back(point1); vertices->push_back(point2); colors->push_back(color); colors->push_back(color); }