feat: add render scale

This commit is contained in:
Cat Flynn 2024-08-21 14:56:56 +01:00
parent 6844f4454c
commit 8d6138f15e
5 changed files with 20 additions and 12 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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;

View File

@ -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

View File

@ -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;
};