refactor: move orbiter->particle

This commit is contained in:
Cat Flynn 2024-08-18 14:12:08 +01:00
parent 4d9adf2e7f
commit a5ff616e86
10 changed files with 63 additions and 62 deletions

View File

@ -32,8 +32,7 @@ add_executable(${PROJECT_NAME}
src/icosphere.cpp src/icosphere.cpp
src/gfx.cpp src/gfx.cpp
src/orbitvisualizer.cpp src/orbitvisualizer.cpp
src/orbitervisualizer.cpp src/particlevisualizer.cpp
src/orbiter.cpp
src/widget.cpp src/widget.cpp
) )

View File

@ -3,6 +3,7 @@ project(skein)
add_library(skein STATIC add_library(skein STATIC
src/orbit.cpp src/orbit.cpp
src/particle.cpp
) )
target_include_directories(skein PUBLIC target_include_directories(skein PUBLIC

View File

@ -2,11 +2,11 @@
#include <skein/orbit.h> #include <skein/orbit.h>
class Orbiter class Particle
{ {
public: public:
Orbiter() = default; Particle() = default;
~Orbiter() = default; ~Particle() = default;
Orbit& getOrbit(); Orbit& getOrbit();

View File

@ -0,0 +1,7 @@
#include "skein/particle.h"
Orbit& Particle::getOrbit()
{
return _orbit;
}

View File

@ -41,12 +41,12 @@
#include "gfx.hpp" #include "gfx.hpp"
#include "icosphere.hpp" #include "icosphere.hpp"
#include "orbiter.hpp" #include "particlevisualizer.hpp"
#include "orbitervisualizer.hpp"
#include "orbitvisualizer.hpp" #include "orbitvisualizer.hpp"
#include "widget.hpp" #include "widget.hpp"
#include <skein/orbit.h> #include <skein/orbit.h>
#include <skein/particle.h>
// INPUT! // INPUT!
// //
@ -95,15 +95,15 @@ int main()
// set up scene // set up scene
Icosphere planet(0.2, 3, litProgram); Icosphere planet(0.2, 3, litProgram);
Orbiter orbiter; Particle particle;
Orbit& orbit = orbiter.getOrbit(); Orbit& orbit = particle.getOrbit();
orbit.setSemiMajorAxis(.75); orbit.setSemiMajorAxis(.75);
orbit.setEccentricity(.5); orbit.setEccentricity(.5);
orbit.setInclination(3.142 / 2.0 + 1); orbit.setInclination(3.142 / 2.0 + 1);
orbit.setArgumentOfPeriapsis(2.0); orbit.setArgumentOfPeriapsis(2.0);
orbit.setLongitudeOfAscendingNode(0.1); orbit.setLongitudeOfAscendingNode(0.1);
OrbiterVisualizer orbiterVisualizer(orbiter, litProgram, unlitProgram); ParticleVisualizer particleVisualizer(particle, litProgram, unlitProgram);
OrbitVisualizer orbitVisualizer(orbit, unlitProgram); OrbitVisualizer orbitVisualizer(orbit, unlitProgram);
// register input // register input
@ -149,7 +149,7 @@ int main()
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
planet.render(time); planet.render(time);
orbiterVisualizer.render(time); particleVisualizer.render(time);
orbitVisualizer.render(time); orbitVisualizer.render(time);
glfwSwapBuffers(window); glfwSwapBuffers(window);

View File

@ -1,7 +0,0 @@
#include "orbiter.hpp"
Orbit& Orbiter::getOrbit()
{
return _orbit;
}

View File

@ -1,23 +0,0 @@
#include "orbitervisualizer.hpp"
OrbiterVisualizer::OrbiterVisualizer(Orbiter& orbiter, GLuint sphereShaderProgram, GLuint widgetShaderProgram)
: _orbiter(orbiter), _sphere({0.07, 2, sphereShaderProgram}), _widget(widgetShaderProgram)
{
}
void OrbiterVisualizer::render(float time)
{
const Orbit& orbit = _orbiter.getOrbit();
const float meanAnomaly = time;
glm::vec3 pos = orbit.getPosition(meanAnomaly);
// render widget
glm::mat4 widgetMatrix = orbit.getLookAlongMatrix(time);
_widget.setModelMatrix(widgetMatrix);
_widget.render(time);
// render sphere
_sphere.setPosition(pos);
_sphere.render(time);
}

View File

@ -1,21 +0,0 @@
#pragma once
#include "widget.hpp"
#include "icosphere.hpp"
#include "orbiter.hpp"
class OrbiterVisualizer
{
public:
OrbiterVisualizer(Orbiter& orbiter, GLuint sphereShaderProgram, GLuint widgetShaderProgram);
~OrbiterVisualizer() = default;
void render(float time);
private:
void updateModelMatrix();
Orbiter& _orbiter;
Icosphere _sphere;
Widget _widget;
};

View File

@ -0,0 +1,23 @@
#include "particlevisualizer.hpp"
ParticleVisualizer::ParticleVisualizer(Particle& particle, GLuint sphereShaderProgram, GLuint widgetShaderProgram)
: _particle(particle), _sphere({0.07, 2, sphereShaderProgram}), _widget(widgetShaderProgram)
{
}
void ParticleVisualizer::render(float time)
{
const Orbit& orbit = _particle.getOrbit();
const float meanAnomaly = time;
glm::vec3 pos = orbit.getPosition(meanAnomaly);
// render widget
glm::mat4 widgetMatrix = orbit.getLookAlongMatrix(time);
_widget.setModelMatrix(widgetMatrix);
_widget.render(time);
// render sphere
_sphere.setPosition(pos);
_sphere.render(time);
}

View File

@ -0,0 +1,22 @@
#pragma once
#include "widget.hpp"
#include "icosphere.hpp"
#include <skein/particle.h>
class ParticleVisualizer
{
public:
ParticleVisualizer(Particle& particle, GLuint sphereShaderProgram, GLuint widgetShaderProgram);
~ParticleVisualizer() = default;
void render(float time);
private:
void updateModelMatrix();
Particle& _particle;
Icosphere _sphere;
Widget _widget;
};