feat: draw apo/periapses
This commit is contained in:
parent
7034b1e70c
commit
ab5b400608
|
@ -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);
|
||||
|
|
|
@ -25,5 +25,6 @@ class OrbitVisualizer
|
|||
GLuint _vao;
|
||||
std::vector<float> _vertices;
|
||||
|
||||
glm::dvec3 getPositionOnOrbit(double trueAnomaly) const;
|
||||
void regenerateVertices(const glm::vec3& basePos);
|
||||
};
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue