feat: draw orbit with astro
This commit is contained in:
parent
cf5418780b
commit
80ddb7dd82
|
@ -155,7 +155,7 @@ int main()
|
||||||
GLuint unlitProgram = compileShaderProgram("./frag_unlit.glsl");
|
GLuint unlitProgram = compileShaderProgram("./frag_unlit.glsl");
|
||||||
|
|
||||||
Icosphere sphere(0.5, 2);
|
Icosphere sphere(0.5, 2);
|
||||||
Orbit orbit(30, glm::vec3(.5, .5, 0));
|
Orbit orbit(100);
|
||||||
|
|
||||||
// Main loop
|
// Main loop
|
||||||
while (!glfwWindowShouldClose(window))
|
while (!glfwWindowShouldClose(window))
|
||||||
|
|
|
@ -1,28 +1,33 @@
|
||||||
#include "orbit.hpp"
|
#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 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
|
std::vector<float> keplerianElements(6);
|
||||||
glm::quat rot = glm::rotation(worldUp, normalize(up));
|
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++)
|
for (int i = 0; i < vertexCount; i++)
|
||||||
{
|
{
|
||||||
float a = (float)i / (float)vertexCount;
|
float a = (float)i / (float)vertexCount;
|
||||||
a *= 2.0 * pi;
|
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
|
std::vector<float> cartesian = astro::convertKeplerianToCartesianElements(
|
||||||
v = rot * v;
|
keplerianElements,
|
||||||
|
1.0);
|
||||||
|
|
||||||
_vertices.push_back(v.x);
|
_vertices.push_back(cartesian[astro::xPositionIndex]);
|
||||||
_vertices.push_back(v.y);
|
_vertices.push_back(cartesian[astro::yPositionIndex]);
|
||||||
_vertices.push_back(v.z);
|
_vertices.push_back(cartesian[astro::zPositionIndex]);
|
||||||
}
|
}
|
||||||
|
|
||||||
glGenVertexArrays(1, &_vao);
|
glGenVertexArrays(1, &_vao);
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
class Orbit
|
class Orbit
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Orbit(int vertexCount, glm::vec3 up);
|
Orbit(int vertexCount);
|
||||||
void render();
|
void render();
|
||||||
~Orbit();
|
~Orbit();
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in New Issue