1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-27 16:54:15 +01:00

LP-29 fix osg attitude handling issue when pitch close to +/-90 (thank you @liftbag for reporting it)

This commit is contained in:
Philippe Renon 2016-02-17 22:55:20 +01:00
parent 96ed1e40ba
commit bdb42246e8
4 changed files with 25 additions and 18 deletions

View File

@ -252,7 +252,7 @@ public:
// disable any installed camera manipulator // disable any installed camera manipulator
// TODO create and use own camera manipulator to avoid disabling ON_DEMAND frame update scheme // TODO create and use own camera manipulator to avoid disabling ON_DEMAND frame update scheme
// see https://github.com/gwaldron/osgearth/commit/796daf4792ccaf18ae7eb6a5cb268eef0d42888d // see https://github.com/gwaldron/osgearth/commit/796daf4792ccaf18ae7eb6a5cb268eef0d42888d
// TODO see StandardManaipulator for example on how to react to events (tohabd FOV changes without the need for an update callback?) // TODO see StandardManipulator for an example on how to react to events (to have FOV changes without the need for an update callback?)
cm = NULL; cm = NULL;
break; break;
case ManipulatorMode::Earth: case ManipulatorMode::Earth:
@ -331,23 +331,24 @@ public:
} }
fovDirty = false; fovDirty = false;
// qDebug() << "OSGCamera::updateCameraFOV"; qDebug() << "OSGCamera::updateCameraFOV" << fieldOfView;
double fovy, ar, zn, zf; double fovy, ar, zn, zf;
camera->getProjectionMatrixAsPerspective(fovy, ar, zn, zf); camera->getProjectionMatrixAsPerspective(fovy, ar, zn, zf);
fovy = fieldOfView; fovy = fieldOfView;
camera->setProjectionMatrixAsPerspective(fovy, ar, zn, zf); camera->setProjectionMatrixAsPerspective(fovy, ar, zn, zf);
} }
void updateAspectRatio() void updateAspectRatio()
{ {
double fovy, ar, zn, zf;
camera->getProjectionMatrixAsPerspective(fovy, ar, zn, zf);
osg::Viewport *viewport = camera->getViewport(); osg::Viewport *viewport = camera->getViewport();
ar = static_cast<double>(viewport->width()) / static_cast<double>(viewport->height()); double aspectRatio = static_cast<double>(viewport->width()) / static_cast<double>(viewport->height());
qDebug() << "OSGCamera::updateAspectRatio" << aspectRatio;
double fovy, ar, zn, zf;
camera->getProjectionMatrixAsPerspective(fovy, ar, zn, zf);
ar = aspectRatio;
camera->setProjectionMatrixAsPerspective(fovy, ar, zn, zf); camera->setProjectionMatrixAsPerspective(fovy, ar, zn, zf);
} }
@ -392,10 +393,13 @@ public:
osg::DegreesToRadians(0.0), osg::Vec3(0.0, 0.0, 1.0)); osg::DegreesToRadians(0.0), osg::Vec3(0.0, 0.0, 1.0));
// Final camera matrix // Final camera matrix
double roll = osg::DegreesToRadians(attitude.x());
double pitch = osg::DegreesToRadians(attitude.y());
double yaw = osg::DegreesToRadians(attitude.z());
osg::Matrix cameraMatrix = cameraRotation osg::Matrix cameraMatrix = cameraRotation
* osg::Matrix::rotate(osg::DegreesToRadians(attitude.x()), osg::Vec3(1.0, 0.0, 0.0)) * osg::Matrix::rotate(roll, osg::Vec3(0, 1, 0))
* osg::Matrix::rotate(osg::DegreesToRadians(attitude.y()), osg::Vec3(0.0, 1.0, 0.0)) * osg::Matrix::rotate(pitch, osg::Vec3(1, 0, 0))
* osg::Matrix::rotate(osg::DegreesToRadians(attitude.z()), osg::Vec3(0.0, 0.0, 1.0)) * cameraPosition; * osg::Matrix::rotate(yaw, osg::Vec3(0, 0, -1.0)) * cameraPosition;
// Inverse the camera's position and orientation matrix to obtain the view matrix // Inverse the camera's position and orientation matrix to obtain the view matrix
cameraMatrix = osg::Matrix::inverse(cameraMatrix); cameraMatrix = osg::Matrix::inverse(cameraMatrix);

View File

@ -194,10 +194,13 @@ public:
osg::Quat localRotation() osg::Quat localRotation()
{ {
double roll = osg::DegreesToRadians(attitude.x());
double pitch = osg::DegreesToRadians(attitude.y());
double yaw = osg::DegreesToRadians(attitude.z());
osg::Quat q = osg::Quat( osg::Quat q = osg::Quat(
osg::DegreesToRadians(attitude.x()), osg::Vec3d(1, 0, 0), roll, osg::Vec3d(0, 1, 0),
osg::DegreesToRadians(attitude.y()), osg::Vec3d(0, 1, 0), pitch, osg::Vec3d(1, 0, 0),
osg::DegreesToRadians(attitude.z()), osg::Vec3d(0, 0, 1)); yaw, osg::Vec3d(0, 0, -1));
return q; return q;
} }

View File

@ -147,7 +147,7 @@ void OsgEarth::initializeCache()
} else { } else {
qWarning() << "OsgEarth::initializeCache - Failed to initialize cache"; qWarning() << "OsgEarth::initializeCache - Failed to initialize cache";
} }
#endif #endif // ifdef USE_OSGEARTH
} }
void OsgEarth::displayInfo() void OsgEarth::displayInfo()

View File

@ -81,7 +81,7 @@ Qt.include("common.js")
*/ */
function attitude() { function attitude() {
return Qt.vector3d(attitudeState.pitch, attitudeState.roll, -attitudeState.yaw); return Qt.vector3d(attitudeState.roll, attitudeState.pitch, attitudeState.yaw);
} }
function attitudeRoll() { function attitudeRoll() {