feat: add render scale
This commit is contained in:
parent
6844f4454c
commit
8d6138f15e
12
src/main.cpp
12
src/main.cpp
|
@ -103,9 +103,8 @@ int main()
|
||||||
|
|
||||||
// set parameters of moon's orbit around earth
|
// set parameters of moon's orbit around earth
|
||||||
Orbit orbit;
|
Orbit orbit;
|
||||||
orbit.setSemiMajorAxis(1.0); // in km
|
double semiMajorAxis = 3.84748e9;
|
||||||
// TODO: implement zoom
|
orbit.setSemiMajorAxis(semiMajorAxis); // metres
|
||||||
//orbit.setSemiMajorAxis(384748); // in km
|
|
||||||
orbit.setEccentricity(0.055);
|
orbit.setEccentricity(0.055);
|
||||||
orbit.setInclination(glm::radians(5.15)); // radians?
|
orbit.setInclination(glm::radians(5.15)); // radians?
|
||||||
orbit.setArgumentOfPeriapsis(318.15); // in the case of the moon these last two values are
|
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({"earth", 5.9e24});
|
||||||
map.setParticle({"moon", 7.3e22});
|
map.setParticle({"moon", 7.3e22});
|
||||||
map.setRelationship("earth", "moon", orbit);
|
map.setRelationship("earth", "moon", orbit);
|
||||||
ParticleVisualizer earthVis(map, "earth", 0.2, litProgram, unlitProgram);
|
float scale = semiMajorAxis * 1.1;
|
||||||
ParticleVisualizer moonVis(map, "moon", 0.1, litProgram, unlitProgram);
|
ParticleVisualizer earthVis(map, "earth", 0.2, litProgram, unlitProgram, scale);
|
||||||
OrbitVisualizer orbitVis(orbit, unlitProgram);
|
ParticleVisualizer moonVis(map, "moon", 0.1, litProgram, unlitProgram, scale);
|
||||||
|
OrbitVisualizer orbitVis(orbit, unlitProgram, scale);
|
||||||
|
|
||||||
// register input
|
// register input
|
||||||
glfwSetKeyCallback(window, keyCallback);
|
glfwSetKeyCallback(window, keyCallback);
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
#include "orbitvisualizer.hpp"
|
#include "orbitvisualizer.hpp"
|
||||||
#include "gfx.hpp"
|
#include "gfx.hpp"
|
||||||
|
|
||||||
OrbitVisualizer::OrbitVisualizer(const Orbit& orbit, const GLuint shaderProgram)
|
OrbitVisualizer::OrbitVisualizer(const Orbit& orbit, const GLuint shaderProgram, float scale)
|
||||||
: _orbit(orbit), _shaderProgram(shaderProgram)
|
: _orbit(orbit), _shaderProgram(shaderProgram), _scale(scale)
|
||||||
{
|
{
|
||||||
glGenVertexArrays(1, &_vao);
|
glGenVertexArrays(1, &_vao);
|
||||||
glGenBuffers(1, &_vbo);
|
glGenBuffers(1, &_vbo);
|
||||||
|
@ -36,6 +36,8 @@ void OrbitVisualizer::regenerateVertices()
|
||||||
pos.y = y;
|
pos.y = y;
|
||||||
pos.z *= -1;
|
pos.z *= -1;
|
||||||
|
|
||||||
|
pos /= _scale;
|
||||||
|
|
||||||
_vertices.push_back(pos.x);
|
_vertices.push_back(pos.x);
|
||||||
_vertices.push_back(pos.y);
|
_vertices.push_back(pos.y);
|
||||||
_vertices.push_back(pos.z);
|
_vertices.push_back(pos.z);
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
class OrbitVisualizer
|
class OrbitVisualizer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
OrbitVisualizer(const Orbit& orbit, const GLuint shaderProgram);
|
OrbitVisualizer(const Orbit& orbit, const GLuint shaderProgram, float scale);
|
||||||
~OrbitVisualizer();
|
~OrbitVisualizer();
|
||||||
|
|
||||||
void render(const float time);
|
void render(const float time);
|
||||||
|
@ -18,6 +18,7 @@ class OrbitVisualizer
|
||||||
const int _vertexCount = 100;
|
const int _vertexCount = 100;
|
||||||
const GLuint _shaderProgram;
|
const GLuint _shaderProgram;
|
||||||
const Orbit& _orbit;
|
const Orbit& _orbit;
|
||||||
|
const float _scale;
|
||||||
|
|
||||||
GLuint _vbo;
|
GLuint _vbo;
|
||||||
GLuint _vao;
|
GLuint _vao;
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
#include "particlevisualizer.hpp"
|
#include "particlevisualizer.hpp"
|
||||||
|
|
||||||
ParticleVisualizer::ParticleVisualizer(const ParticleMap& map, const std::string& particleId, float radius,
|
ParticleVisualizer::ParticleVisualizer(const ParticleMap& map, const std::string& particleId, float radius,
|
||||||
GLuint sphereShaderProgram, GLuint widgetShaderProgram)
|
GLuint sphereShaderProgram, GLuint widgetShaderProgram, float scale)
|
||||||
: _map(map), _particleId(particleId), _sphere({radius, 2, sphereShaderProgram}), _widget(widgetShaderProgram)
|
: _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.y = y;
|
||||||
pos.z *= -1;
|
pos.z *= -1;
|
||||||
|
|
||||||
|
pos /= _scale;
|
||||||
|
|
||||||
// TODO: extract widget to its own visualizer since we know it wants an orbit but we
|
// TODO: extract widget to its own visualizer since we know it wants an orbit but we
|
||||||
// might not have one here
|
// might not have one here
|
||||||
//// render widget
|
//// render widget
|
||||||
|
|
|
@ -8,7 +8,8 @@
|
||||||
class ParticleVisualizer
|
class ParticleVisualizer
|
||||||
{
|
{
|
||||||
public:
|
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;
|
~ParticleVisualizer() = default;
|
||||||
|
|
||||||
void render(float time);
|
void render(float time);
|
||||||
|
@ -18,6 +19,7 @@ class ParticleVisualizer
|
||||||
|
|
||||||
const ParticleMap& _map;
|
const ParticleMap& _map;
|
||||||
const std::string _particleId;
|
const std::string _particleId;
|
||||||
|
const float _scale;
|
||||||
Icosphere _sphere;
|
Icosphere _sphere;
|
||||||
Widget _widget;
|
Widget _widget;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue