From fdf8038306f921bb4e23a13059ebe9ca6947f3d4 Mon Sep 17 00:00:00 2001 From: KarRei Date: Mon, 19 Mar 2018 13:59:07 -0400 Subject: [PATCH] lua function adds nodes to place star at position stated in star.speck --- modules/exoplanets/exoplanetsmodule.cpp | 77 +++++++++++++++---------- 1 file changed, 46 insertions(+), 31 deletions(-) diff --git a/modules/exoplanets/exoplanetsmodule.cpp b/modules/exoplanets/exoplanetsmodule.cpp index be8a0551a0..ba970d2fa4 100644 --- a/modules/exoplanets/exoplanetsmodule.cpp +++ b/modules/exoplanets/exoplanetsmodule.cpp @@ -41,7 +41,7 @@ ExoplanetsModule::ExoplanetsModule() : OpenSpaceModule(Name) {} std::vector readSpeckFile(std::string starname) { std::ifstream file("C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/stars.speck"); if (!file.good()) { - std::cout << "Failed to open Speck file '{}'"; + std::cout << "Failed to open Speck file"; } int _nValuesPerStar = 0; @@ -84,25 +84,24 @@ std::vector readSpeckFile(std::string starname) { } _nValuesPerStar += 3; // X Y Z are not counted in the Speck file indices + std::vector coords; do { - std::vector values(_nValuesPerStar); + std::vector temp(_nValuesPerStar); std::getline(file, line); std::stringstream str(line); for (int i = 0; i < _nValuesPerStar; ++i) { - str >> values[i]; + str >> temp[i]; } std::string next; std::getline(str, next); std::stringstream namestr(next); - // 1. ignore first # - // 2. push all names in the rest of the stream to a array std::string value; - std::vector names; + std::vector names; while (namestr >> value) { if (value == "#" || value == "|") @@ -113,45 +112,61 @@ std::vector readSpeckFile(std::string starname) { } for (size_t i = 0; i < names.size(); ++i) { - if (!names[i].empty() && names[i].compare(starname) == 0) { - return values; + if (names[i].compare(starname) == 0) { + for (int i = 0; i < 3; i++) { + coords.push_back(temp[i]); + } + return coords; } } } while (!file.eof()); + return coords; } int addNode(lua_State* L) { - // get name of star and add a node at the position of the star. - // position is found in the star-files - // after the node has been added one should be able to select it as a focus point. - - //start - - const int StringLocation = -1; //first argument + const int StringLocation = -1; const std::string starname = luaL_checkstring(L, StringLocation); std::vector values = readSpeckFile(starname); - printf(std::to_string(values[0]).c_str()); - // adding the parent node of the exoplanet system - //const std::string luaTableParent = "{ Name = '" + starname +"', Parent = 'SolarSystemBarycenter', Transform = { Translation = { Type = 'StaticTranslation', Position = {" + std::to_string(values[0]) + ", " + std::to_string(values[1]) + ", " + std::to_string(values[2]) + "} } }}"; // positionen must be gathered from star.speck - const std::string luaTableParent = "{ Name = '" + starname + "', Parent = 'SolarSystemBarycenter', Transform = { Translation = { Type = 'StaticTranslation', Position = { -6.5825, -1.6713, 25.2259} } }}"; - const std::string scriptParent = "openspace.addSceneGraphNode("+ luaTableParent +");"; - OsEng.scriptEngine().queueScript( - scriptParent, - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); + if (!values.empty()) + { + double parsecinmeter = 3.08567758*10e16; - // adding a renderable in the place of the stars - const std::string luaTableStarGlare = "{ Name = '" + starname + "Plane', Parent = '" + starname +"', Renderable = { Type = 'RenderablePlaneImageLocal', Size = 1.3*10^10.5, Billboard = true, Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/glare.png', BlendMode = 'Additive' } }"; - const std::string scriptGlare= "openspace.addSceneGraphNode("+ luaTableStarGlare +");"; - OsEng.scriptEngine().queueScript( - scriptGlare, - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); + const std::string luaTableParent = "{" + "Name = '" + starname + "'," + "Parent = 'SolarSystemBarycenter'," + "Transform = {" + "Translation = {" + "Type = 'StaticTranslation'," + "Position = {" + std::to_string(values[0] * parsecinmeter) + ", " + std::to_string(values[1] * parsecinmeter) + ", " + std::to_string(values[2] * parsecinmeter) + "}" + "}" + "}" + "}"; + const std::string luaTableStarGlare = "{" + "Name = '" + starname + "Plane'," + "Parent = '" + starname + "'," + "Renderable = {" + "Type = 'RenderablePlaneImageLocal'," + "Size = 1.3*10^10.5," + "Billboard = true," + "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/glare.png'," + "BlendMode = 'Additive'" + "}" + "}"; + const std::string scriptParent = "openspace.addSceneGraphNode(" + luaTableParent + "); openspace.addSceneGraphNode(" + luaTableStarGlare + ");"; + OsEng.scriptEngine().queueScript( + scriptParent, + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); + } + else + { + printf("No star with that name."); + } }