diff --git a/src/icosphere.cpp b/src/icosphere.cpp index 8046176..db404b8 100644 --- a/src/icosphere.cpp +++ b/src/icosphere.cpp @@ -7,9 +7,9 @@ #include "gfx.hpp" -Icosphere::Icosphere(float radius, int subdivisions, GLuint shaderProgram, glm::vec3 position) : +Icosphere::Icosphere(float radius, int subdivisions, GLuint shaderProgram) : _shaderProgram(shaderProgram), - _position(position) + _position({}) { generateVertices(radius, subdivisions); @@ -157,6 +157,11 @@ void Icosphere::render() glDrawElements(GL_TRIANGLES, _indices.size(), GL_UNSIGNED_INT, 0); } +void Icosphere::setPosition(glm::vec3 position) +{ + _position = position; +} + Icosphere::~Icosphere() { glDeleteVertexArrays(1, &_vao); diff --git a/src/icosphere.hpp b/src/icosphere.hpp index eaeb143..856802b 100644 --- a/src/icosphere.hpp +++ b/src/icosphere.hpp @@ -10,9 +10,11 @@ class Icosphere { public: - Icosphere(float radius, int subdivisions, GLuint shaderProgram, glm::vec3 position); + Icosphere(float radius, int subdivisions, GLuint shaderProgram); void render(); + void setPosition(glm::vec3 position); + ~Icosphere(); private: diff --git a/src/main.cpp b/src/main.cpp index 9837be4..1334c61 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -51,8 +51,8 @@ int main() GLuint litProgram = compileShaderProgram("./frag_lit.glsl"); GLuint unlitProgram = compileShaderProgram("./frag_unlit.glsl"); - Icosphere planet(0.4, 2, litProgram, glm::vec3(0.0, 0.0, 0.0)); - Icosphere orbiter(0.1, 2, litProgram, glm::vec3(0.6, 0.0, 0.0)); + Icosphere planet(0.4, 2, litProgram); + Icosphere orbiter(0.1, 2, litProgram); Orbit orbit(100); // Main loop @@ -62,6 +62,12 @@ int main() glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); float time = glfwGetTime(); + float r = .7; + float x = cos(time); + float y = sin(time); + glm::vec3 pos(x, 0, y); + pos *= r; + orbiter.setPosition(pos); // Render lit objects glUseProgram(litProgram);