diff --git a/modules/exoplanets/discoverymethods/discoverymethods.cpp b/modules/exoplanets/discoverymethods/discoverymethods.cpp index 8fc3649195..5be5117a91 100644 --- a/modules/exoplanets/discoverymethods/discoverymethods.cpp +++ b/modules/exoplanets/discoverymethods/discoverymethods.cpp @@ -54,9 +54,10 @@ namespace openspace::exoplanets{ void DiscoveryMethods::addTransitMethodVisualization() { std::string starName = OsEng.moduleEngine().module()->getStarName(); - float planetSemiMajorAxis = (OsEng.moduleEngine().module()->getClosestExoplanet()).A; // AU - float eccentricity = (OsEng.moduleEngine().module()->getClosestExoplanet()).ECC; - float starRadius = (OsEng.moduleEngine().module()->getClosestExoplanet()).RSTAR; // Solar Radii + std::vector planets = OsEng.moduleEngine().module()->getPlsy(); + float planetSemiMajorAxis = planets[0].A; // AU + float eccentricity = planets[0].ECC; + float starRadius = planets[0].RSTAR; // Solar Radii // periapsis radius float periapsisRadius = planetSemiMajorAxis * (1.0 - eccentricity); @@ -82,10 +83,12 @@ namespace openspace::exoplanets{ void DiscoveryMethods::addDopplerMethodVisualization() { std::string starName = OsEng.moduleEngine().module()->getStarName(); - float planetSemiMajorAxis = (OsEng.moduleEngine().module()->getClosestExoplanet()).A; + std::vector planets = OsEng.moduleEngine().module()->getPlsy(); + //float planetSemiMajorAxis = (OsEng.moduleEngine().module()->getClosestExoplanet()).A; + float planetSemiMajorAxis = planets[0].A; float starSemiMajorAxis = 0.1 * planetSemiMajorAxis * 149597871; // 10% of exoplanets semiMajorAxis (get value from em) - float eccentricity = (OsEng.moduleEngine().module()->getClosestExoplanet()).ECC; - float starRadius = (OsEng.moduleEngine().module()->getClosestExoplanet()).RSTAR; // Solar Radii + float eccentricity = planets[0].ECC; + float starRadius = planets[0].RSTAR; // Solar Radii float periapsisRadius = planetSemiMajorAxis * (1.0 - eccentricity); // to km @@ -96,12 +99,14 @@ namespace openspace::exoplanets{ moveCameraDopplerView(); scaleStar(starName + "Globe", scaleFactor); moveStar(starName, starSemiMajorAxis); + toggleVisabilityOuterPlanets("false"); } void DiscoveryMethods::removeDopplerMethodVisualization() { std::string starName = OsEng.moduleEngine().module()->getStarName(); scaleStar(starName + "Globe", 1.0); moveStar(starName, 0.0); + toggleVisabilityOuterPlanets("true"); } void DiscoveryMethods::scaleStar(std::string nodeName, float scalefactor) { @@ -138,6 +143,30 @@ namespace openspace::exoplanets{ OsEng.navigationHandler().resetCameraDirection(); } + + void DiscoveryMethods::toggleVisabilityOuterPlanets(std::string visability) { + //std::vector planets = OsEng.moduleEngine().module()->getPlsy(); + std::vector planetNames = OsEng.moduleEngine().module()->getPlna(); + + if (planetNames.size()>1) + { + //keeping first planet in the list, wich dosn't neccesarily mean the closest one... + for (size_t i = 1; i < planetNames.size(); i++) { + std::string script = ""; + //remove planetglobe + script += "openspace.setPropertyValueSingle( 'Scene." + planetNames[i] + ".renderable.Enabled', "+visability+"); "; + //remove trail + script += "openspace.setPropertyValueSingle( 'Scene." + planetNames[i] + "Trail.renderable.Enabled', " + visability + "); "; + //remove disc + script += "openspace.setPropertyValueSingle( 'Scene."+planetNames[i]+"Disc.renderable.Enabled', " + visability + "); "; + + OsEng.scriptEngine().queueScript( + script, + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); + } + } + } void DiscoveryMethods::moveCameraDopplerView() { @@ -149,8 +178,10 @@ namespace openspace::exoplanets{ glm::dvec3 north = glm::dvec3(0.0, 0.0, 1.0); glm::dvec3 northProjected = glm::normalize(glm::length(north)*glm::sin(glm::dot(north, starToSunVec)) * glm::cross(starToSunVec, glm::cross(north, starToSunVec))); glm::dvec3 faceOnVector = glm::normalize(glm::cross(starToSunVec, northProjected)); - // a position along that vector (twice the semimajor axis away from the sun) - float semiMajorAxis = (OsEng.moduleEngine().module()->getClosestExoplanet()).A; + // a position along that vector (3x the semimajor axis away from the star) + //float semiMajorAxis = (OsEng.moduleEngine().module()->getClosestExoplanet()).A; + std::vector planets = OsEng.moduleEngine().module()->getPlsy(); + float semiMajorAxis = planets[0].A; glm::dvec3 newCameraPosition = starPosition + ((3.0 * semiMajorAxis * 149597870700) * faceOnVector); //move camera to that pos @@ -199,6 +230,7 @@ namespace openspace::exoplanets{ } }); + } } // namespce diff --git a/modules/exoplanets/discoverymethods/discoverymethods.h b/modules/exoplanets/discoverymethods/discoverymethods.h index 18e2b516cf..c340c62e3a 100644 --- a/modules/exoplanets/discoverymethods/discoverymethods.h +++ b/modules/exoplanets/discoverymethods/discoverymethods.h @@ -48,6 +48,7 @@ private: void moveStar(std::string, float); void moveCameraTransitView(); void moveCameraDopplerView(); + void toggleVisabilityOuterPlanets(std::string); }; diff --git a/modules/exoplanets/exoplanetsmodule.cpp b/modules/exoplanets/exoplanetsmodule.cpp index ee3c8c8ecf..0f60d9a86a 100644 --- a/modules/exoplanets/exoplanetsmodule.cpp +++ b/modules/exoplanets/exoplanetsmodule.cpp @@ -53,6 +53,18 @@ void ExoplanetsModule::setStarName(std::string starName) { std::string ExoplanetsModule::getStarName() { return _starName; } +void ExoplanetsModule::setPlsy(std::vector plsy) { + _plsy = plsy; +} +std::vector ExoplanetsModule::getPlsy() { + return _plsy; +} +void ExoplanetsModule::setPlna(std::vector plna) { + _plna = plna; +} +std::vector ExoplanetsModule::getPlna() { + return _plna; +} scripting::LuaLibrary ExoplanetsModule::luaLibrary() const { diff --git a/modules/exoplanets/exoplanetsmodule.h b/modules/exoplanets/exoplanetsmodule.h index e7cd06b2fb..a473ccfc0b 100644 --- a/modules/exoplanets/exoplanetsmodule.h +++ b/modules/exoplanets/exoplanetsmodule.h @@ -93,6 +93,10 @@ public: Exoplanet getClosestExoplanet(); void setStarName(std::string); std::string getStarName(); + void setPlsy(std::vector); + std::vector getPlsy(); + void setPlna(std::vector); + std::vector getPlna(); protected: void internalInitialize(const ghoul::Dictionary&) override; @@ -100,6 +104,8 @@ protected: Exoplanet _exo; std::string _starName; + std::vector _plsy; + std::vector _plna; }; } // namespace openspace diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index b511d39bf2..2f5532f5ef 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -63,12 +63,16 @@ std::string getStarColor(float bv) { return colorString; } -glm::dmat4 computeOrbitPlaneRotationMatrix(float i, float bigom, float om) { +glm::dmat4 computeOrbitPlaneRotationMatrix(float i, float bigom, float om, glm::dmat3 rot) { // Exoplanet defined inclination changed to be used as Kepler defined inclination - const glm::vec3 ascendingNodeAxisRot = { 0.f, 0.f, 1.f }; - const glm::vec3 inclinationAxisRot = { 1.f, 0.f, 0.f }; - const glm::vec3 argPeriapsisAxisRot = { 0.f, 0.f, 1.f }; + const glm::dvec3 ascendingNodeAxisRot = rot * glm::dvec3(0.f, 0.f, 1.f); + const glm::dvec3 inclinationAxisRot = rot * glm::dvec3(1.f, 0.f, 0.f ); + const glm::vec3 argPeriapsisAxisRot = rot * glm::dvec3( 0.f, 0.f, 1.f ); + + /*const glm::vec3 ascendingNodeAxisRot = { 0.f, 0.f, 1.f }; + const glm::vec3 inclinationAxisRot = { 1.f, 0.f, 0.f }; + const glm::vec3 argPeriapsisAxisRot = { 0.f, 0.f, 1.f };*/ const double asc = glm::radians(bigom); const double inc = glm::radians(i); @@ -267,9 +271,11 @@ int addExoplanetSystem(lua_State* L) { } } + data.close(); lut.close(); - + OsEng.moduleEngine().module()->setPlna(plna); + OsEng.moduleEngine().module()->setPlsy(plsy); OsEng.moduleEngine().module()->setClosestExoplanet(p); if (found && !isnan(p.POSITIONX) && !isnan(p.A) && !isnan(p.PER)) //&& !p.BINARY @@ -281,12 +287,14 @@ int addExoplanetSystem(lua_State* L) { glm::dvec3 position = glm::dvec3(p.POSITIONX * parsec , p.POSITIONY * parsec, p.POSITIONZ * parsec); glm::dvec3 starToSunVec = normalize(glm::dvec3(0.0, 0.0, 0.0) - position); - glm::dvec3 north = glm::dvec3(0.0, 0.0, 1.0); + glm::dvec3 northEclipticPole = glm::dvec3(0.0, 0.0, 1.0); // , 1.0); + //glm::dvec3 northCelectialPole = northEclipticPole * glm::rotate(glm::radians(336.6), glm::dvec3(1.f, 0.f, 0.f)); + printf(std::to_string(northEclipticPole).c_str()); // Earths north vector (0,0,1) projected onto the skyplane, the plane perpendicular to the viewing vector (starTosunVec) - glm::dvec3 northProjected = normalize(glm::length(north)*glm::sin(dot(north, starToSunVec)) * glm::cross(starToSunVec, glm::cross(north, starToSunVec))); - + glm::dvec3 northProjected = normalize(glm::length(northEclipticPole)*glm::sin(dot(northEclipticPole, starToSunVec)) * glm::cross(starToSunVec, glm::cross(northEclipticPole, starToSunVec))); + printf(std::to_string(northProjected).c_str()); glm::dmat3 firstRotation = getExoplanetSystemRotation(glm::dvec3(0.0,0.0,1.0), starToSunVec); - glm::dvec3 newX = firstRotation * glm::dvec3(1.0, 0.0, 0.0) ; + glm::dvec3 newX = firstRotation * glm::dvec3(1.0, 0.0, 0.0); glm::dmat3 secondRotation = getExoplanetSystemRotation(newX, northProjected); glm::dmat3 exoplanetSystemRot = secondRotation * firstRotation; @@ -295,9 +303,9 @@ int addExoplanetSystem(lua_State* L) { "Identifier = '" + starname + "'," "Parent = 'SolarSystemBarycenter'," "Transform = {" - "Rotation = {" - "Type = 'StaticRotation'," - "Rotation = " + std::to_string(exoplanetSystemRot) + "," + "Rotation = {" + "Type = 'StaticRotation'," + "Rotation = " + std::to_string(exoplanetSystemRot) + "," "}," "Translation = {" "Type = 'StaticTranslation'," @@ -305,6 +313,7 @@ int addExoplanetSystem(lua_State* L) { "}," "}" "}"; + script = "openspace.addSceneGraphNode(" + starParent + ");"; OsEng.scriptEngine().queueScript( script, @@ -314,25 +323,25 @@ int addExoplanetSystem(lua_State* L) { { std::string color = getStarColor(p.BMV); - if (isnan(p.ECC)) + if (isnan(plsy[0].ECC)) { - p.ECC = 0; + plsy[0].ECC = 0; } - if (isnan(p.I)) + if (isnan(plsy[0].I)) { - p.I = 90; + plsy[0].I = 90; } - if (isnan(p.BIGOM)) + if (isnan(plsy[0].BIGOM)) { - p.BIGOM = 0; + plsy[0].BIGOM = 0; } - if (isnan(p.OM)) + if (isnan(plsy[0].OM)) { - p.OM = 90; + plsy[0].OM = 90; } std::string sepoch_star; - if (!isnan(p.TT)) { - epoch.setTime("JD " + std::to_string(p.TT)); + if (!isnan(plsy[0].TT)) { + epoch.setTime("JD " + std::to_string(plsy[0].TT)); sepoch_star = epoch.ISO8601(); } else @@ -370,14 +379,14 @@ int addExoplanetSystem(lua_State* L) { "}," "Translation = {" "Type = 'KeplerTranslation'," - "Eccentricity = " + std::to_string(p.ECC) + "," //ECC + "Eccentricity = " + std::to_string(plsy[0].ECC) + "," //ECC "SemiMajorAxis = 0," // 149 597 871km = 1 AU. A - "Inclination = " + std::to_string(p.I) + "," //I - "AscendingNode = " + std::to_string(p.BIGOM) + "," //BIGOM - "ArgumentOfPeriapsis = " + std::to_string(p.OM) + "," //OM + "Inclination = " + std::to_string(plsy[0].I) + "," //I + "AscendingNode = " + std::to_string(plsy[0].BIGOM) + "," //BIGOM + "ArgumentOfPeriapsis = " + std::to_string(plsy[0].OM) + "," //OM "MeanAnomaly = 180.0," "Epoch = '" + sepoch_star + "'," //TT. JD to YYYY MM DD hh:mm:ss - "Period = " + std::to_string(p.PER) + "* 86400" //PER. 86 400sec = 1 day. + "Period = " + std::to_string(plsy[0].PER) + "* 86400" //PER. 86 400sec = 1 day. "}" "}" "}"; @@ -445,6 +454,7 @@ int addExoplanetSystem(lua_State* L) { const std::string planet = "{" "Identifier = '" + plna[i] + "'," "Parent = '" + starname + "'," + "Enabled = true," "Renderable = {" "Type = 'RenderableGlobe'," "Radii = " + std::to_string(plsy[i].R) + " *7.1492E7," //R. in meters. 1 jupiter radii = 7.1492×10e7 m @@ -492,6 +502,7 @@ int addExoplanetSystem(lua_State* L) { const std::string planetTrail = "{" "Identifier = '" + plna[i] + "Trail'," "Parent = '" + starname + "'," + "Enabled = true," "Renderable = {" "Type = 'RenderableTrailOrbit'," "Period = " + std::to_string(plsy[i].PER) + "," @@ -519,13 +530,13 @@ int addExoplanetSystem(lua_State* L) { if (!isnan(plsy[i].AUPPER) && !isnan(plsy[i].ALOWER)) { // Get the orbit plane that the trail orbit and planet have from the KeplerTranslation - glm::dmat4 orbitPlaneRotationMatrix = computeOrbitPlaneRotationMatrix(plsy[i].I, plsy[i].BIGOM, plsy[i].OM); - glm::dmat4 exoplanetSystemRotInverse = transpose(exoplanetSystemRot); - glm::dmat3 rot = glm::dmat4(exoplanetSystemRot) * orbitPlaneRotationMatrix * exoplanetSystemRotInverse; + glm::dmat4 orbitPlaneRotationMatrix = computeOrbitPlaneRotationMatrix(plsy[i].I, plsy[i].BIGOM, plsy[i].OM, exoplanetSystemRot); + glm::dmat3 rot = orbitPlaneRotationMatrix; const std::string disc = "{" "Identifier = '" + plna[i] + "Disc'," "Parent = '" + starname + "'," + "Enabled = true," "Renderable = {" "Type = 'RenderableOrbitdisc'," "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/disc.png'," @@ -558,21 +569,21 @@ int addExoplanetSystem(lua_State* L) { "Identifier = '" + plna[i] + "discECCLOWER'," "Parent = '" + starname + "'," "Renderable = {" - "Type = 'RenderableOrbitdisc'," - "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/discL.png'," - "Size = " + std::to_string(plsy[i].A) + " * 149597870700," // 149 597 870 700 m = 1 AU. A - "Eccentricity = " + std::to_string(lower_ecc) + "," - "Offset = { " + std::to_string(plsy[i].ALOWER) + ", " + std::to_string(plsy[i].AUPPER) + " }," //min / max extend - "Transparency = 0.98," - "Enabled = false" + "Type = 'RenderableOrbitdisc'," + "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/discL.png'," + "Size = " + std::to_string(plsy[i].A) + " * 149597870700," // 149 597 870 700 m = 1 AU. A + "Eccentricity = " + std::to_string(lower_ecc) + "," + "Offset = { " + std::to_string(plsy[i].ALOWER) + ", " + std::to_string(plsy[i].AUPPER) + " }," //min / max extend + "Transparency = 0.98," + "Enabled = false" "}," "Transform = {" - "Rotation = {" - "Type = 'StaticRotation'," - "Rotation = " + std::to_string(rot) + "," - "}" + "Rotation = {" + "Type = 'StaticRotation'," + "Rotation = " + std::to_string(rot) + "," + "}" "}," - "}"; + "}"; OsEng.scriptEngine().queueScript( @@ -589,21 +600,21 @@ int addExoplanetSystem(lua_State* L) { "Identifier = '" + plna[i] + "discECCUPPER'," "Parent = '" + starname + "'," "Renderable = {" - "Type = 'RenderableOrbitdisc'," - "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/discU.png'," - "Size = " + std::to_string(plsy[i].A) + " * 149597870700," // 149 597 870 700 m = 1 AU. A - "Eccentricity = " + std::to_string(upper_ecc) + "," - "Offset = { " + std::to_string(plsy[i].ALOWER) + ", " + std::to_string(plsy[i].AUPPER) + " }," //min / max extend - "Transparency = 0.98," - "Enabled = false" + "Type = 'RenderableOrbitdisc'," + "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/discU.png'," + "Size = " + std::to_string(plsy[i].A) + " * 149597870700," // 149 597 870 700 m = 1 AU. A + "Eccentricity = " + std::to_string(upper_ecc) + "," + "Offset = { " + std::to_string(plsy[i].ALOWER) + ", " + std::to_string(plsy[i].AUPPER) + " }," //min / max extend + "Transparency = 0.98," + "Enabled = false" "}," "Transform = {" - "Rotation = {" - "Type = 'StaticRotation'," - "Rotation = " + std::to_string(rot) + "," - "}" + "Rotation = {" + "Type = 'StaticRotation'," + "Rotation = " + std::to_string(rot) + "," + "}" "}," - "}"; + "}"; OsEng.scriptEngine().queueScript(