From ab5b40060861fd86759830a9a3eb39c17896d146 Mon Sep 17 00:00:00 2001 From: Cat Flynn Date: Sun, 29 Sep 2024 00:17:18 +0100 Subject: [PATCH] feat: draw apo/periapses --- src/orbitvisualizer.cpp | 37 ++++++++++++++++++++++++------------- src/orbitvisualizer.hpp | 1 + src/particlevisualizer.cpp | 7 ------- 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/orbitvisualizer.cpp b/src/orbitvisualizer.cpp index a45c4a1..91b9593 100644 --- a/src/orbitvisualizer.cpp +++ b/src/orbitvisualizer.cpp @@ -1,5 +1,6 @@ #include "orbitvisualizer.hpp" #include "gfx.hpp" +#include "icosphere.hpp" OrbitVisualizer::OrbitVisualizer(const ParticleMap& map, const std::string& particleId, const GLuint shaderProgram, float scale) : _map(map), _particleId(particleId), _shaderProgram(shaderProgram), _scale(scale) @@ -23,12 +24,32 @@ void OrbitVisualizer::render(const float time) glBindBuffer(GL_ARRAY_BUFFER, _vbo); glDrawArrays(GL_LINE_LOOP, 0, _vertices.size() / 3); + + glm::dvec3 position; + + Icosphere apoapsis(0.01, 2, _shaderProgram); + position = getPositionOnOrbit(3.142); + position /= _scale; + apoapsis.setPosition(position); + apoapsis.render(time); + + Icosphere periapsis(0.01, 2, _shaderProgram); + position = getPositionOnOrbit(0.0); + position /= _scale; + periapsis.setPosition(position); + periapsis.render(time); + +} + +glm::dvec3 OrbitVisualizer::getPositionOnOrbit(double trueAnomaly) const +{ + Orbit orbit(_map.getOrbit(_particleId)); + orbit.setTrueAnomaly(trueAnomaly); + return orbit.getPosition(1); } void OrbitVisualizer::regenerateVertices(const glm::vec3& basePos) { - Orbit orbit(_map.getOrbit(_particleId)); - _vertices.clear(); for (int i = 0; i < _vertexCount; i++) { @@ -36,18 +57,8 @@ void OrbitVisualizer::regenerateVertices(const glm::vec3& basePos) // better to actually create a first-class ellipse object and use that to generate // a nice continuous mesh, instead of using orbital positions. float t = (float)i / (float)_vertexCount * 2.0 * _pi; - orbit.setTrueAnomaly(t); - //glm::vec3 pos = orbit.getPositionFromMeanAnomaly(t, 1); - glm::vec3 pos = orbit.getPosition(1); + glm::vec3 pos = getPositionOnOrbit(t); pos += basePos; - - // Vertices come out of the library with X and Y being in the 'flat' plane. Re-order them - // here such that Z is up. - float y = pos.z; - pos.z = pos.y; - pos.y = y; - pos.z *= -1; - pos /= _scale; _vertices.push_back(pos.x); diff --git a/src/orbitvisualizer.hpp b/src/orbitvisualizer.hpp index 9b9783a..c3b66e9 100644 --- a/src/orbitvisualizer.hpp +++ b/src/orbitvisualizer.hpp @@ -25,5 +25,6 @@ class OrbitVisualizer GLuint _vao; std::vector _vertices; + glm::dvec3 getPositionOnOrbit(double trueAnomaly) const; void regenerateVertices(const glm::vec3& basePos); }; diff --git a/src/particlevisualizer.cpp b/src/particlevisualizer.cpp index 3f1fd22..edb431e 100644 --- a/src/particlevisualizer.cpp +++ b/src/particlevisualizer.cpp @@ -9,14 +9,7 @@ ParticleVisualizer::ParticleVisualizer(const ParticleMap& map, const std::string void ParticleVisualizer::render(float time) { - // TODO: get mean anomly from particle which has the mass!! - //const float meanAnomaly = time; glm::vec3 pos = _map.getParticlePosition(_particleId); - float y = pos.z; - pos.z = pos.y; - pos.y = y; - pos.z *= -1; - pos /= _scale; // TODO: extract widget to its own visualizer since we know it wants an orbit but we