diff --git a/modules/autonavigation/path.cpp b/modules/autonavigation/path.cpp index 5da1b4ea3e..b466ac9cfe 100644 --- a/modules/autonavigation/path.cpp +++ b/modules/autonavigation/path.cpp @@ -114,22 +114,22 @@ double Path::speedAtTime(double time) const { } CameraPose Path::interpolatedPose(double distance) const { - double u = distance / pathLength(); + const double relativeDistance = distance / pathLength(); CameraPose cs; - cs.position = _curve->positionAt(u); - cs.rotation = interpolateRotation(u); + cs.position = _curve->positionAt(distance); + cs.rotation = interpolateRotation(relativeDistance); return cs; } -glm::dquat Path::interpolateRotation(double u) const { +glm::dquat Path::interpolateRotation(double t) const { switch (_curveType) { case CurveType::AvoidCollision: case CurveType::Linear: - return interpolation::easedSlerp(_start.rotation(), _end.rotation(), u); + return interpolation::easedSlerp(_start.rotation(), _end.rotation(), t); case CurveType::ZoomOutOverview: { - const double u1 = 0.2; - const double u2 = 0.8; + const double t1 = 0.2; + const double t2 = 0.8; const glm::dvec3 startPos = _curve->positionAt(0.0); const glm::dvec3 endPos = _curve->positionAt(1.0); @@ -137,39 +137,39 @@ glm::dquat Path::interpolateRotation(double u) const { const glm::dvec3 endNodePos = _end.node()->worldPosition(); glm::dvec3 lookAtPos; - if (u < u1) { + if (t < t1) { // Compute a position in front of the camera at the start orientation const double inFrontDistance = glm::distance(startPos, startNodePos); const glm::dvec3 viewDir = helpers::viewDirection(_start.rotation()); const glm::dvec3 inFrontOfStart = startPos + inFrontDistance * viewDir; - double uScaled = ghoul::cubicEaseInOut(u / u1); + const double tScaled = ghoul::cubicEaseInOut(t / t1); lookAtPos = - ghoul::interpolateLinear(uScaled, inFrontOfStart, startNodePos); + ghoul::interpolateLinear(tScaled, inFrontOfStart, startNodePos); } - else if (u <= u2) { - double uScaled = ghoul::cubicEaseInOut((u - u1) / (u2 - u1)); - lookAtPos = ghoul::interpolateLinear(uScaled, startNodePos, endNodePos); + else if (t <= t2) { + const double tScaled = ghoul::cubicEaseInOut((t - t1) / (t2 - t1)); + lookAtPos = ghoul::interpolateLinear(tScaled, startNodePos, endNodePos); } - else if (u2 < u) { + else if (t2 < t) { // Compute a position in front of the camera at the end orientation const double inFrontDistance = glm::distance(endPos, endNodePos); const glm::dvec3 viewDir = helpers::viewDirection(_end.rotation()); const glm::dvec3 inFrontOfEnd = endPos + inFrontDistance * viewDir; - double uScaled = ghoul::cubicEaseInOut((u - u2) / (1.0 - u2)); - lookAtPos = ghoul::interpolateLinear(uScaled, endNodePos, inFrontOfEnd); + const double tScaled = ghoul::cubicEaseInOut((t - t2) / (1.0 - t2)); + lookAtPos = ghoul::interpolateLinear(tScaled, endNodePos, inFrontOfEnd); } // Handle up vector separately glm::dvec3 startUp = _start.rotation() * glm::dvec3(0.0, 1.0, 0.0); glm::dvec3 endUp = _end.rotation() * glm::dvec3(0.0, 1.0, 0.0); - double uUp = helpers::shiftAndScale(u, u1, u2); - uUp = ghoul::sineEaseInOut(uUp); - glm::dvec3 up = ghoul::interpolateLinear(uUp, startUp, endUp); + double tUp = helpers::shiftAndScale(t, t1, t2); + tUp = ghoul::sineEaseInOut(tUp); + glm::dvec3 up = ghoul::interpolateLinear(tUp, startUp, endUp); - return helpers::lookAtQuaternion(_curve->positionAt(u), lookAtPos, up); + return helpers::lookAtQuaternion(_curve->positionAt(t), lookAtPos, up); } default: throw ghoul::MissingCaseException(); diff --git a/modules/autonavigation/pathcurve.cpp b/modules/autonavigation/pathcurve.cpp index fbcd96bc19..1a4a802583 100644 --- a/modules/autonavigation/pathcurve.cpp +++ b/modules/autonavigation/pathcurve.cpp @@ -45,8 +45,8 @@ const double PathCurve::length() const { return _totalLength; } -glm::dvec3 PathCurve::positionAt(double relativeLength) { - double u = curveParameter(relativeLength * _totalLength); +glm::dvec3 PathCurve::positionAt(double length) { + const double u = curveParameter(length); return interpolate(u); } @@ -58,7 +58,7 @@ double PathCurve::curveParameter(double s) { if (s >= _totalLength) return 1.0; unsigned int segmentIndex = 1; - while (s > _arcLengthSums[segmentIndex]) { + while (s > _lengthSums[segmentIndex]) { segmentIndex++; } @@ -93,7 +93,7 @@ void PathCurve::initializeParameterData() { ghoul_assert(_nSegments > 0, "Cannot have a curve with zero segments!"); _curveParameterSteps.clear(); - _arcLengthSums.clear(); + _lengthSums.clear(); _parameterSamples.clear(); // Evenly space out parameter intervals @@ -106,22 +106,22 @@ void PathCurve::initializeParameterData() { _curveParameterSteps.push_back(1.0); // Arc lengths - _arcLengthSums.reserve(_nSegments + 1); - _arcLengthSums.push_back(0.0); + _lengthSums.reserve(_nSegments + 1); + _lengthSums.push_back(0.0); for (unsigned int i = 1; i <= _nSegments; i++) { double u = _curveParameterSteps[i]; double uPrev = _curveParameterSteps[i - 1]; double length = arcLength(uPrev, u); - _arcLengthSums.push_back(_arcLengthSums[i - 1] + length); + _lengthSums.push_back(_lengthSums[i - 1] + length); } - _totalLength = _arcLengthSums.back(); + _totalLength = _lengthSums.back(); // Compute a map of arc lengths s and curve parameters u, for reparameterization _parameterSamples.reserve(NrSamplesPerSegment * _nSegments + 1); const double uStep = 1.0 / (_nSegments * NrSamplesPerSegment); for (unsigned int i = 0; i < _nSegments; i++) { double uStart = _curveParameterSteps[i]; - double sStart = _arcLengthSums[i]; + double sStart = _lengthSums[i]; for (int j = 0; j < NrSamplesPerSegment; ++j) { double u = uStart + j * uStep; double s = sStart + arcLength(uStart, u); diff --git a/modules/autonavigation/pathcurve.h b/modules/autonavigation/pathcurve.h index 22d5bc8a8c..2b8ffc923a 100644 --- a/modules/autonavigation/pathcurve.h +++ b/modules/autonavigation/pathcurve.h @@ -36,7 +36,7 @@ public: virtual ~PathCurve() = 0; const double length() const; - glm::dvec3 positionAt(double relativeLength); + glm::dvec3 positionAt(double length); // Compute curve parameter u that matches the input arc length s double curveParameter(double s); @@ -58,7 +58,7 @@ protected: unsigned int _nSegments; std::vector _curveParameterSteps; // per segment - std::vector _arcLengthSums; // per segment + std::vector _lengthSums; // per segment double _totalLength; struct ParameterPair {