/
wmigor
/
z-plane
Обзор
Документация
Войти
/
wmigor
/
z-plane
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
app/src/Aircraft.cpp
74 строки
2 KB
wmigor
сохранение/загрузка
8 часов назад
8 часов назад
81be381
Код
Авторство
О чём код?
#include "Aircraft.h" #include "Wheel.h" #include <osg/MatrixTransform> #include <osg/Camera> #include "converters.h" Aircraft::Aircraft(asim::AircraftPhysics* physics): _physics(physics) { _body = new RigidBody(); _body->setMass(_physics->mass); _body->setInertia(_physics->inertia); _body->setMassCenter(_physics->massCenter); for (const auto &wheel : physics->getWheels()) { ::Wheel::Config config; config.position = wheel.position; config.radius = wheel.radius; config.maxAngle = wheel.maxAngle; config.stiffness = 60000.0; config.damping = 6000.0; _body->addForce(new ::Wheel(&input, config)); } for (auto wing : _physics->getWings()) { const auto §ions = wing->getSections(); if (sections.empty()) continue; const auto §ion = sections[sections.size() - 1]; auto point = section.getPosition(1.0); _body->addContactPoint(point, 0.1); if (section.mirror) _body->addContactPoint(glm::reflect(point, asim::Constants::Right), 0.1); } for (auto thruster : _physics->getThrusters()) _body->addContactPoint(thruster->position, 0.1); } Aircraft::~Aircraft() { delete _physics; } void Aircraft::update(double delta) { auto rotation = _body->rotation; auto localMassCenter = _body->getMassCenter(); auto density = 1.225; auto wrench = _physics->calculate(delta, input, _body->linearVelocity, _body->angularVelocity, localMassCenter, rotation, density); _body->applyForce(wrench.force); _body->applyTorque(wrench.torque); _body->update(delta); } void Aircraft::operator()(osg::Node *node, osg::NodeVisitor *nv) { auto transform = dynamic_cast<osg::MatrixTransform *>(node); if (transform == NULL) { traverse(node, nv); return; } osg::Matrix matrix; matrix.setRotate(toQuat(_body->rotation)); matrix.setTrans(toVec3(_body->position)); transform->setMatrix(matrix); traverse(node, nv); }