From 80ddb7dd8289a44c034d523d56231b02ec1a55ed Mon Sep 17 00:00:00 2001 From: Cat Flynn Date: Sun, 6 Aug 2023 15:20:22 +0200 Subject: [PATCH] feat: draw orbit with astro --- src/hello.cpp | 2 +- src/orbit.cpp | 27 ++++++++++++++++----------- src/orbit.hpp | 2 +- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/hello.cpp b/src/hello.cpp index fcaa096..a783abb 100644 --- a/src/hello.cpp +++ b/src/hello.cpp @@ -155,7 +155,7 @@ int main() GLuint unlitProgram = compileShaderProgram("./frag_unlit.glsl"); Icosphere sphere(0.5, 2); - Orbit orbit(30, glm::vec3(.5, .5, 0)); + Orbit orbit(100); // Main loop while (!glfwWindowShouldClose(window)) diff --git a/src/orbit.cpp b/src/orbit.cpp index 6bee57a..1ed4758 100644 --- a/src/orbit.cpp +++ b/src/orbit.cpp @@ -1,28 +1,33 @@ #include "orbit.hpp" -#include "glm/gtx/quaternion.hpp" +#include "astro/stateVectorIndices.hpp" +#include "astro/orbitalElementConversions.hpp" -Orbit::Orbit(int vertexCount, glm::vec3 up) +Orbit::Orbit(int vertexCount) { const float pi = 3.14159265359; - const glm::vec3 worldUp = glm::vec3(0.0, 1.0, 0.0); - // Compute the rotation between world 'up' and our defined up - glm::quat rot = glm::rotation(worldUp, normalize(up)); + std::vector keplerianElements(6); + keplerianElements[astro::semiMajorAxisIndex] = .75; + keplerianElements[astro::eccentricityIndex] = .1; + keplerianElements[astro::inclinationIndex] = pi / 2.0 + 0.1; + keplerianElements[astro::argumentOfPeriapsisIndex] = 0; + keplerianElements[astro::longitudeOfAscendingNodeIndex] = 0; for (int i = 0; i < vertexCount; i++) { float a = (float)i / (float)vertexCount; a *= 2.0 * pi; - glm::vec3 v = glm::vec3(cos(a), 0.0, sin(a)); + keplerianElements[astro::trueAnomalyIndex] = a; - // Rotate generated point to align with new up vector - v = rot * v; + std::vector cartesian = astro::convertKeplerianToCartesianElements( + keplerianElements, + 1.0); - _vertices.push_back(v.x); - _vertices.push_back(v.y); - _vertices.push_back(v.z); + _vertices.push_back(cartesian[astro::xPositionIndex]); + _vertices.push_back(cartesian[astro::yPositionIndex]); + _vertices.push_back(cartesian[astro::zPositionIndex]); } glGenVertexArrays(1, &_vao); diff --git a/src/orbit.hpp b/src/orbit.hpp index 3bc15d1..a9773e9 100644 --- a/src/orbit.hpp +++ b/src/orbit.hpp @@ -8,7 +8,7 @@ class Orbit { public: - Orbit(int vertexCount, glm::vec3 up); + Orbit(int vertexCount); void render(); ~Orbit(); private: