mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-18 09:58:59 -05:00
Temporary solution for handling pauses in instruction
This commit is contained in:
@@ -253,7 +253,7 @@ bool AutoNavigationHandler::handleInstruction(const Instruction& instruction, in
|
||||
break;
|
||||
|
||||
default:
|
||||
LERROR(fmt::format("Non-implemented instruction type: {}.", instruction.type));
|
||||
LERROR("Non-implemented instruction type.");
|
||||
success = false;
|
||||
break;
|
||||
}
|
||||
@@ -355,15 +355,13 @@ bool AutoNavigationHandler::handlePauseInstruction(const Instruction& instructio
|
||||
return false;
|
||||
}
|
||||
|
||||
CameraState startState =_pathSegments.empty()
|
||||
CameraState state =_pathSegments.empty()
|
||||
? currentCameraState()
|
||||
: _pathSegments.back().end();
|
||||
|
||||
CameraState endState = startState;
|
||||
|
||||
// TODO: implement more complex behavior later
|
||||
|
||||
addSegment(startState, endState, instruction.props->duration);
|
||||
addPause(state, instruction.props->duration);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -390,6 +388,23 @@ void AutoNavigationHandler::addSegment(CameraState& start,
|
||||
_pathSegments.push_back(newSegment);
|
||||
}
|
||||
|
||||
void AutoNavigationHandler::addPause(CameraState& state, std::optional<double> duration) {
|
||||
// compute startTime
|
||||
double startTime = 0.0;
|
||||
if (!_pathSegments.empty()) {
|
||||
PathSegment& last = _pathSegments.back();
|
||||
startTime = last.startTime() + last.duration();
|
||||
}
|
||||
|
||||
PathSegment newSegment = PathSegment{ state, state, startTime, CurveType::Pause };
|
||||
|
||||
// TODO: handle duration better
|
||||
if (duration.has_value()) {
|
||||
newSegment.setDuration(duration.value());
|
||||
}
|
||||
_pathSegments.push_back(newSegment);
|
||||
}
|
||||
|
||||
glm::dvec3 AutoNavigationHandler::computeTargetPositionAtNode(
|
||||
const SceneGraphNode* node, glm::dvec3 prevPos, double height)
|
||||
{
|
||||
|
||||
@@ -72,6 +72,8 @@ private:
|
||||
|
||||
void addSegment(CameraState& start, CameraState& end, std::optional<double> duration);
|
||||
|
||||
void addPause(CameraState& state, std::optional<double> duration);
|
||||
|
||||
glm::dvec3 computeTargetPositionAtNode(const SceneGraphNode* node,
|
||||
glm::dvec3 prevPos, double height);
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
|
||||
namespace openspace::autonavigation {
|
||||
|
||||
enum InstructionType { TargetNode, NavigationState, Pause };
|
||||
enum class InstructionType { TargetNode, NavigationState, Pause };
|
||||
|
||||
struct InstructionProps {
|
||||
InstructionProps() = default;
|
||||
|
||||
@@ -175,4 +175,13 @@ glm::dvec3 Linear2Curve::valueAt(double t) {
|
||||
return interpolation::piecewiseLinear(t, _points);
|
||||
}
|
||||
|
||||
// TODO: Iprove handling of pauses
|
||||
PauseCurve::PauseCurve(CameraState& state) {
|
||||
_points.push_back(state.position);
|
||||
}
|
||||
|
||||
glm::dvec3 PauseCurve::valueAt(double t) {
|
||||
return _points[0];
|
||||
}
|
||||
|
||||
} // namespace openspace::autonavigation
|
||||
|
||||
@@ -73,6 +73,14 @@ public:
|
||||
glm::dvec3 valueAt(double t);
|
||||
};
|
||||
|
||||
// OBS! This is a temporary class specialised for handling pauses.
|
||||
// TODO: handle better in the future.
|
||||
class PauseCurve : public PathCurve {
|
||||
public:
|
||||
PauseCurve(CameraState& state);
|
||||
glm::dvec3 valueAt(double t);
|
||||
};
|
||||
|
||||
} // namespace openspace::autonavigation
|
||||
|
||||
#endif // __OPENSPACE_MODULE_AUTONAVIGATION___PATHCURVE___H__
|
||||
|
||||
@@ -79,7 +79,7 @@ const glm::dquat PathSegment::getRotationAt(double t) const {
|
||||
tRot = easingfunctions::cubicEaseInOut(tRot);
|
||||
|
||||
switch (_curveType) {
|
||||
case Linear2:
|
||||
case CurveType::Linear2:
|
||||
return getLookAtRotation(
|
||||
tRot,
|
||||
getPositionAt(t),
|
||||
@@ -113,23 +113,26 @@ void PathSegment::initCurve() {
|
||||
_curve.reset();
|
||||
|
||||
switch (_curveType) {
|
||||
case Bezier:
|
||||
case CurveType::Bezier:
|
||||
_curve = std::make_shared<BezierCurve>(_start, _end);
|
||||
break;
|
||||
case Bezier2:
|
||||
case CurveType::Bezier2:
|
||||
_curve = std::make_shared<Bezier2Curve>(_start, _end);
|
||||
break;
|
||||
case Bezier3:
|
||||
case CurveType::Bezier3:
|
||||
_curve = std::make_shared<Bezier3Curve>(_start, _end);
|
||||
break;
|
||||
case Linear:
|
||||
case CurveType::Linear:
|
||||
_curve = std::make_shared<LinearCurve>(_start, _end);
|
||||
break;
|
||||
case Linear2:
|
||||
case CurveType::Linear2:
|
||||
_curve = std::make_shared<Linear2Curve>(_start, _end);
|
||||
break;
|
||||
case CurveType::Pause:
|
||||
_curve = std::make_shared<PauseCurve>(_start);
|
||||
break;
|
||||
default:
|
||||
LERROR(fmt::format("Cannot create curve of type {}. Type does not exist!", _curveType));
|
||||
LERROR("Could not create curve. Type does not exist!");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,12 +31,13 @@
|
||||
|
||||
namespace openspace::autonavigation {
|
||||
|
||||
enum CurveType {
|
||||
enum class CurveType {
|
||||
Bezier,
|
||||
Bezier2,
|
||||
Bezier3,
|
||||
Linear,
|
||||
Linear2,
|
||||
Pause, // OBS! Temporary special case for handling pauses
|
||||
None
|
||||
};
|
||||
|
||||
@@ -44,7 +45,7 @@ class PathCurve;
|
||||
|
||||
class PathSegment {
|
||||
public:
|
||||
PathSegment(CameraState start, CameraState end, double startTime, CurveType type = Bezier3);
|
||||
PathSegment(CameraState start, CameraState end, double startTime, CurveType type = CurveType::Bezier3);
|
||||
~PathSegment() = default;
|
||||
|
||||
// Mutators
|
||||
|
||||
Reference in New Issue
Block a user