mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-03-10 07:18:46 -05:00
Move ra dec conversion lua function to the space module
This commit is contained in:
@@ -44,6 +44,7 @@ set(HEADER_FILES
|
||||
source_group("Header Files" FILES ${HEADER_FILES})
|
||||
|
||||
set(SOURCE_FILES
|
||||
spacemodule_lua.inl
|
||||
speckloader.cpp
|
||||
rendering/planetgeometry.cpp
|
||||
rendering/renderableconstellationbounds.cpp
|
||||
|
||||
@@ -39,11 +39,14 @@
|
||||
#include <openspace/documentation/documentation.h>
|
||||
#include <openspace/rendering/renderable.h>
|
||||
#include <openspace/rendering/screenspacerenderable.h>
|
||||
#include <openspace/scripting/lualibrary.h>
|
||||
#include <openspace/util/factorymanager.h>
|
||||
#include <openspace/util/spicemanager.h>
|
||||
#include <ghoul/misc/assert.h>
|
||||
#include <ghoul/misc/templatefactory.h>
|
||||
|
||||
#include "spacemodule_lua.inl"
|
||||
|
||||
namespace {
|
||||
constexpr openspace::properties::Property::PropertyInfo SpiceExceptionInfo = {
|
||||
"ShowExceptions",
|
||||
@@ -133,4 +136,27 @@ std::vector<documentation::Documentation> SpaceModule::documentations() const {
|
||||
};
|
||||
}
|
||||
|
||||
scripting::LuaLibrary SpaceModule::luaLibrary() const {
|
||||
scripting::LuaLibrary res;
|
||||
res.name = "space";
|
||||
res.functions = {
|
||||
{
|
||||
"convertFromRaDec",
|
||||
&space::luascriptfunctions::convertFromRaDec,
|
||||
{},
|
||||
"string, string, double",
|
||||
"Returns the cartesian world position of a ra dec coordinate with distance"
|
||||
},
|
||||
{
|
||||
"convertToRaDec",
|
||||
&space::luascriptfunctions::convertToRaDec,
|
||||
{},
|
||||
"double, double, double",
|
||||
"Returns the ra, dec strings and distance for a given cartesian world coordinate"
|
||||
}
|
||||
};
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -42,6 +42,8 @@ public:
|
||||
|
||||
static ghoul::opengl::ProgramObjectManager ProgramObjectManager;
|
||||
|
||||
scripting::LuaLibrary luaLibrary() const override;
|
||||
|
||||
private:
|
||||
void internalInitialize(const ghoul::Dictionary&) override;
|
||||
void internalDeinitializeGL() override;
|
||||
|
||||
70
modules/space/spacemodule_lua.inl
Normal file
70
modules/space/spacemodule_lua.inl
Normal file
@@ -0,0 +1,70 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2021 *
|
||||
* *
|
||||
* 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 <openspace/documentation/documentation.h>
|
||||
#include <openspace/engine/globals.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <ghoul/misc/defer.h>
|
||||
#include <ghoul/misc/easing.h>
|
||||
#include <openspace/util/coordinateconversion.h>
|
||||
|
||||
namespace openspace::space::luascriptfunctions {
|
||||
|
||||
int convertFromRaDec(lua_State* L) {
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 3, "lua::convertFromRaDec");
|
||||
|
||||
std::string ra = ghoul::lua::value<std::string>(L, 1);
|
||||
std::string dec = ghoul::lua::value<std::string>(L, 2);
|
||||
double distance = ghoul::lua::value<double>(L, 3);
|
||||
lua_settop(L, 0);
|
||||
|
||||
glm::dvec2 degrees = icrsToDecimalDegrees(ra, dec);
|
||||
glm::dvec3 pos = icrsToGalacticCartesian(degrees.x, degrees.y, distance);
|
||||
|
||||
ghoul::lua::push(L, pos);
|
||||
|
||||
ghoul_assert(lua_gettop(L) == 1, "Incorrect number of items left on stack");
|
||||
return 1;
|
||||
}
|
||||
|
||||
int convertToRaDec(lua_State* L) {
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 3, "lua::convertToRaDec");
|
||||
|
||||
double x = ghoul::lua::value<double>(L, 1);
|
||||
double y = ghoul::lua::value<double>(L, 2);
|
||||
double z = ghoul::lua::value<double>(L, 3);
|
||||
lua_settop(L, 0);
|
||||
|
||||
glm::dvec3 degrees = galacticCartesianToIcrs(x, y, z);
|
||||
std::pair<std::string, std::string> raDecPair = decimalDegreesToIcrs(degrees.x, degrees.y);
|
||||
|
||||
ghoul::lua::push(L, raDecPair.first); // Ra
|
||||
ghoul::lua::push(L, raDecPair.second); // Dec
|
||||
ghoul::lua::push(L, degrees.z); // Distance
|
||||
|
||||
ghoul_assert(lua_gettop(L) == 3, "Incorrect number of items left on stack");
|
||||
return 3;
|
||||
}
|
||||
|
||||
} // namespace openspace::space::luascriptfunctions
|
||||
Reference in New Issue
Block a user