feat: inc/dec orbiter velocity
This commit is contained in:
parent
be40086eae
commit
7034b1e70c
|
@ -119,7 +119,14 @@ void ParticleMap::setParticleLocalVelocity(const std::string& id, double time, c
|
||||||
newOrbit.setTrueAnomaly(keplerian[astro::trueAnomalyIndex]);
|
newOrbit.setTrueAnomaly(keplerian[astro::trueAnomalyIndex]);
|
||||||
|
|
||||||
const double newMeanAnomaly = newOrbit.getMeanAnomaly(gravitationalParameter, time);
|
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);
|
newOrbit.setMeanAnomalyAtEpoch(newMeanAnomalyAtEpoch);
|
||||||
|
|
||||||
setRelationship(parentId, id, newOrbit);
|
setRelationship(parentId, id, newOrbit);
|
||||||
|
|
80
src/main.cpp
80
src/main.cpp
|
@ -35,7 +35,8 @@
|
||||||
struct Input
|
struct Input
|
||||||
{
|
{
|
||||||
bool pauseTime;
|
bool pauseTime;
|
||||||
bool updateOrbit;
|
bool prograde;
|
||||||
|
bool retrograde;
|
||||||
} input;
|
} input;
|
||||||
|
|
||||||
|
|
||||||
|
@ -44,14 +45,16 @@ void keyCallback(GLFWwindow* window, int key, int scancode, int action, int mods
|
||||||
if (action == GLFW_PRESS)
|
if (action == GLFW_PRESS)
|
||||||
{
|
{
|
||||||
input.pauseTime = key == GLFW_KEY_SPACE;
|
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()
|
void clearInput()
|
||||||
{
|
{
|
||||||
input.pauseTime = false;
|
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
|
// 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
|
// set parameters of moon's orbit around earth
|
||||||
Orbit moonOrbit;
|
Orbit moonOrbit;
|
||||||
double moonOrbitSemiMajorAxis = 3.84748e8;
|
//double moonOrbitSemiMajorAxis = 3.84748e8;
|
||||||
|
double moonOrbitSemiMajorAxis = 1;
|
||||||
moonOrbit.setSemiMajorAxis(moonOrbitSemiMajorAxis); // metres
|
moonOrbit.setSemiMajorAxis(moonOrbitSemiMajorAxis); // metres
|
||||||
moonOrbit.setEccentricity(0.055);
|
//moonOrbit.setEccentricity(0.055);
|
||||||
moonOrbit.setInclination(glm::radians(5.15)); // radians
|
//moonOrbit.setInclination(glm::radians(5.15)); // radians
|
||||||
moonOrbit.setArgumentOfPeriapsis(318.15); // in the case of the moon these last two values are
|
//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.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);
|
moonOrbit.setTrueAnomaly(0.0);
|
||||||
|
|
||||||
// set parameters of satellite orbit around moon
|
// set parameters of satellite orbit around moon
|
||||||
Orbit stationOrbit;
|
//Orbit stationOrbit;
|
||||||
stationOrbit.setSemiMajorAxis(5e7);
|
//stationOrbit.setSemiMajorAxis(5e7);
|
||||||
stationOrbit.setEccentricity(0.6);
|
//stationOrbit.setEccentricity(0.6);
|
||||||
stationOrbit.setInclination(glm::radians(89.0));
|
//stationOrbit.setInclination(glm::radians(89.0));
|
||||||
stationOrbit.setArgumentOfPeriapsis(43.2);
|
//stationOrbit.setArgumentOfPeriapsis(43.2);
|
||||||
stationOrbit.setLongitudeOfAscendingNode(239.7);
|
//stationOrbit.setLongitudeOfAscendingNode(239.7);
|
||||||
stationOrbit.setTrueAnomaly(0.0);
|
//stationOrbit.setTrueAnomaly(0.0);
|
||||||
|
|
||||||
ParticleMap map;
|
ParticleMap map;
|
||||||
map.setParticle({"earth", 5.9e24});
|
//map.setParticle({"earth", 5.9e24});
|
||||||
map.setParticle({"moon", 7.3e22});
|
//map.setParticle({"moon", 7.3e22});
|
||||||
map.setParticle({"station", 1e6});
|
map.setParticle({"earth", 1});
|
||||||
|
map.setParticle({"moon", .5});
|
||||||
|
//map.setParticle({"station", 1e6});
|
||||||
map.setRelationship("earth", "moon", moonOrbit);
|
map.setRelationship("earth", "moon", moonOrbit);
|
||||||
map.setRelationship("moon", "station", stationOrbit);
|
//map.setRelationship("moon", "station", stationOrbit);
|
||||||
|
|
||||||
float scale = moonOrbitSemiMajorAxis * 1.1;
|
float scale = moonOrbitSemiMajorAxis * 1.1;
|
||||||
ParticleVisualizer earthVis(map, "earth", 0.1, litProgram, unlitProgram, scale);
|
ParticleVisualizer earthVis(map, "earth", 0.1, litProgram, unlitProgram, scale);
|
||||||
ParticleVisualizer moonVis(map, "moon", 0.02, 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 moonOrbitVis(map, "moon", unlitProgram, scale);
|
||||||
OrbitVisualizer stationOrbitVis(map, "station", unlitProgram, scale);
|
//OrbitVisualizer stationOrbitVis(map, "station", unlitProgram, scale);
|
||||||
|
|
||||||
// register input
|
// register input
|
||||||
glfwSetKeyCallback(window, keyCallback);
|
glfwSetKeyCallback(window, keyCallback);
|
||||||
|
@ -166,16 +176,18 @@ int main()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (input.updateOrbit)
|
//glm::dvec3 v = map.getParticleLocalVelocity("station", time);
|
||||||
|
glm::dvec3 v = map.getParticleLocalVelocity("moon", time);
|
||||||
|
if (input.prograde)
|
||||||
{
|
{
|
||||||
|
v *= 1.01;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
else if (input.retrograde)
|
||||||
|
{
|
||||||
|
v *= 0.99;
|
||||||
|
}
|
||||||
|
//map.setParticleLocalVelocity("station", time, v);
|
||||||
|
map.setParticleLocalVelocity("moon", time, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
// rendering
|
// rendering
|
||||||
|
@ -186,17 +198,17 @@ int main()
|
||||||
const Particle& earth = map.getParticle("earth");
|
const Particle& earth = map.getParticle("earth");
|
||||||
const Particle& moon = map.getParticle("moon");
|
const Particle& moon = map.getParticle("moon");
|
||||||
moonOrbit = map.getOrbit("moon");
|
moonOrbit = map.getOrbit("moon");
|
||||||
stationOrbit = map.getOrbit("station");
|
//stationOrbit = map.getOrbit("station");
|
||||||
moonOrbit.update(time, earth.getGravitationalParameter());
|
moonOrbit.update(time, earth.getGravitationalParameter());
|
||||||
stationOrbit.update(time, moon.getGravitationalParameter());
|
//stationOrbit.update(time, moon.getGravitationalParameter());
|
||||||
map.setRelationship("earth", "moon", moonOrbit);
|
map.setRelationship("earth", "moon", moonOrbit);
|
||||||
map.setRelationship("moon", "station", stationOrbit);
|
//map.setRelationship("moon", "station", stationOrbit);
|
||||||
|
|
||||||
earthVis.render(time);
|
earthVis.render(time);
|
||||||
moonVis.render(time);
|
moonVis.render(time);
|
||||||
stationVis.render(time);
|
//stationVis.render(time);
|
||||||
moonOrbitVis.render(time);
|
moonOrbitVis.render(time);
|
||||||
stationOrbitVis.render(time);
|
//stationOrbitVis.render(time);
|
||||||
|
|
||||||
glfwSwapBuffers(window);
|
glfwSwapBuffers(window);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue