Add Lua function that returns the worldPosition of a scenegraph node

This commit is contained in:
Malin Ejdbo
2021-05-19 11:41:05 +02:00
parent e209c4a0a2
commit 52a9e23fa9
3 changed files with 21 additions and 2 deletions

View File

@@ -25,8 +25,8 @@
#ifndef __OPENSPACE_MODULE_BASE___RENDERABLEPRISM___H__
#define __OPENSPACE_MODULE_BASE___RENDERABLEPRISM___H__
#include <openspace/properties/scalar/floatProperty.h>
#include <openspace/properties/scalar/intProperty.h>
#include <openspace/properties/scalar/floatproperty.h>
#include <openspace/properties/scalar/intproperty.h>
#include <openspace/properties/vector/vec3property.h>
#include <openspace/rendering/renderable.h>
#include <ghoul/opengl/ghoul_gl.h>

View File

@@ -706,6 +706,13 @@ scripting::LuaLibrary Scene::luaLibrary() {
"Adds an interesting time to the current scene. The first argument is "
"the name of the time and the second argument is the time itself in the "
"format YYYY-MM-DDThh:mm:ss.uuu"
},
{
"worldPosition",
&luascriptfunctions::worldPosition,
{},
"string",
"Returns the worldPosition of the scene graph node with the given string as identifier"
}
}
};

View File

@@ -902,4 +902,16 @@ int addInterestingTime(lua_State* L) {
return 0;
}
int worldPosition(lua_State* L) {
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::worldPosition");
std::string identifier = ghoul::lua::value<std::string>(L, 1, ghoul::lua::PopValue::Yes);
glm::dvec3 pos = global::renderEngine->scene()->sceneGraphNode(identifier)->worldPosition();
ghoul::lua::push(L, pos);
ghoul_assert(lua_gettop(L) == 1, "Incorrect number of items left on stack");
return 1;
}
} // namespace openspace::luascriptfunctions