Interpolate back to look at target at the end of a path

This commit is contained in:
Emma Broman
2021-11-19 08:11:47 +01:00
parent 85416e0cf9
commit 51bd416fd0
3 changed files with 23 additions and 1 deletions

View File

@@ -62,6 +62,12 @@ public:
*/
double pathLength() const;
/**
* Return the remaining distance for the path, that is the path length
* minus the travelled distance, in meters
*/
double remainingDistance() const;
/**
* Return a vector of positions corresponding to the control points of the path's
* spline curve

View File

@@ -132,6 +132,8 @@ Waypoint Path::endPoint() const { return _end; }
double Path::pathLength() const { return _curve->length(); }
double Path::remainingDistance() const { return _curve->length() - _traveledDistance; }
std::vector<glm::dvec3> Path::controlPoints() const {
return _curve->points();
}

View File

@@ -417,8 +417,22 @@ void PathNavigator::findRelevantNodes() {
void PathNavigator::applyLocalRotationFromInput(CameraPose& pose, double deltaTime) {
const constexpr float maxAngle = glm::radians(30.f);
double almostArrivedDistance = 8.0 * _currentPath->endPoint().validBoundingSphere();
double remainingDistance = _currentPath->remainingDistance();
if (remainingDistance < almostArrivedDistance) {
// Interpolate back to the view the camera path wants and ignore any further input
double t = 1.0;
if (remainingDistance > 0.0) {
double clampedRemaining = std::clamp(remainingDistance, 0.0001, almostArrivedDistance);
t = 1.0 - std::log(clampedRemaining) / std::log(almostArrivedDistance);
t = ghoul::cubicEaseInOut(t);
}
pose.rotation = glm::mix(camera()->rotationQuaternion(), pose.rotation, t);
return;
}
glm::dvec2 velocity = _mouseStates.globalRotationVelocity();
float rollVelocity = 0.1f * _mouseStates.globalRollVelocity().x; // TODO: move this factor somewhere else?
// TODO (emmbr, 2021-11-17) It's really ugly ot depend on the orbital navigator's