/
wmigor
/
z-plane
Обзор
Документация
Войти
/
wmigor
/
z-plane
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
app/src/AircraftCameraManipulator.cpp
74 строки
2 KB
wmigor
Плавное управление мышкой
04 июн 2026, 23:00
Верифицирован
04 июн 2026, 23:00
43aa585
Код
Авторство
О чём код?
#include "AircraftCameraManipulator.h" #include <glm/gtx/rotate_vector.hpp> #include "converters.h" #include <asim/Constants.h> bool AircraftCameraManipulator::handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &) { switch (ea.getEventType()) { case osgGA::GUIEventAdapter::FRAME: updateMatrix(); return true; case osgGA::GUIEventAdapter::PUSH: _mouseX = ea.getX(); _mouseY = ea.getY(); return true; case osgGA::GUIEventAdapter::DRAG: return handleDrag(ea); case osgGA::GUIEventAdapter::KEYDOWN: return handleKeyDown(ea); default: return false; } } void AircraftCameraManipulator::updateMatrix() { auto body = _aircraft->getBody(); auto position = body->getMassCenterGlobal(); auto rotation = body->rotation; auto forward = rotation * asim::Constants::Forward; auto right = rotation * asim::Constants::Right; auto up = glm::cross(right, forward); auto eye = position - forward * 7.0 - body->linearVelocity * 0.1 + up * 3.0; auto cameraRotation = glm::angleAxis(_cameraYaw, up) * glm::angleAxis(_cameraPitch, right); auto direction = cameraRotation * (eye - position); eye = position + direction; if (eye.y < 0.35) eye.y = 0.35; up = glm::cross(direction, cameraRotation * right); _matrix.makeLookAt(toVec3(eye), toVec3(position), toVec3(up)); } bool AircraftCameraManipulator::handleDrag(const osgGA::GUIEventAdapter& ea) { if (!(ea.getButtonMask() & osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON)) return false; _cameraYaw -= (ea.getX() - _mouseX) / 180.0; _cameraPitch += (ea.getY() - _mouseY) / 180.0; _mouseX = ea.getX(); _mouseY = ea.getY(); return true; } bool AircraftCameraManipulator::handleKeyDown(const osgGA::GUIEventAdapter &ea) { switch (ea.getKey()) { case osgGA::GUIEventAdapter::KEY_C: _mouseX = ea.getX(); _mouseY = ea.getY(); _cameraPitch = 0.0; _cameraYaw = 0.0; return true; default: return false; } }