mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-25 21:48:57 -05:00
WIP: getting position of star from stars.speck
This commit is contained in:
@@ -32,10 +32,96 @@
|
||||
|
||||
#include <ghoul/misc/assert.h>
|
||||
|
||||
#include <fstream>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
ExoplanetsModule::ExoplanetsModule() : OpenSpaceModule(Name) {}
|
||||
|
||||
std::vector<float> 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 '{}'";
|
||||
}
|
||||
|
||||
int _nValuesPerStar = 0;
|
||||
|
||||
// The beginning of the speck file has a header that either contains comments
|
||||
// (signaled by a preceding '#') or information about the structure of the file
|
||||
// (signaled by the keywords 'datavar', 'texturevar', and 'texture')
|
||||
std::string line = "";
|
||||
while (true) {
|
||||
std::streampos position = file.tellg();
|
||||
std::getline(file, line);
|
||||
|
||||
if (line[0] == '#' || line.empty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (line.substr(0, 7) != "datavar" &&
|
||||
line.substr(0, 10) != "texturevar" &&
|
||||
line.substr(0, 7) != "texture")
|
||||
{
|
||||
// we read a line that doesn't belong to the header, so we have to jump back
|
||||
// before the beginning of the current line
|
||||
file.seekg(position);
|
||||
break;
|
||||
}
|
||||
|
||||
if (line.substr(0, 7) == "datavar") {
|
||||
// datavar lines are structured as follows:
|
||||
// datavar # description
|
||||
// where # is the index of the data variable; so if we repeatedly overwrite
|
||||
// the 'nValues' variable with the latest index, we will end up with the total
|
||||
// number of values (+3 since X Y Z are not counted in the Speck file index)
|
||||
std::stringstream str(line);
|
||||
|
||||
std::string dummy;
|
||||
str >> dummy;
|
||||
str >> _nValuesPerStar;
|
||||
_nValuesPerStar += 1; // We want the number, but the index is 0 based
|
||||
}
|
||||
}
|
||||
|
||||
_nValuesPerStar += 3; // X Y Z are not counted in the Speck file indices
|
||||
|
||||
do {
|
||||
std::vector<float> values(_nValuesPerStar);
|
||||
|
||||
std::getline(file, line);
|
||||
std::stringstream str(line);
|
||||
|
||||
for (int i = 0; i < _nValuesPerStar; ++i) {
|
||||
str >> values[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<std::string> names;
|
||||
|
||||
while (namestr >> value) {
|
||||
if (value == "#" || value == "|")
|
||||
continue;
|
||||
else {
|
||||
names.push_back(value);
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < names.size(); ++i) {
|
||||
if (!names[i].empty() && names[i].compare(starname) == 0) {
|
||||
return values;
|
||||
}
|
||||
}
|
||||
|
||||
} while (!file.eof());
|
||||
|
||||
}
|
||||
|
||||
int addNode(lua_State* L) {
|
||||
|
||||
// get name of star and add a node at the position of the star.
|
||||
@@ -47,15 +133,17 @@ int addNode(lua_State* L) {
|
||||
const int StringLocation = -1; //first argument
|
||||
const std::string starname = luaL_checkstring(L, StringLocation);
|
||||
|
||||
//printf(starname.c_str());
|
||||
std::vector<float> 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 = {4662120063743.592773, 1263245003503.724854, -955413856565.788086} } }}"; // positionen must be gathered from star.speck
|
||||
//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
|
||||
);
|
||||
);
|
||||
|
||||
// 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' } }";
|
||||
@@ -65,7 +153,6 @@ int addNode(lua_State* L) {
|
||||
openspace::scripting::ScriptEngine::RemoteScripting::Yes
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
scripting::LuaLibrary ExoplanetsModule::luaLibrary() const {
|
||||
@@ -78,7 +165,7 @@ scripting::LuaLibrary ExoplanetsModule::luaLibrary() const {
|
||||
&addNode,
|
||||
{},
|
||||
"string",
|
||||
"Adds print message."
|
||||
"Adds two nodes to the scenegraph, one position node and one node to represenet the star."
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user