mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-03-15 10:09:48 -05:00
Minor refactor
This commit is contained in:
@@ -133,7 +133,6 @@ void AutoNavigationHandler::createPath(PathSpecification& spec) {
|
||||
break;
|
||||
}
|
||||
|
||||
// OBS! Would it be better to save the spec in the handler class?
|
||||
_stopAtTargets = spec.stopAtTargets();
|
||||
|
||||
// Check if we have a specified start navigation state. If so, update first segment
|
||||
@@ -389,8 +388,7 @@ void AutoNavigationHandler::addPause(std::optional<double> duration) {
|
||||
_pathSegments.push_back(std::unique_ptr<PathSegment>(new PathSegment(segment)));
|
||||
}
|
||||
|
||||
void AutoNavigationHandler::addSegment(Waypoint& waypoint, std::optional<double> duration) {
|
||||
|
||||
void AutoNavigationHandler::addSegment(Waypoint& waypoint, std::optional<double> duration){
|
||||
// TODO: Improve how curve types are handled
|
||||
const int curveType = _defaultCurveOption;
|
||||
|
||||
|
||||
@@ -91,4 +91,4 @@ private:
|
||||
|
||||
} // namespace openspace::autonavigation
|
||||
|
||||
#endif // __OPENSPACE_CORE___NAVIGATIONHANDLER___H__
|
||||
#endif // __OPENSPACE_MODULE___AUTONAVIGATIONHANDLER___H__
|
||||
|
||||
@@ -79,7 +79,6 @@ std::vector<glm::dvec3> PathCurve::getPoints() {
|
||||
}
|
||||
|
||||
Bezier3Curve::Bezier3Curve(const Waypoint& start, const Waypoint& end) {
|
||||
// default rotation interpolation
|
||||
_rotationInterpolator = RotationInterpolator{ start, end, this, LookAt };
|
||||
|
||||
glm::dvec3 startNodePos = start.node()->worldPosition();
|
||||
@@ -110,7 +109,6 @@ Bezier3Curve::Bezier3Curve(const Waypoint& start, const Waypoint& end) {
|
||||
// Assuming we move straigh out to point to a distance proportional to radius, angle is enough to check collision risk
|
||||
double cosStartAngle = glm::dot(startTangentDirection, startToEndDirection);
|
||||
double cosEndAngle = glm::dot(endTangentDirection, startToEndDirection);
|
||||
double cosStartDir = glm::dot(startTangentDirection, endTangentDirection);
|
||||
|
||||
//TODO: investigate suitable values, could be risky close to surface..
|
||||
bool TARGET_BEHIND_STARTNODE = cosStartAngle < -0.8;
|
||||
|
||||
@@ -80,13 +80,13 @@ CameraPose PathSegment::traversePath(double dt) {
|
||||
// In case there is an error in the speed VS distance VS duration relation,
|
||||
// make sure that we actually reach the end point.
|
||||
double displacement;
|
||||
if (_currentTime > _duration && !hasReachedEnd()) {
|
||||
if (_progressedTime > _duration && !hasReachedEnd()) {
|
||||
// TODO: reach the target in a reasonable amount of time and with smooth motion
|
||||
LWARNING("Did not reach the target in the given duration. Moving toward the target in constant speed. TODO: fix so that this does not happen"); // TODO: fix and then remove this
|
||||
displacement = dt * speedAtTime(_duration - _duration * dt);
|
||||
}
|
||||
else {
|
||||
displacement = dt * speedAtTime(_currentTime);
|
||||
displacement = dt * speedAtTime(_progressedTime);
|
||||
}
|
||||
|
||||
_traveledDistance += displacement;
|
||||
@@ -99,12 +99,17 @@ CameraPose PathSegment::traversePath(double dt) {
|
||||
//LINFO(fmt::format("u = {}", relativeDisplacement));
|
||||
//LINFO(fmt::format("currentTime = {}", _currentTime));
|
||||
|
||||
_currentTime += dt;
|
||||
_progressedTime += dt;
|
||||
|
||||
return interpolatedPose(relativeDisplacement);
|
||||
}
|
||||
|
||||
bool PathSegment::hasReachedEnd() {
|
||||
std::string PathSegment::getCurrentAnchor() const {
|
||||
bool pastHalfway = (_traveledDistance / pathLength()) > 0.5;
|
||||
return (pastHalfway) ? _end.nodeDetails.identifier : _start.nodeDetails.identifier;
|
||||
}
|
||||
|
||||
bool PathSegment::hasReachedEnd() const {
|
||||
return (_traveledDistance / pathLength()) >= 1.0;
|
||||
}
|
||||
|
||||
@@ -114,7 +119,7 @@ bool PathSegment::hasReachedEnd() {
|
||||
* Thus, we scale according to the constraint in eq. 14 in Eberly 2007
|
||||
* (https://www.geometrictools.com/Documentation/MovingAlongCurveSpecifiedSpeed.pdf)
|
||||
*/
|
||||
double PathSegment::speedAtTime(double time) {
|
||||
double PathSegment::speedAtTime(double time) const {
|
||||
ghoul_assert(time >= 0 && time <= _duration, "Time out of range [0, duration]");
|
||||
double t = time / _duration;
|
||||
return (pathLength() * _speedFunction.value(t)) / _speedFunction.integratedSum;
|
||||
@@ -127,14 +132,8 @@ CameraPose PathSegment::interpolatedPose(double u) const {
|
||||
return cs;
|
||||
}
|
||||
|
||||
std::string PathSegment::getCurrentAnchor() const {
|
||||
bool pastHalfway = (_traveledDistance / pathLength()) > 0.5;
|
||||
return (pastHalfway) ? _end.nodeDetails.identifier : _start.nodeDetails.identifier;
|
||||
}
|
||||
|
||||
// Initialise the curve, based on the start, end state and curve type
|
||||
void PathSegment::initCurve() {
|
||||
// in case there already is a curve object, reset the pointer.
|
||||
_curve.reset();
|
||||
|
||||
switch (_curveType) {
|
||||
@@ -166,7 +165,7 @@ PathSegment::SpeedFunction::SpeedFunction(double duration) {
|
||||
integratedSum = speedSum;
|
||||
}
|
||||
|
||||
double PathSegment::SpeedFunction::value(double t) {
|
||||
double PathSegment::SpeedFunction::value(double t) const {
|
||||
ghoul_assert(t >= 0 && t <= 1, "Variable t out of range [0,1]");
|
||||
|
||||
const double t1 = 0.2;
|
||||
|
||||
@@ -50,11 +50,11 @@ public:
|
||||
const std::vector<glm::dvec3> getControlPoints() const; // TODO: remove this debugging function
|
||||
|
||||
CameraPose traversePath(double dt);
|
||||
std::string getCurrentAnchor() const;
|
||||
bool hasReachedEnd() const;
|
||||
|
||||
bool hasReachedEnd();
|
||||
double speedAtTime(double time);
|
||||
double speedAtTime(double time) const;
|
||||
CameraPose interpolatedPose(double u) const;
|
||||
std::string getCurrentAnchor() const;
|
||||
|
||||
private:
|
||||
void initCurve();
|
||||
@@ -63,7 +63,7 @@ private:
|
||||
struct SpeedFunction {
|
||||
SpeedFunction() = default;
|
||||
SpeedFunction(double duration);
|
||||
double value(double t);
|
||||
double value(double t) const;
|
||||
|
||||
// store the sum of the function over the duration of the segment,
|
||||
// so we don't need to recompue it every time we access the speed
|
||||
@@ -81,7 +81,7 @@ private:
|
||||
|
||||
// Playback variables
|
||||
double _traveledDistance = 0.0;
|
||||
double _currentTime = 0.0; // Time since playback started
|
||||
double _progressedTime = 0.0; // Time since playback started
|
||||
};
|
||||
|
||||
} // namespace openspace::autonavigation
|
||||
|
||||
@@ -37,10 +37,8 @@ namespace openspace::autonavigation {
|
||||
|
||||
RotationInterpolator::RotationInterpolator(
|
||||
const Waypoint& start, const Waypoint& end, PathCurve* curve, RotationMethod method)
|
||||
: _start(start), _end(end), _method(method)
|
||||
{
|
||||
_curve = curve;
|
||||
}
|
||||
: _start(start), _end(end), _method(method), _curve(curve)
|
||||
{}
|
||||
|
||||
glm::dquat RotationInterpolator::rotationAt(double u) {
|
||||
switch (_method)
|
||||
@@ -70,8 +68,8 @@ glm::dquat RotationInterpolator::easedSlerp(double u) {
|
||||
return glm::slerp(_start.rotation(), _end.rotation(), uScaled);
|
||||
}
|
||||
|
||||
// Look at start node until tStart, then turn to look at end node from tEnd
|
||||
// Will overwrite rotation of navigation states!
|
||||
// Look at start node until tStart, then turn to look at end node from tEnd.
|
||||
// OBS! Will overwrite rotation of navigation states!!
|
||||
glm::dquat RotationInterpolator::lookAtInterpolator(double u) {
|
||||
double tStart = 0.15;
|
||||
double tEnd = 0.7;
|
||||
|
||||
Reference in New Issue
Block a user