diff --git a/lib/skein/include/skein/orbit.h b/lib/skein/include/skein/orbit.h index e3f6002..6420c76 100644 --- a/lib/skein/include/skein/orbit.h +++ b/lib/skein/include/skein/orbit.h @@ -9,18 +9,19 @@ typedef std::vector Vector6; class Orbit { public: - Orbit(const Vector6 keplerianElements); + Orbit(float semiMajorAxis, float eccentricity, float inclination, + float argumentOfPeriapsis, float longitudeOfAscendingNode); ~Orbit() = default; + float getEccentricity() const; + void setEccentricity(float eccentricity); + // TODO: meanAnomaly in all these arguments actually means eccentricMeanAnomaly, // will have to change that when adding non-ellipctical orbits - don't get confused! const glm::vec3 getPosition(const float meanAnomaly) const; glm::vec3 getTangent(const float meanAnomaly); glm::mat4 getLookAlongMatrix(const float meanAnomaly); - void setElements(Vector6 keplerianElements); - void getElements(Vector6& keplerianElements) const; - private: Vector6 _keplerianElements; diff --git a/lib/skein/src/orbit.cpp b/lib/skein/src/orbit.cpp index 726f259..1a9335f 100644 --- a/lib/skein/src/orbit.cpp +++ b/lib/skein/src/orbit.cpp @@ -5,19 +5,25 @@ #include -Orbit::Orbit(Vector6 keplerianElements) : - _keplerianElements(keplerianElements) +Orbit::Orbit(float semiMajorAxis, float eccentricity, float inclination, + float argumentOfPeriapsis, float longitudeOfAscendingNode) { + _keplerianElements.resize(6); + _keplerianElements[astro::semiMajorAxisIndex] = semiMajorAxis; + _keplerianElements[astro::eccentricityIndex] = eccentricity; + _keplerianElements[astro::inclinationIndex] = inclination; + _keplerianElements[astro::argumentOfPeriapsisIndex] = argumentOfPeriapsis; + _keplerianElements[astro::longitudeOfAscendingNodeIndex] = semiMajorAxis; } -void Orbit::setElements(Vector6 keplerianElements) +float Orbit::getEccentricity() const { - _keplerianElements = keplerianElements; + return _keplerianElements[astro::eccentricityIndex]; } -void Orbit::getElements(Vector6& keplerianElements) const +void Orbit::setEccentricity(float eccentricity) { - keplerianElements = _keplerianElements; + _keplerianElements[astro::eccentricityIndex] = eccentricity; } glm::mat4 Orbit::getLookAlongMatrix(const float meanAnomaly) diff --git a/src/main.cpp b/src/main.cpp index eb95051..72c147b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -37,7 +37,6 @@ #include #include -#include #include #include "gfx.hpp" @@ -95,13 +94,7 @@ int main() // set up scene Icosphere planet(0.2, 3, litProgram); - std::vector keplerianElements(6); - keplerianElements[astro::semiMajorAxisIndex] = .75; - keplerianElements[astro::eccentricityIndex] = .5; - keplerianElements[astro::inclinationIndex] = 3.142 / 2.0 + 1; - keplerianElements[astro::argumentOfPeriapsisIndex] = 2.0; - keplerianElements[astro::longitudeOfAscendingNodeIndex] = 0; - Orbit orbit(keplerianElements); + Orbit orbit(.75f, .5, 3.142 / 2.0 + 1, 2.0, 0); OrbitVisualizer orbitVisualizer(orbit, unlitProgram); Icosphere orbiterSphere(0.07, 2, litProgram); diff --git a/src/orbiter.cpp b/src/orbiter.cpp index d2fdf2a..0dabbfa 100644 --- a/src/orbiter.cpp +++ b/src/orbiter.cpp @@ -1,7 +1,6 @@ #include "orbiter.hpp" #include -#include Orbiter::Orbiter(Icosphere& sphere, Orbit& orbit, GLuint shaderProgram) : _sphere(sphere), @@ -28,23 +27,17 @@ void Orbiter::cycleAnimation() glm::vec3 Orbiter::getPosition(const float time) { - std::vector keplerianElements(6); - _orbit.getElements(keplerianElements); - //int animation = (int)(time/ORBITAL_PERIOD) % 2 == 1; if (_animation == ANIM_ORBITING) return _orbit.getPosition(time); - // TODO: i want to modify the eccentricity of the orbit with a control, - // not an automatic animation + // TODO: modify the eccentricity of the orbit with a control instead + // of an automatic animation if (_animation == ANIM_ECCENTRICITY) { - // TODO: what are these magic numbers float e = .25 + .2 * sin(time); - keplerianElements[astro::eccentricityIndex] = e; - // TODO: extract set from getter - _orbit.setElements(keplerianElements); + _orbit.setEccentricity(e); return _orbit.getPosition(0); }