Move geo path creation to globebrowsing module

This commit is contained in:
Emma Broman
2021-06-23 09:09:45 +02:00
parent 77bdfaefd6
commit a247f9d1b3
4 changed files with 91 additions and 70 deletions
@@ -398,6 +398,20 @@ scripting::LuaLibrary GlobeBrowsingModule::luaLibrary() const {
"altitude is provided, the altitude will be kept as the current distance to "
"the surface of the specified globe."
},
{
// @TODO (2021-06-23, emmbr) Combine with the above function when the camera
// paths work really well close to surfaces
"flyToGeo",
&globebrowsing::luascriptfunctions::flyToGeo,
{},
"[string], number, number, number, [number]",
"Fly the camera to geographic coordinates of a globe, using the path "
"navigation system. The first (optional) argument is the identifier of a "
"scene graph node with a RenderableGlobe. If no globe is passed in, the "
"current anchor will be used. The second and third argument is latitude "
"and longitude (degrees). The fourth argument is the altitude, in meters. "
"The last (optional) parameter is a duration for the motion"
},
{
"getGeoPosition",
&globebrowsing::luascriptfunctions::getGeoPosition,
@@ -287,6 +287,82 @@ int goToGeo(lua_State* L) {
return 0;
}
int flyToGeo(lua_State* L) {
int nArguments = ghoul::lua::checkArgumentsAndThrow(L, { 3, 5 }, "lua::flyToGeo");
// Check if the user provided a Scene graph node identifier as the first argument.
// lua_isstring returns true for both numbers and strings, so better use !lua_isnumber
const bool providedGlobeIdentifier = !lua_isnumber(L, 1);
const int parameterOffset = providedGlobeIdentifier ? 1 : 0;
const SceneGraphNode* n;
if (providedGlobeIdentifier) {
const std::string& globeIdentifier = ghoul::lua::value<std::string>(L, 1);
n = sceneGraphNode(globeIdentifier);
if (!n) {
return ghoul::lua::luaError(L, "Unknown globe name: " + globeIdentifier);
}
}
else {
n = global::navigationHandler->orbitalNavigator().anchorNode();
if (!n) {
return ghoul::lua::luaError(L, "No anchor node is set.");
}
}
const RenderableGlobe* globe = dynamic_cast<const RenderableGlobe*>(n->renderable());
if (!globe) {
if (providedGlobeIdentifier) {
return ghoul::lua::luaError(L, "Identifier must be a RenderableGlobe");
}
else {
return ghoul::lua::luaError(L,
"Current anchor node is not a RenderableGlobe. "
"Either change the anchor to a globe, or specify a globe identifier "
"as the first argument"
);
}
}
const double latitude = ghoul::lua::value<double>(L, parameterOffset + 1);
const double longitude = ghoul::lua::value<double>(L, parameterOffset + 2);
const double altitude = ghoul::lua::value<double>(L, parameterOffset + 3);
// Compute the relative position based on the input values
auto module = global::moduleEngine->module<GlobeBrowsingModule>();
const glm::dvec3 positionModelCoords = module->cartesianCoordinatesFromGeo(
*globe,
latitude,
longitude,
altitude
);
using namespace std::string_literals;
ghoul::Dictionary instruction;
instruction.setValue("Type", "Node"s);
instruction.setValue("Target", n->identifier());
instruction.setValue("Position", positionModelCoords);
if (nArguments == parameterOffset + 4) {
const double duration = ghoul::lua::value<double>(L, parameterOffset + 4);
if (duration <= 0.0) {
lua_settop(L, 0);
return ghoul::lua::luaError(L, "Duration must be larger than zero.");
}
instruction.setValue("Duration", duration);
}
global::navigationHandler->pathNavigator().createPath(instruction);
global::navigationHandler->pathNavigator().startPath();
// @TODO (2021-06-26, emmbr) add possibility to specify that north should be "up"?
lua_settop(L, 0);
ghoul_assert(lua_gettop(L) == 0, "Incorrect number of items left on stack");
return 0;
}
int getGeoPosition(lua_State* L) {
ghoul::lua::checkArgumentsAndThrow(L, 4, "lua::getGeoPosition");
-11
View File
@@ -572,17 +572,6 @@ scripting::LuaLibrary PathNavigator::luaLibrary() {
"the target up vector for camera is set based on the target node. Either of "
"the optional parameters can be left out."
},
//{
// "goToGeo",
// &luascriptfunctions::goToGeo,
// {},
// "string, double, double, double [, bool, double]",
// "Move the camera to the globe with the name given by the input string. "
// "The next three input parameters are latitude, longitude and altitude. "
// "The optional double specifies the duration of the motion. If the optional "
// "bool is set to true the target up vector for camera is set based on the "
// "target node. Either of the optional parameters can be left out."
//},
{
"generatePath",
&luascriptfunctions::generatePath,
+1 -59
View File
@@ -22,8 +22,6 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
//#include <modules/globebrowsing/globebrowsingmodule.h> // TODO: remove dependancy
//#include <modules/globebrowsing/src/renderableglobe.h>
#include <openspace/camera/camera.h>
#include <openspace/engine/globals.h>
#include <openspace/engine/moduleengine.h>
@@ -39,7 +37,7 @@
#include <glm/gtx/vector_angle.hpp>
namespace {
constexpr const double Epsilon = 1e-12;
constexpr const double Epsilon = 1e-5;
} // namespace
namespace openspace::luascriptfunctions {
@@ -196,62 +194,6 @@ int goToHeight(lua_State* L) {
return 0;
}
//// @TODO (emmbr 2020-11-06) Ideally, this module shouldn't depend on things from
//// Globebrowsing, but we want it for an istallation. Later on, move this functionality
//// somewhere else. Maybe combine with the existing "goToGeo" in globebrowsing?
//int goToGeo(lua_State* L) {
// int nArguments = ghoul::lua::checkArgumentsAndThrow(L, { 4, 6 }, "lua::goToGeo");
//
// const std::string& nodeIdentifier = ghoul::lua::value<std::string>(L, 1);
// const SceneGraphNode* n = sceneGraphNode(nodeIdentifier);
// if (!n) {
// lua_settop(L, 0);
// return ghoul::lua::luaError(L, "Unknown globe name: " + nodeIdentifier);
// }
//
// const double latitude = ghoul::lua::value<double>(L, 2);
// const double longitude = ghoul::lua::value<double>(L, 3);
// const double altitude = ghoul::lua::value<double>(L, 4);
//
// using RenderableGlobe = openspace::globebrowsing::RenderableGlobe;
// const RenderableGlobe* globe = dynamic_cast<const RenderableGlobe*>(n->renderable());
// if (!globe) {
// return ghoul::lua::luaError(L, "Identifier must be a RenderableGlobe");
// }
//
// // Compute the relative position based on the input values
// glm::dvec3 positionModelCoords = global::moduleEngine->module<GlobeBrowsingModule>()
// ->cartesianCoordinatesFromGeo(
// *globe,
// latitude,
// longitude,
// altitude
// );
//
// using namespace std::string_literals;
// ghoul::Dictionary insDict;
// insDict.setValue("Type", "Node"s);
// insDict.setValue("Target", nodeIdentifier);
// insDict.setValue("Position", positionModelCoords);
//
// if (nArguments > 4) {
// int result = handleOptionalGoToParameters(L, 5, nArguments, insDict);
// if (result != 0) {
// return result; // An error occurred
// }
// }
//
// global::navigationHandler->pathNavigator().createPath(insDict);
//
// if (global::navigationHandler->pathNavigator().hasCurrentPath()) {
// global::navigationHandler->pathNavigator().startPath();
// }
//
// lua_settop(L, 0);
// ghoul_assert(lua_gettop(L) == 0, "Incorrect number of items left on stack");
// return 0;
//}
int generatePath(lua_State* L) {
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::generatePath");