diff --git a/data/scene/examples/luatransforms/luatransforms.mod b/data/scene/examples/luatransforms/luatransforms.mod new file mode 100644 index 0000000000..8ba5ea62b8 --- /dev/null +++ b/data/scene/examples/luatransforms/luatransforms.mod @@ -0,0 +1,21 @@ +return { + -- Earth barycenter module + { + Name = "Lua Transformation", + Parent = "SolarSystemBarycenter", + Transform = { + Rotation = { + Type = "LuaRotation", + Script = "rotation.lua" + }, + Scale = { + Type = "LuaScale", + Script = "scale.lua" + }, + Translation = { + Type = "LuaTranslation", + Script = "translate.lua" + } + } + } +} diff --git a/data/scene/examples/luatransforms/rotation.lua b/data/scene/examples/luatransforms/rotation.lua new file mode 100644 index 0000000000..0db9bd5949 --- /dev/null +++ b/data/scene/examples/luatransforms/rotation.lua @@ -0,0 +1,6 @@ +-- t1: Ingame seconds past the J2000 epoch +-- t2: Wallclock milliseconds past the J2000 epoch + +function rotation(t1, t2) + return 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0 +end diff --git a/data/scene/examples/luatransforms/scale.lua b/data/scene/examples/luatransforms/scale.lua new file mode 100644 index 0000000000..99ac664c5f --- /dev/null +++ b/data/scene/examples/luatransforms/scale.lua @@ -0,0 +1,6 @@ +-- t1: Ingame seconds past the J2000 epoch +-- t2: Wallclock milliseconds past the J2000 epoch + +function scale(t1, t2) + return 1.0; +end diff --git a/data/scene/examples/luatransforms/translate.lua b/data/scene/examples/luatransforms/translate.lua new file mode 100644 index 0000000000..3dfb769e98 --- /dev/null +++ b/data/scene/examples/luatransforms/translate.lua @@ -0,0 +1,6 @@ +-- t1: Ingame seconds past the J2000 epoch +-- t2: Wallclock milliseconds past the J2000 epoch + +function translation(t1, t2) + return 0.0, 0.0, 0.0 +end diff --git a/include/openspace/scene/scale.h b/include/openspace/scene/scale.h index 2c1876148e..a9f8cbd856 100644 --- a/include/openspace/scene/scale.h +++ b/include/openspace/scene/scale.h @@ -47,10 +47,13 @@ public: virtual ~Scale() = default; virtual bool initialize(); - virtual double scaleValue() const = 0; + virtual double scaleValue() const; virtual void update(const UpdateData& data); static documentation::Documentation Documentation(); + +protected: + double _scale; }; } // namespace openspace diff --git a/include/openspace/scene/translation.h b/include/openspace/scene/translation.h index 21ce0515b4..bcd7597c68 100644 --- a/include/openspace/scene/translation.h +++ b/include/openspace/scene/translation.h @@ -48,7 +48,7 @@ public: virtual ~Translation() = default; virtual bool initialize(); - virtual glm::dvec3 position() const = 0; + virtual glm::dvec3 position() const; virtual void update(const UpdateData& data); glm::dvec3 position(double time); @@ -63,6 +63,8 @@ protected: void notifyObservers(); std::function _onParameterChangeCallback; + + glm::dvec3 _positionValue; }; } // namespace openspace diff --git a/modules/base/CMakeLists.txt b/modules/base/CMakeLists.txt index 6f85ec7df9..f178c57515 100644 --- a/modules/base/CMakeLists.txt +++ b/modules/base/CMakeLists.txt @@ -37,8 +37,11 @@ set(HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/rendering/screenspaceframebuffer.h ${CMAKE_CURRENT_SOURCE_DIR}/rendering/screenspaceimagelocal.h ${CMAKE_CURRENT_SOURCE_DIR}/rendering/screenspaceimageonline.h + ${CMAKE_CURRENT_SOURCE_DIR}/translation/luatranslation.h ${CMAKE_CURRENT_SOURCE_DIR}/translation/statictranslation.h + ${CMAKE_CURRENT_SOURCE_DIR}/rotation/luarotation.h ${CMAKE_CURRENT_SOURCE_DIR}/rotation/staticrotation.h + ${CMAKE_CURRENT_SOURCE_DIR}/scale/luascale.h ${CMAKE_CURRENT_SOURCE_DIR}/scale/staticscale.h ) source_group("Header Files" FILES ${HEADER_FILES}) @@ -56,8 +59,11 @@ set(SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/rendering/screenspaceframebuffer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/rendering/screenspaceimagelocal.cpp ${CMAKE_CURRENT_SOURCE_DIR}/rendering/screenspaceimageonline.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/translation/luatranslation.cpp ${CMAKE_CURRENT_SOURCE_DIR}/translation/statictranslation.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/rotation/luarotation.cpp ${CMAKE_CURRENT_SOURCE_DIR}/rotation/staticrotation.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/scale/luascale.cpp ${CMAKE_CURRENT_SOURCE_DIR}/scale/staticscale.cpp ) source_group("Source Files" FILES ${SOURCE_FILES}) diff --git a/modules/base/basemodule.cpp b/modules/base/basemodule.cpp index 86e9e000b2..c7165bbd5b 100644 --- a/modules/base/basemodule.cpp +++ b/modules/base/basemodule.cpp @@ -43,10 +43,13 @@ #include #include +#include #include +#include #include +#include #include #include @@ -85,16 +88,19 @@ void BaseModule::internalInitialize() { auto fTranslation = FactoryManager::ref().factory(); ghoul_assert(fTranslation, "Ephemeris factory was not created"); + fTranslation->registerClass("LuaTranslation"); fTranslation->registerClass("StaticTranslation"); auto fRotation = FactoryManager::ref().factory(); ghoul_assert(fRotation, "Rotation factory was not created"); + fRotation->registerClass("LuaRotation"); fRotation->registerClass("StaticRotation"); auto fScale = FactoryManager::ref().factory(); ghoul_assert(fScale, "Scale factory was not created"); + fScale->registerClass("LuaScale"); fScale->registerClass("StaticScale"); auto fModelGeometry = FactoryManager::ref().factory(); @@ -112,8 +118,11 @@ std::vector BaseModule::documentations() const { ScreenSpaceFramebuffer::Documentation(), ScreenSpaceImageLocal::Documentation(), ScreenSpaceImageOnline::Documentation(), + LuaRotation::Documentation(), StaticRotation::Documentation(), + LuaScale::Documentation(), StaticScale::Documentation(), + LuaTranslation::Documentation(), StaticTranslation::Documentation(), modelgeometry::ModelGeometry::Documentation(), }; diff --git a/modules/base/rotation/luarotation.cpp b/modules/base/rotation/luarotation.cpp new file mode 100644 index 0000000000..5192a85b9e --- /dev/null +++ b/modules/base/rotation/luarotation.cpp @@ -0,0 +1,133 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2017 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#include + +#include +#include +#include + +#include +#include +#include + +#include + +namespace { + static const openspace::properties::Property::PropertyInfo ScriptInfo = { + "Script", + "Script", + "This value is the path to the Lua script that will be executed to compute the " + "rotation for this transformation. The script needs to define a function " + "'rotation' that takes the current simulation time in seconds past the J2000 " + "epoch as the first argument, the current wall time as milliseconds past the " + "J2000 epoch as the second argument and computes the rotation returned as 9 " + "values." + };} // namespace + +namespace openspace { + +documentation::Documentation LuaRotation::Documentation() { + using namespace openspace::documentation; + return { + "Lua Rotation", + "base_transform_rotation_lua", + { + { + "Type", + new StringEqualVerifier("LuaRotation"), + Optional::No + }, + { + ScriptInfo.identifier, + new StringVerifier, + Optional::No, + ScriptInfo.description + } + } + }; +} + +LuaRotation::LuaRotation() + : _luaScriptFile(ScriptInfo) + , _state(false) +{ + addProperty(_luaScriptFile); +} + +LuaRotation::LuaRotation(const ghoul::Dictionary& dictionary) + : LuaRotation() +{ + documentation::testSpecificationAndThrow( + Documentation(), + dictionary, + "LuaRotation" + ); + + _luaScriptFile = absPath(dictionary.value(ScriptInfo.identifier)); +} + +void LuaRotation::update(const UpdateData& data) { + ghoul::lua::runScriptFile(_state, _luaScriptFile); + + // Get the scaling function + lua_getglobal(_state, "rotation"); + bool isFunction = lua_isfunction(_state, -1); + if (!isFunction) { + LERRORC( + "LuaRotation", + "Script '" << _luaScriptFile << "' does not have a function 'rotation'" + ); + return; + } + + // First argument is the number of seconds past the J2000 epoch in ingame time + lua_pushnumber(_state, data.time.j2000Seconds()); + + // Second argument is the number of milliseconds past the J2000 epoch in wallclock + using namespace std::chrono; + auto now = high_resolution_clock::now(); + lua_pushnumber( + _state, + duration_cast(now.time_since_epoch()).count() + ); + + // Execute the scaling function + int success = lua_pcall(_state, 2, 9, 0); + if (success != 0) { + LERRORC( + "LuaScale", + "Error executing 'rotation': " << lua_tostring(_state, -1) + ); + } + + double values[9]; + for (int i = 0; i < 9; ++i) { + values[i] = luaL_checknumber(_state, -1 - i); + } + + _matrix = glm::make_mat3(values); +} + +} // namespace openspace diff --git a/modules/base/rotation/luarotation.h b/modules/base/rotation/luarotation.h new file mode 100644 index 0000000000..0c6a2d444f --- /dev/null +++ b/modules/base/rotation/luarotation.h @@ -0,0 +1,54 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2017 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#ifndef __OPENSPACE_MODULE_BASE___LUAROTATION___H__ +#define __OPENSPACE_MODULE_BASE___LUAROTATION___H__ + +#include + +#include + +#include + +namespace openspace { + +namespace documentation { struct Documentation; } + +class LuaRotation : public Rotation { +public: + LuaRotation(); + LuaRotation(const ghoul::Dictionary& dictionary); + + void update(const UpdateData& data) override; + + static documentation::Documentation Documentation(); + +private: + properties::StringProperty _luaScriptFile; + ghoul::lua::LuaState _state; +}; + +} // namespace openspace + +#endif // __OPENSPACE_MODULE_BASE___LUAROTATION___H__ diff --git a/modules/base/scale/luascale.cpp b/modules/base/scale/luascale.cpp new file mode 100644 index 0000000000..30636c4be4 --- /dev/null +++ b/modules/base/scale/luascale.cpp @@ -0,0 +1,119 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2017 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#include + +#include +#include +#include + +#include +#include +#include + +#include + +namespace { + static const openspace::properties::Property::PropertyInfo ScriptInfo = { + "Script", + "Script", + "This value is the path to the Lua script that will be executed to compute the " + "scaling factor for this transformation. The script needs to define a function " + "'scale' that takes the current simulation time in seconds past the J2000 epoch " + "as the first argument, the current wall time as milliseconds past the J2000 " + "epoch the second argument and computes the scaling factor." + }; +} // namespace + +namespace openspace { + +documentation::Documentation LuaScale::Documentation() { + using namespace openspace::documentation; + return { + "Lua Scaling", + "base_scale_lua", + { + { + ScriptInfo.identifier, + new StringVerifier, + Optional::No, + ScriptInfo.description + } + } + }; +} + +LuaScale::LuaScale() + : _luaScriptFile(ScriptInfo) + , _state(false) +{ + addProperty(_luaScriptFile); +} + +LuaScale::LuaScale(const ghoul::Dictionary& dictionary) + : LuaScale() +{ + documentation::testSpecificationAndThrow(Documentation(), dictionary, "LuaScale"); + + _luaScriptFile = absPath(dictionary.value(ScriptInfo.identifier)); +} + +void LuaScale::update(const UpdateData& data) { + ghoul::lua::runScriptFile(_state, _luaScriptFile); + + // Get the scaling function + lua_getglobal(_state, "scale"); + bool isFunction = lua_isfunction(_state, -1); + if (!isFunction) { + LERRORC( + "LuaScale", + "Script '" << _luaScriptFile << "' does not have a function 'scale'" + ); + return; + } + + // First argument is the number of seconds past the J2000 epoch in ingame time + lua_pushnumber(_state, data.time.j2000Seconds()); + + // Second argument is the number of milliseconds past the J2000 epoch in wallclock + using namespace std::chrono; + auto now = high_resolution_clock::now(); + lua_pushnumber( + _state, + duration_cast(now.time_since_epoch()).count() + ); + + // Execute the scaling function + int success = lua_pcall(_state, 2, 1, 0); + if (success != 0) { + LERRORC( + "LuaScale", + "Error executing 'scale': " << lua_tostring(_state, -1) + ); + } + + _scale = luaL_checknumber(_state, -1); +} + +} // namespace openspace diff --git a/modules/base/scale/luascale.h b/modules/base/scale/luascale.h new file mode 100644 index 0000000000..2a96aca443 --- /dev/null +++ b/modules/base/scale/luascale.h @@ -0,0 +1,54 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2017 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#ifndef __OPENSPACE_MODULE_BASE___LUASCALE___H__ +#define __OPENSPACE_MODULE_BASE___LUASCALE___H__ + +#include + +#include + +#include + +namespace openspace { + +namespace documentation { struct Documentation; } + +class LuaScale : public Scale { +public: + LuaScale(); + LuaScale(const ghoul::Dictionary& dictionary); + + void update(const UpdateData& data) override; + + static documentation::Documentation Documentation(); + +private: + properties::StringProperty _luaScriptFile; + ghoul::lua::LuaState _state; +}; + +} // namespace openspace + +#endif // __OPENSPACE_MODULE_BASE___LUASCALE___H__ diff --git a/modules/base/scale/staticscale.cpp b/modules/base/scale/staticscale.cpp index 8a9f895856..3659e6b7ce 100644 --- a/modules/base/scale/staticscale.cpp +++ b/modules/base/scale/staticscale.cpp @@ -58,6 +58,8 @@ StaticScale::StaticScale() : _scaleValue(ScaleInfo, 1.0, 1.0, 1e6) { addProperty(_scaleValue); + + _scaleValue.onChange([&](){ _scale = _scaleValue; }); } StaticScale::StaticScale(const ghoul::Dictionary& dictionary) @@ -68,8 +70,4 @@ StaticScale::StaticScale(const ghoul::Dictionary& dictionary) _scaleValue = static_cast(dictionary.value(ScaleInfo.identifier)); } -double StaticScale::scaleValue() const { - return _scaleValue; -} - } // namespace openspace diff --git a/modules/base/scale/staticscale.h b/modules/base/scale/staticscale.h index aff8812ee7..11aa0c5ad1 100644 --- a/modules/base/scale/staticscale.h +++ b/modules/base/scale/staticscale.h @@ -38,8 +38,6 @@ public: StaticScale(); StaticScale(const ghoul::Dictionary& dictionary); - double scaleValue() const override; - static documentation::Documentation Documentation(); private: diff --git a/modules/base/translation/luatranslation.cpp b/modules/base/translation/luatranslation.cpp new file mode 100644 index 0000000000..85b20c52ef --- /dev/null +++ b/modules/base/translation/luatranslation.cpp @@ -0,0 +1,141 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2017 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#include + +#include +#include +#include + +#include +#include +#include + +#include + +namespace { + static const openspace::properties::Property::PropertyInfo ScriptInfo = { + "Script", + "Script", + "This value is the path to the Lua script that will be executed to compute the " + "translation for this transformation. The script needs to define a function " + "'translate' that takes the current simulation time in seconds past the J2000 " + "epoch as the first argument, the current wall time as milliseconds past the " + "J2000 epoch as the second argument and computes the translation." + }; +} // namespace + +namespace openspace { + +documentation::Documentation LuaTranslation::Documentation() { + using namespace documentation; + return { + "Lua Translation", + "base_transform_translation_lua", + { + { + "Type", + new StringEqualVerifier("LuaTranslation"), + Optional::No + }, + { + ScriptInfo.identifier, + new StringVerifier, + Optional::No, + ScriptInfo.description + } + } + }; +} + + +LuaTranslation::LuaTranslation() + : _luaScriptFile(ScriptInfo) + , _state(false) +{ + addProperty(_luaScriptFile); + + _luaScriptFile.onChange([&](){ + _fileHandle = std::make_unique(_luaScriptFile); + _fileHandle->setCallback([&](const ghoul::filesystem::File&){ + notifyObservers(); + }); + }); +} + +LuaTranslation::LuaTranslation(const ghoul::Dictionary& dictionary) + : LuaTranslation() +{ + documentation::testSpecificationAndThrow( + Documentation(), + dictionary, + "StaticTranslation" + ); + + _luaScriptFile = absPath(dictionary.value(ScriptInfo.identifier)); +} + +void LuaTranslation::update(const UpdateData& data) { + ghoul::lua::runScriptFile(_state, _luaScriptFile); + + // Get the scaling function + lua_getglobal(_state, "translation"); + bool isFunction = lua_isfunction(_state, -1); + if (!isFunction) { + LERRORC( + "LuaScale", + "Script '" << _luaScriptFile << "' does not have a function 'translation'" + ); + return; + } + + // First argument is the number of seconds past the J2000 epoch in ingame time + lua_pushnumber(_state, data.time.j2000Seconds()); + + // Second argument is the number of milliseconds past the J2000 epoch in wallclock + using namespace std::chrono; + auto now = high_resolution_clock::now(); + lua_pushnumber( + _state, + duration_cast(now.time_since_epoch()).count() + ); + + // Execute the scaling function + int success = lua_pcall(_state, 2, 3, 0); + if (success != 0) { + LERRORC( + "LuaScale", + "Error executing 'translation': " << lua_tostring(_state, -1) + ); + } + + double values[3]; + for (int i = 0; i < 3; ++i) { + values[i] = luaL_checknumber(_state, -1 - i); + } + + _positionValue = glm::make_vec3(values); +} + +} // namespace openspace diff --git a/modules/base/translation/luatranslation.h b/modules/base/translation/luatranslation.h new file mode 100644 index 0000000000..2ee4302d75 --- /dev/null +++ b/modules/base/translation/luatranslation.h @@ -0,0 +1,59 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2017 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#ifndef __OPENSPACE_MODULE_BASE___LUATRANSLATION___H__ +#define __OPENSPACE_MODULE_BASE___LUATRANSLATION___H__ + +#include + +#include + +#include +#include + +#include + +namespace openspace { + +namespace documentation { struct Documentation; } + +class LuaTranslation : public Translation { +public: + LuaTranslation(); + LuaTranslation(const ghoul::Dictionary& dictionary); + + virtual void update(const UpdateData& data) override; + + static documentation::Documentation Documentation(); + +private: + properties::StringProperty _luaScriptFile; + ghoul::lua::LuaState _state; + + std::unique_ptr _fileHandle; +}; + +} // namespace openspace + +#endif // __OPENSPACE_MODULE_BASE___LUATRANSLATION___H__ diff --git a/modules/base/translation/statictranslation.cpp b/modules/base/translation/statictranslation.cpp index be2c3c9520..a201294070 100644 --- a/modules/base/translation/statictranslation.cpp +++ b/modules/base/translation/statictranslation.cpp @@ -69,6 +69,8 @@ StaticTranslation::StaticTranslation() ) { addProperty(_position); + + _position.onChange([&](){ _positionValue = _position; }); } StaticTranslation::StaticTranslation(const ghoul::Dictionary& dictionary) @@ -83,8 +85,4 @@ StaticTranslation::StaticTranslation(const ghoul::Dictionary& dictionary) _position = dictionary.value(PositionInfo.identifier); } -glm::dvec3 StaticTranslation::position() const { - return _position; -} - } // namespace openspace diff --git a/modules/base/translation/statictranslation.h b/modules/base/translation/statictranslation.h index df9d4c4e77..50860dbbc7 100644 --- a/modules/base/translation/statictranslation.h +++ b/modules/base/translation/statictranslation.h @@ -38,8 +38,6 @@ public: StaticTranslation(); StaticTranslation(const ghoul::Dictionary& dictionary); - virtual glm::dvec3 position() const override; - static documentation::Documentation Documentation(); private: diff --git a/src/scene/scale.cpp b/src/scene/scale.cpp index dae3cf2ae1..da0b9efc35 100644 --- a/src/scene/scale.cpp +++ b/src/scene/scale.cpp @@ -72,12 +72,17 @@ std::unique_ptr Scale::createFromDictionary(const ghoul::Dictionary& dict Scale::Scale() : properties::PropertyOwner({ "Scale" }) + , _scale(1.0) {} bool Scale::initialize() { return true; } - + +double Scale::scaleValue() const { + return _scale; +} + void Scale::update(const UpdateData&) {} } // namespace openspace diff --git a/src/scene/translation.cpp b/src/scene/translation.cpp index 03d07c7aba..5b41e97a63 100644 --- a/src/scene/translation.cpp +++ b/src/scene/translation.cpp @@ -73,6 +73,7 @@ std::unique_ptr Translation::createFromDictionary( Translation::Translation() : properties::PropertyOwner({ "Translation" }) + , _positionValue(glm::dvec3(0.0)) {} bool Translation::initialize() { @@ -81,6 +82,10 @@ bool Translation::initialize() { void Translation::update(const UpdateData&) {} +glm::dvec3 Translation::position() const { + return _positionValue; +} + glm::dvec3 Translation::position(double time) { update({ {},