Add support to pause and continue playing a path

This commit is contained in:
Emma Broman
2021-06-09 16:45:35 +02:00
parent e1ada5ab88
commit d0c433ff10
4 changed files with 92 additions and 46 deletions

View File

@@ -133,12 +133,12 @@ double AutoNavigationHandler::speedScale() const {
return _speedScale;
}
bool AutoNavigationHandler::noCurrentPath() const {
return _currentPath == nullptr;
bool AutoNavigationHandler::hasCurrentPath() const {
return _currentPath != nullptr;
}
bool AutoNavigationHandler::hasFinished() const {
if (noCurrentPath()) {
if (!hasCurrentPath()) {
return true;
}
@@ -150,13 +150,13 @@ void AutoNavigationHandler::updateCamera(double deltaTime) {
if (!_isPlaying) {
// TODO: Determine how this should work
if (_applyStopBehaviorWhenIdle) {
if (hasFinished() && _applyStopBehaviorWhenIdle) {
applyStopBehavior(deltaTime);
}
return;
}
if (noCurrentPath()) {
if (!hasCurrentPath()) {
return;
}
@@ -217,7 +217,6 @@ void AutoNavigationHandler::createPath(PathInstruction& instruction) {
);
LINFO("Successfully generated camera path");
startPath();
}
void AutoNavigationHandler::clearPath() {
@@ -226,7 +225,7 @@ void AutoNavigationHandler::clearPath() {
}
void AutoNavigationHandler::startPath() {
if (noCurrentPath()) {
if (!hasCurrentPath()) {
LERROR("There is no path to start");
return;
}
@@ -241,21 +240,6 @@ void AutoNavigationHandler::startPath() {
_isPlaying = true;
}
//void AutoNavigationHandler::continuePath() {
// if (hasFinished()) {
// LERROR("No path to resume (path is empty or has finished).");
// return;
// }
//
// if (_isPlaying) {
// LERROR("Cannot resume a path that is already playing");
// return;
// }
//
// LINFO("Continuing path...");
// _isPlaying = true;
//}
void AutoNavigationHandler::abortPath() {
if (!_isPlaying) {
LWARNING("No camera path is playing");
@@ -265,10 +249,40 @@ void AutoNavigationHandler::abortPath() {
LINFO("Aborted camera path");
}
void AutoNavigationHandler::pausePath() {
if (hasFinished()) {
LERROR("No path to pause (path is empty or has finished).");
return;
}
if (!_isPlaying) {
LERROR("Cannot pause a path that is not playing");
return;
}
LINFO("Path paused");
_isPlaying = false;
}
void AutoNavigationHandler::continuePath() {
if (hasFinished()) {
LERROR("No path to resume (path is empty or has finished).");
return;
}
if (_isPlaying) {
LERROR("Cannot resume a path that is already playing");
return;
}
LINFO("Continuing path...");
_isPlaying = true;
}
// TODO: remove when not needed
// Created for debugging
std::vector<glm::dvec3> AutoNavigationHandler::curvePositions(int nSteps) const {
if (noCurrentPath()) {
if (!hasCurrentPath()) {
LERROR("There is no current path to sample points from.");
return {};
}
@@ -288,7 +302,7 @@ std::vector<glm::dvec3> AutoNavigationHandler::curvePositions(int nSteps) const
// TODO: remove when not needed
// Created for debugging
std::vector<glm::dquat> AutoNavigationHandler::curveOrientations(int nSteps) const {
if (noCurrentPath()) {
if (!hasCurrentPath()) {
LERROR("There is no current path to sample points from.");
return {};
}
@@ -310,7 +324,7 @@ std::vector<glm::dquat> AutoNavigationHandler::curveOrientations(int nSteps) con
// TODO: remove when not needed or combined into pose version
// Created for debugging
std::vector<glm::dvec3> AutoNavigationHandler::curveViewDirections(int nSteps) const {
if (noCurrentPath()) {
if (!hasCurrentPath()) {
LERROR("There is no current path to sample points from.");
return {};
}
@@ -337,7 +351,7 @@ std::vector<glm::dvec3> AutoNavigationHandler::curveViewDirections(int nSteps) c
// TODO: remove when not needed
// Created for debugging
std::vector<glm::dvec3> AutoNavigationHandler::controlPoints() const {
if (noCurrentPath()) {
if (!hasCurrentPath()) {
LERROR("There is no current path to sample points from.");
return {};
}

View File

@@ -54,7 +54,7 @@ public:
const SceneGraphNode* anchor() const;
double speedScale() const;
bool noCurrentPath() const;
bool hasCurrentPath() const;
bool hasFinished() const;
void updateCamera(double deltaTime);
@@ -62,9 +62,8 @@ public:
void clearPath();
void startPath();
void abortPath();
// TODO: allow option to pause during a path and then change this to continue playing
//void continuePath();
void pausePath();
void continuePath();
// TODO: remove functions for debugging
std::vector<glm::dvec3> curvePositions(int nSteps) const;

View File

@@ -144,13 +144,20 @@ scripting::LuaLibrary AutoNavigationModule::luaLibrary() const {
"",
"Returns true if a camera path is currently running, and false otherwise."
},
//{
// "continuePath",
// &autonavigation::luascriptfunctions::continuePath,
// {},
// "",
// "Continue playing a paused camera path."
//},
{
"continuePath",
&autonavigation::luascriptfunctions::continuePath,
{},
"",
"Continue playing a paused camera path."
},
{
"pausePath",
&autonavigation::luascriptfunctions::pausePath,
{},
"",
"Pause a playing camera path."
},
{
"stopPath",
&autonavigation::luascriptfunctions::stopPath,

View File

@@ -56,15 +56,25 @@ int isFlying(lua_State* L) {
return 1;
}
//int continuePath(lua_State* L) {
// ghoul::lua::checkArgumentsAndThrow(L, 0, "lua::continuePath");
//
// AutoNavigationModule* module = global::moduleEngine->module<AutoNavigationModule>();
// module->AutoNavigationHandler().continuePath();
//
// ghoul_assert(lua_gettop(L) == 0, "Incorrect number of items left on stack");
// return 0;
//}
int continuePath(lua_State* L) {
ghoul::lua::checkArgumentsAndThrow(L, 0, "lua::continuePath");
AutoNavigationModule* module = global::moduleEngine->module<AutoNavigationModule>();
module->AutoNavigationHandler().continuePath();
ghoul_assert(lua_gettop(L) == 0, "Incorrect number of items left on stack");
return 0;
}
int pausePath(lua_State* L) {
ghoul::lua::checkArgumentsAndThrow(L, 0, "lua::pausePath");
AutoNavigationModule* module = global::moduleEngine->module<AutoNavigationModule>();
module->AutoNavigationHandler().pausePath();
ghoul_assert(lua_gettop(L) == 0, "Incorrect number of items left on stack");
return 0;
}
int stopPath(lua_State* L) {
ghoul::lua::checkArgumentsAndThrow(L, 0, "lua::stopPath");
@@ -149,6 +159,10 @@ int goTo(lua_State* L) {
AutoNavigationModule* module = global::moduleEngine->module<AutoNavigationModule>();
module->AutoNavigationHandler().createPath(instruction);
if (module->AutoNavigationHandler().hasCurrentPath()) {
module->AutoNavigationHandler().startPath();
}
lua_settop(L, 0);
ghoul_assert(lua_gettop(L) == 0, "Incorrect number of items left on stack");
return 0;
@@ -184,6 +198,10 @@ int goToHeight(lua_State* L) {
AutoNavigationModule* module = global::moduleEngine->module<AutoNavigationModule>();
module->AutoNavigationHandler().createPath(instruction);
if (module->AutoNavigationHandler().hasCurrentPath()) {
module->AutoNavigationHandler().startPath();
}
lua_settop(L, 0);
ghoul_assert(lua_gettop(L) == 0, "Incorrect number of items left on stack");
return 0;
@@ -239,6 +257,10 @@ int goToGeo(lua_State* L) {
AutoNavigationModule* module = global::moduleEngine->module<AutoNavigationModule>();
module->AutoNavigationHandler().createPath(instruction);
if (module->AutoNavigationHandler().hasCurrentPath()) {
module->AutoNavigationHandler().startPath();
}
lua_settop(L, 0);
ghoul_assert(lua_gettop(L) == 0, "Incorrect number of items left on stack");
return 0;
@@ -254,6 +276,10 @@ int generatePath(lua_State* L) {
AutoNavigationModule* module = global::moduleEngine->module<AutoNavigationModule>();
module->AutoNavigationHandler().createPath(instruction);
if (module->AutoNavigationHandler().hasCurrentPath()) {
module->AutoNavigationHandler().startPath();
}
lua_settop(L, 0);
ghoul_assert(lua_gettop(L) == 0, "Incorrect number of items left on stack");
return 0;