diff --git a/src/main.cpp b/src/main.cpp index 992a39c..4df46cf 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -103,9 +103,8 @@ int main() // set parameters of moon's orbit around earth Orbit orbit; - orbit.setSemiMajorAxis(1.0); // in km - // TODO: implement zoom - //orbit.setSemiMajorAxis(384748); // in km + double semiMajorAxis = 3.84748e9; + orbit.setSemiMajorAxis(semiMajorAxis); // metres orbit.setEccentricity(0.055); orbit.setInclination(glm::radians(5.15)); // radians? orbit.setArgumentOfPeriapsis(318.15); // in the case of the moon these last two values are @@ -117,9 +116,10 @@ int main() map.setParticle({"earth", 5.9e24}); map.setParticle({"moon", 7.3e22}); map.setRelationship("earth", "moon", orbit); - ParticleVisualizer earthVis(map, "earth", 0.2, litProgram, unlitProgram); - ParticleVisualizer moonVis(map, "moon", 0.1, litProgram, unlitProgram); - OrbitVisualizer orbitVis(orbit, unlitProgram); + float scale = semiMajorAxis * 1.1; + ParticleVisualizer earthVis(map, "earth", 0.2, litProgram, unlitProgram, scale); + ParticleVisualizer moonVis(map, "moon", 0.1, litProgram, unlitProgram, scale); + OrbitVisualizer orbitVis(orbit, unlitProgram, scale); // register input glfwSetKeyCallback(window, keyCallback); diff --git a/src/orbitvisualizer.cpp b/src/orbitvisualizer.cpp index 03a4e58..258f970 100644 --- a/src/orbitvisualizer.cpp +++ b/src/orbitvisualizer.cpp @@ -1,8 +1,8 @@ #include "orbitvisualizer.hpp" #include "gfx.hpp" -OrbitVisualizer::OrbitVisualizer(const Orbit& orbit, const GLuint shaderProgram) - : _orbit(orbit), _shaderProgram(shaderProgram) +OrbitVisualizer::OrbitVisualizer(const Orbit& orbit, const GLuint shaderProgram, float scale) + : _orbit(orbit), _shaderProgram(shaderProgram), _scale(scale) { glGenVertexArrays(1, &_vao); glGenBuffers(1, &_vbo); @@ -36,6 +36,8 @@ void OrbitVisualizer::regenerateVertices() pos.y = y; pos.z *= -1; + pos /= _scale; + _vertices.push_back(pos.x); _vertices.push_back(pos.y); _vertices.push_back(pos.z); diff --git a/src/orbitvisualizer.hpp b/src/orbitvisualizer.hpp index fb925b3..db9be6a 100644 --- a/src/orbitvisualizer.hpp +++ b/src/orbitvisualizer.hpp @@ -7,7 +7,7 @@ class OrbitVisualizer { public: - OrbitVisualizer(const Orbit& orbit, const GLuint shaderProgram); + OrbitVisualizer(const Orbit& orbit, const GLuint shaderProgram, float scale); ~OrbitVisualizer(); void render(const float time); @@ -18,6 +18,7 @@ class OrbitVisualizer const int _vertexCount = 100; const GLuint _shaderProgram; const Orbit& _orbit; + const float _scale; GLuint _vbo; GLuint _vao; diff --git a/src/particlevisualizer.cpp b/src/particlevisualizer.cpp index 9d83445..82fa1bf 100644 --- a/src/particlevisualizer.cpp +++ b/src/particlevisualizer.cpp @@ -1,8 +1,9 @@ #include "particlevisualizer.hpp" ParticleVisualizer::ParticleVisualizer(const ParticleMap& map, const std::string& particleId, float radius, - GLuint sphereShaderProgram, GLuint widgetShaderProgram) - : _map(map), _particleId(particleId), _sphere({radius, 2, sphereShaderProgram}), _widget(widgetShaderProgram) + GLuint sphereShaderProgram, GLuint widgetShaderProgram, float scale) + : _map(map), _particleId(particleId), _sphere({radius, 2, sphereShaderProgram}), + _widget(widgetShaderProgram), _scale(scale) { } @@ -16,6 +17,8 @@ void ParticleVisualizer::render(float time) pos.y = y; pos.z *= -1; + pos /= _scale; + // TODO: extract widget to its own visualizer since we know it wants an orbit but we // might not have one here //// render widget diff --git a/src/particlevisualizer.hpp b/src/particlevisualizer.hpp index d16c987..2cce070 100644 --- a/src/particlevisualizer.hpp +++ b/src/particlevisualizer.hpp @@ -8,7 +8,8 @@ class ParticleVisualizer { public: - ParticleVisualizer(const ParticleMap& map, const std::string& particleId, float radius, GLuint sphereShaderProgram, GLuint widgetShaderProgram); + ParticleVisualizer(const ParticleMap& map, const std::string& particleId, float radius, + GLuint sphereShaderProgram, GLuint widgetShaderProgram, float scale); ~ParticleVisualizer() = default; void render(float time); @@ -18,6 +19,7 @@ class ParticleVisualizer const ParticleMap& _map; const std::string _particleId; + const float _scale; Icosphere _sphere; Widget _widget; };