diff --git a/lib/skein/src/particlemap.cpp b/lib/skein/src/particlemap.cpp index b0320e8..ce6633e 100644 --- a/lib/skein/src/particlemap.cpp +++ b/lib/skein/src/particlemap.cpp @@ -119,7 +119,14 @@ void ParticleMap::setParticleLocalVelocity(const std::string& id, double time, c newOrbit.setTrueAnomaly(keplerian[astro::trueAnomalyIndex]); const double newMeanAnomaly = newOrbit.getMeanAnomaly(gravitationalParameter, time); - const double newMeanAnomalyAtEpoch = originalMeanAnomalyAtEpoch - (newMeanAnomaly - originalMeanAnomaly); + const double meanAnomalyShift = newMeanAnomaly - originalMeanAnomaly; + const double periapsisShift = newOrbit.getArgumentOfPeriapsis() - orbit.getArgumentOfPeriapsis(); + //const double ascendingNodeShift = newOrbit.getLongitudeOfAscendingNode() - orbit.getLongitudeOfAscendingNode(); + + const double newMeanAnomalyAtEpoch = originalMeanAnomalyAtEpoch + - meanAnomalyShift + - periapsisShift; + //- ascendingNodeShift; newOrbit.setMeanAnomalyAtEpoch(newMeanAnomalyAtEpoch); setRelationship(parentId, id, newOrbit); diff --git a/src/main.cpp b/src/main.cpp index 93a5e45..c4aab42 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -35,7 +35,8 @@ struct Input { bool pauseTime; - bool updateOrbit; + bool prograde; + bool retrograde; } input; @@ -44,14 +45,16 @@ void keyCallback(GLFWwindow* window, int key, int scancode, int action, int mods if (action == GLFW_PRESS) { input.pauseTime = key == GLFW_KEY_SPACE; - input.updateOrbit = key == GLFW_KEY_W; + input.prograde = key == GLFW_KEY_W; + input.retrograde = key == GLFW_KEY_S; } } void clearInput() { input.pauseTime = false; - input.updateOrbit = false; + input.prograde = false; + input.retrograde = false; } // now should always increase linearly with real world time, this should not be modified by input @@ -88,36 +91,43 @@ int main() // set parameters of moon's orbit around earth Orbit moonOrbit; - double moonOrbitSemiMajorAxis = 3.84748e8; + //double moonOrbitSemiMajorAxis = 3.84748e8; + double moonOrbitSemiMajorAxis = 1; moonOrbit.setSemiMajorAxis(moonOrbitSemiMajorAxis); // metres - moonOrbit.setEccentricity(0.055); - moonOrbit.setInclination(glm::radians(5.15)); // radians - moonOrbit.setArgumentOfPeriapsis(318.15); // in the case of the moon these last two values are - moonOrbit.setLongitudeOfAscendingNode(60.0); // pretty much constantly changing so use whatever + //moonOrbit.setEccentricity(0.055); + //moonOrbit.setInclination(glm::radians(5.15)); // radians + //moonOrbit.setArgumentOfPeriapsis(318.15); // in the case of the moon these last two values are + //moonOrbit.setLongitudeOfAscendingNode(60.0); // pretty much constantly changing so use whatever + moonOrbit.setEccentricity(0.01); + moonOrbit.setInclination(0.0); + moonOrbit.setArgumentOfPeriapsis(0.0); + moonOrbit.setLongitudeOfAscendingNode(0.0); moonOrbit.setTrueAnomaly(0.0); // set parameters of satellite orbit around moon - Orbit stationOrbit; - stationOrbit.setSemiMajorAxis(5e7); - stationOrbit.setEccentricity(0.6); - stationOrbit.setInclination(glm::radians(89.0)); - stationOrbit.setArgumentOfPeriapsis(43.2); - stationOrbit.setLongitudeOfAscendingNode(239.7); - stationOrbit.setTrueAnomaly(0.0); + //Orbit stationOrbit; + //stationOrbit.setSemiMajorAxis(5e7); + //stationOrbit.setEccentricity(0.6); + //stationOrbit.setInclination(glm::radians(89.0)); + //stationOrbit.setArgumentOfPeriapsis(43.2); + //stationOrbit.setLongitudeOfAscendingNode(239.7); + //stationOrbit.setTrueAnomaly(0.0); ParticleMap map; - map.setParticle({"earth", 5.9e24}); - map.setParticle({"moon", 7.3e22}); - map.setParticle({"station", 1e6}); + //map.setParticle({"earth", 5.9e24}); + //map.setParticle({"moon", 7.3e22}); + map.setParticle({"earth", 1}); + map.setParticle({"moon", .5}); + //map.setParticle({"station", 1e6}); map.setRelationship("earth", "moon", moonOrbit); - map.setRelationship("moon", "station", stationOrbit); + //map.setRelationship("moon", "station", stationOrbit); float scale = moonOrbitSemiMajorAxis * 1.1; ParticleVisualizer earthVis(map, "earth", 0.1, litProgram, unlitProgram, scale); ParticleVisualizer moonVis(map, "moon", 0.02, litProgram, unlitProgram, scale); - ParticleVisualizer stationVis(map, "station", 0.01, litProgram, unlitProgram, scale); + //ParticleVisualizer stationVis(map, "station", 0.01, litProgram, unlitProgram, scale); OrbitVisualizer moonOrbitVis(map, "moon", unlitProgram, scale); - OrbitVisualizer stationOrbitVis(map, "station", unlitProgram, scale); + //OrbitVisualizer stationOrbitVis(map, "station", unlitProgram, scale); // register input glfwSetKeyCallback(window, keyCallback); @@ -166,16 +176,18 @@ int main() } else { - if (input.updateOrbit) + //glm::dvec3 v = map.getParticleLocalVelocity("station", time); + glm::dvec3 v = map.getParticleLocalVelocity("moon", time); + if (input.prograde) { - - const glm::dvec3 p = map.getParticleLocalPosition("station", time); - - const glm::dvec3 v = map.getParticleLocalVelocity("station", time); - const glm::dvec3 newVelocity = v * 0.99; - - map.setParticleLocalVelocity("station", time, newVelocity); + v *= 1.01; } + else if (input.retrograde) + { + v *= 0.99; + } + //map.setParticleLocalVelocity("station", time, v); + map.setParticleLocalVelocity("moon", time, v); } // rendering @@ -186,17 +198,17 @@ int main() const Particle& earth = map.getParticle("earth"); const Particle& moon = map.getParticle("moon"); moonOrbit = map.getOrbit("moon"); - stationOrbit = map.getOrbit("station"); + //stationOrbit = map.getOrbit("station"); moonOrbit.update(time, earth.getGravitationalParameter()); - stationOrbit.update(time, moon.getGravitationalParameter()); + //stationOrbit.update(time, moon.getGravitationalParameter()); map.setRelationship("earth", "moon", moonOrbit); - map.setRelationship("moon", "station", stationOrbit); + //map.setRelationship("moon", "station", stationOrbit); earthVis.render(time); moonVis.render(time); - stationVis.render(time); + //stationVis.render(time); moonOrbitVis.render(time); - stationOrbitVis.render(time); + //stationOrbitVis.render(time); glfwSwapBuffers(window); }