refactor: move orbiter->particle
This commit is contained in:
parent
4d9adf2e7f
commit
a5ff616e86
|
@ -32,8 +32,7 @@ add_executable(${PROJECT_NAME}
|
|||
src/icosphere.cpp
|
||||
src/gfx.cpp
|
||||
src/orbitvisualizer.cpp
|
||||
src/orbitervisualizer.cpp
|
||||
src/orbiter.cpp
|
||||
src/particlevisualizer.cpp
|
||||
src/widget.cpp
|
||||
)
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ project(skein)
|
|||
|
||||
add_library(skein STATIC
|
||||
src/orbit.cpp
|
||||
src/particle.cpp
|
||||
)
|
||||
|
||||
target_include_directories(skein PUBLIC
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
|
||||
#include <skein/orbit.h>
|
||||
|
||||
class Orbiter
|
||||
class Particle
|
||||
{
|
||||
public:
|
||||
Orbiter() = default;
|
||||
~Orbiter() = default;
|
||||
Particle() = default;
|
||||
~Particle() = default;
|
||||
|
||||
Orbit& getOrbit();
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
#include "skein/particle.h"
|
||||
|
||||
Orbit& Particle::getOrbit()
|
||||
{
|
||||
return _orbit;
|
||||
}
|
||||
|
12
src/main.cpp
12
src/main.cpp
|
@ -41,12 +41,12 @@
|
|||
|
||||
#include "gfx.hpp"
|
||||
#include "icosphere.hpp"
|
||||
#include "orbiter.hpp"
|
||||
#include "orbitervisualizer.hpp"
|
||||
#include "particlevisualizer.hpp"
|
||||
#include "orbitvisualizer.hpp"
|
||||
#include "widget.hpp"
|
||||
|
||||
#include <skein/orbit.h>
|
||||
#include <skein/particle.h>
|
||||
|
||||
// INPUT!
|
||||
//
|
||||
|
@ -95,15 +95,15 @@ int main()
|
|||
// set up scene
|
||||
Icosphere planet(0.2, 3, litProgram);
|
||||
|
||||
Orbiter orbiter;
|
||||
Orbit& orbit = orbiter.getOrbit();
|
||||
Particle particle;
|
||||
Orbit& orbit = particle.getOrbit();
|
||||
orbit.setSemiMajorAxis(.75);
|
||||
orbit.setEccentricity(.5);
|
||||
orbit.setInclination(3.142 / 2.0 + 1);
|
||||
orbit.setArgumentOfPeriapsis(2.0);
|
||||
orbit.setLongitudeOfAscendingNode(0.1);
|
||||
|
||||
OrbiterVisualizer orbiterVisualizer(orbiter, litProgram, unlitProgram);
|
||||
ParticleVisualizer particleVisualizer(particle, litProgram, unlitProgram);
|
||||
OrbitVisualizer orbitVisualizer(orbit, unlitProgram);
|
||||
|
||||
// register input
|
||||
|
@ -149,7 +149,7 @@ int main()
|
|||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
planet.render(time);
|
||||
orbiterVisualizer.render(time);
|
||||
particleVisualizer.render(time);
|
||||
orbitVisualizer.render(time);
|
||||
|
||||
glfwSwapBuffers(window);
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
#include "orbiter.hpp"
|
||||
|
||||
Orbit& Orbiter::getOrbit()
|
||||
{
|
||||
return _orbit;
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
|
@ -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;
|
||||
};
|
|
@ -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);
|
||||
}
|
|
@ -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;
|
||||
};
|
Loading…
Reference in New Issue