refactor: remove astro references

removed from:
main.cpp
orbiter.cpp
This commit is contained in:
Cat Flynn 2024-08-18 00:09:44 +01:00
parent a9c836dea0
commit 2059b4ed16
4 changed files with 21 additions and 28 deletions

View File

@ -9,18 +9,19 @@ typedef std::vector<float> Vector6;
class Orbit class Orbit
{ {
public: public:
Orbit(const Vector6 keplerianElements); Orbit(float semiMajorAxis, float eccentricity, float inclination,
float argumentOfPeriapsis, float longitudeOfAscendingNode);
~Orbit() = default; ~Orbit() = default;
float getEccentricity() const;
void setEccentricity(float eccentricity);
// TODO: meanAnomaly in all these arguments actually means eccentricMeanAnomaly, // TODO: meanAnomaly in all these arguments actually means eccentricMeanAnomaly,
// will have to change that when adding non-ellipctical orbits - don't get confused! // will have to change that when adding non-ellipctical orbits - don't get confused!
const glm::vec3 getPosition(const float meanAnomaly) const; const glm::vec3 getPosition(const float meanAnomaly) const;
glm::vec3 getTangent(const float meanAnomaly); glm::vec3 getTangent(const float meanAnomaly);
glm::mat4 getLookAlongMatrix(const float meanAnomaly); glm::mat4 getLookAlongMatrix(const float meanAnomaly);
void setElements(Vector6 keplerianElements);
void getElements(Vector6& keplerianElements) const;
private: private:
Vector6 _keplerianElements; Vector6 _keplerianElements;

View File

@ -5,19 +5,25 @@
#include <glm/gtc/matrix_transform.hpp> #include <glm/gtc/matrix_transform.hpp>
Orbit::Orbit(Vector6 keplerianElements) : Orbit::Orbit(float semiMajorAxis, float eccentricity, float inclination,
_keplerianElements(keplerianElements) 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) glm::mat4 Orbit::getLookAlongMatrix(const float meanAnomaly)

View File

@ -37,7 +37,6 @@
#include <GL/glew.h> #include <GL/glew.h>
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#include <astro/stateVectorIndices.hpp>
#include <iostream> #include <iostream>
#include "gfx.hpp" #include "gfx.hpp"
@ -95,13 +94,7 @@ int main()
// set up scene // set up scene
Icosphere planet(0.2, 3, litProgram); Icosphere planet(0.2, 3, litProgram);
std::vector<float> keplerianElements(6); Orbit orbit(.75f, .5, 3.142 / 2.0 + 1, 2.0, 0);
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);
OrbitVisualizer orbitVisualizer(orbit, unlitProgram); OrbitVisualizer orbitVisualizer(orbit, unlitProgram);
Icosphere orbiterSphere(0.07, 2, litProgram); Icosphere orbiterSphere(0.07, 2, litProgram);

View File

@ -1,7 +1,6 @@
#include "orbiter.hpp" #include "orbiter.hpp"
#include <iostream> #include <iostream>
#include <astro/stateVectorIndices.hpp>
Orbiter::Orbiter(Icosphere& sphere, Orbit& orbit, GLuint shaderProgram) : Orbiter::Orbiter(Icosphere& sphere, Orbit& orbit, GLuint shaderProgram) :
_sphere(sphere), _sphere(sphere),
@ -28,23 +27,17 @@ void Orbiter::cycleAnimation()
glm::vec3 Orbiter::getPosition(const float time) glm::vec3 Orbiter::getPosition(const float time)
{ {
std::vector<float> keplerianElements(6);
_orbit.getElements(keplerianElements);
//int animation = (int)(time/ORBITAL_PERIOD) % 2 == 1; //int animation = (int)(time/ORBITAL_PERIOD) % 2 == 1;
if (_animation == ANIM_ORBITING) if (_animation == ANIM_ORBITING)
return _orbit.getPosition(time); return _orbit.getPosition(time);
// TODO: i want to modify the eccentricity of the orbit with a control, // TODO: modify the eccentricity of the orbit with a control instead
// not an automatic animation // of an automatic animation
if (_animation == ANIM_ECCENTRICITY) if (_animation == ANIM_ECCENTRICITY)
{ {
// TODO: what are these magic numbers
float e = .25 + .2 * sin(time); float e = .25 + .2 * sin(time);
keplerianElements[astro::eccentricityIndex] = e; _orbit.setEccentricity(e);
// TODO: extract set from getter
_orbit.setElements(keplerianElements);
return _orbit.getPosition(0); return _orbit.getPosition(0);
} }