Adding option for constant velocity flight (closes #2150)

Using adapted code from James H
This commit is contained in:
Alexander Bock
2023-03-11 00:16:54 +01:00
parent ffbcdbea48
commit 6fa589c880
2 changed files with 28 additions and 4 deletions

View File

@@ -214,6 +214,14 @@ namespace {
"UseAdaptiveStereoscopicDepthInfo is set to true"
};
constexpr openspace::properties::Property::PropertyInfo ConstantVelocityFlight = {
"ConstantVelocityFlight",
"Constant Velocitry Flight",
"If this value is enabled, the camera motion will not be affected by the "
"distance of the camera to the surface of a planet. When enabling this setting "
"consider adjusting the mouse sensitivity to a lower value"
};
constexpr openspace::properties::Property::PropertyInfo ApplyIdleBehaviorInfo = {
"ApplyIdleBehavior",
"Apply Idle Behavior",
@@ -356,6 +364,7 @@ OrbitalNavigator::OrbitalNavigator()
500000
)
, _staticViewScaleExponent(StaticViewScaleExponentInfo, 0.f, -30, 10)
, _constantVelocityFlight(ConstantVelocityFlight, false)
, _retargetInterpolationTime(RetargetInterpolationTimeInfo, 2.0, 0.0, 10.0)
, _stereoInterpolationTime(StereoInterpolationTimeInfo, 8.0, 0.0, 10.0)
, _followRotationInterpolationTime(FollowRotationInterpTimeInfo, 1.0, 0.0, 10.0)
@@ -515,6 +524,7 @@ OrbitalNavigator::OrbitalNavigator()
addProperty(_useAdaptiveStereoscopicDepth);
addProperty(_staticViewScaleExponent);
addProperty(_constantVelocityFlight);
_stereoscopicDepthOfFocusSurface.setExponent(3.f);
addProperty(_stereoscopicDepthOfFocusSurface);
@@ -1370,16 +1380,28 @@ glm::dvec3 OrbitalNavigator::translateHorizontally(double deltaTime,
positionHandle.centerToReferenceSurface +
positionHandle.referenceSurfaceOutDirection * positionHandle.heightToSurface;
const glm::dvec3 centerToActualSurface = glm::dmat3(modelTransform) *
centerToActualSurfaceModelSpace;
const glm::dvec3 centerToActualSurface =
glm::dmat3(modelTransform) * centerToActualSurfaceModelSpace;
const glm::dvec3 actualSurfaceToCamera = posDiff - centerToActualSurface;
const double distFromSurfaceToCamera = glm::length(actualSurfaceToCamera);
const double distFromSurfaceToCamera = [&]() {
if (_constantVelocityFlight) {
const glm::dvec3 centerToRefSurface =
glm::dmat3(modelTransform) * positionHandle.centerToReferenceSurface;
const glm::dvec3 refSurfaceToCamera = posDiff - centerToRefSurface;
return glm::length(refSurfaceToCamera);
}
else {
return glm::length(actualSurfaceToCamera);
}
}();
// Final values to be used
const double distFromCenterToSurface = glm::length(centerToActualSurface);
const double distFromCenterToCamera = glm::length(posDiff);
const double speedScale =
double speedScale =
distFromCenterToSurface > 0.0 ?
glm::clamp(distFromSurfaceToCamera / distFromCenterToSurface, 0.0, 1.0) :
1.0;