From ad51be518b7bfb504c2c1cc28e003be022eae3ba Mon Sep 17 00:00:00 2001 From: ktyl Date: Mon, 14 Aug 2023 01:45:54 +0200 Subject: [PATCH] feat: circular orbit --- src/icosphere.cpp | 9 +++++++-- src/icosphere.hpp | 4 +++- src/main.cpp | 10 ++++++++-- 3 files changed, 18 insertions(+), 5 deletions(-) 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);