diff --git a/src/entities/SceneComponent.cpp b/src/entities/SceneComponent.cpp index 7dcbd70f..e20a2e34 100644 --- a/src/entities/SceneComponent.cpp +++ b/src/entities/SceneComponent.cpp @@ -191,6 +191,10 @@ void SceneComponent::UpdateLocationAndRotation() { const osg::Vec3& s = transform_.GetScale(); const osg::Vec3& t = transform_.GetLocation(); osg::Quat quat = OsgUtils::HPRToQuat(r); + + //osg::Vec3 angle; + //OsgUtils::QuatToHPR(quat, &angle); + osg::Matrix matrix = osg::Matrix::scale(s) * osg::Matrix::rotate(quat); if (!geo_.valid()) { matrix *= osg::Matrix::translate(t); diff --git a/src/utils/OsgUtils.cpp b/src/utils/OsgUtils.cpp index f7195769..7f1faa5b 100644 --- a/src/utils/OsgUtils.cpp +++ b/src/utils/OsgUtils.cpp @@ -7,9 +7,9 @@ osg::Quat OsgUtils::HPRToQuat(const osg::Vec3& angle) { osg::Quat q( - osg::inDegrees(angle.y()), osg::Vec3d(0.0, 1.0, 0.0), - osg::inDegrees(angle.x()), osg::Vec3d(1.0, 0.0, 0.0), - osg::inDegrees(angle.z()), osg::Vec3d(0.0, 0.0, 1.0)); + osg::inDegrees(angle.x()), osg::Vec3d(0.0, 1.0, 0.0), + osg::inDegrees(angle.y()), osg::Vec3d(1.0, 0.0, 0.0), + osg::inDegrees(-angle.z()), osg::Vec3d(0.0, 0.0, 1.0)); return q; } @@ -34,9 +34,9 @@ void OsgUtils::QuatToHPR(const osg::Quat& q, osg::Vec3* angle) { double sqy = q.y() * q.y(); double sqz = q.z() * q.z(); heading = atan2(2.0 * q.z() * q.w() - 2.0 * q.y() * q.x(), 1.0 - 2.0 * sqz - 2.0 * sqx); - pitch = asin(2.0 * test); - roll = atan2(2.0 * q.y() * q.w() - 2.0 * q.z() * q.x(), 1.0 - 2.0 * sqy - 2.0 * sqx); - angle->set(osg::RadiansToDegrees(pitch), osg::RadiansToDegrees(roll), osg::RadiansToDegrees(heading)); + roll = asin(2.0 * test); + pitch = atan2(2.0 * q.y() * q.w() - 2.0 * q.z() * q.x(), 1.0 - 2.0 * sqy - 2.0 * sqx); + angle->set(osg::RadiansToDegrees(pitch), osg::RadiansToDegrees(roll), -osg::RadiansToDegrees(heading)); } void OsgUtils::Vec4ToQColor(const osg::Vec4& vec, QColor* color) {