#include "orbitvisualizer.hpp" #include "gfx.hpp" OrbitVisualizer::OrbitVisualizer(const Orbit& orbit, const GLuint shaderProgram) : _orbit(orbit), _shaderProgram(shaderProgram) { glGenVertexArrays(1, &_vao); glGenBuffers(1, &_vbo); } void OrbitVisualizer::render(const float time) { regenerateVertices(); glUseProgram(_shaderProgram); updateModelViewProjectionMatrix(_shaderProgram, time); glBindVertexArray(_vao); glBindBuffer(GL_ARRAY_BUFFER, _vbo); glDrawArrays(GL_LINE_LOOP, 0, _vertices.size() / 3); } void OrbitVisualizer::regenerateVertices() { _vertices.clear(); for (int i = 0; i < _vertexCount; i++) { float t = (float)i / (float)_vertexCount * 2.0 * _pi; glm::vec3 pos = _orbit.getPosition(t); _vertices.push_back(pos.x); _vertices.push_back(pos.y); _vertices.push_back(pos.z); } glBindVertexArray(_vao); glBindBuffer(GL_ARRAY_BUFFER, _vbo); size_t vboBufferSize = _vertices.size() * sizeof(float); glBufferData(GL_ARRAY_BUFFER, vboBufferSize, &_vertices[0], GL_STATIC_DRAW); glEnableVertexAttribArray(0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindVertexArray(0); } OrbitVisualizer::~OrbitVisualizer() { glDeleteVertexArrays(1, &_vao); glDeleteBuffers(1, &_vbo); }