diff --git a/src/hello.cpp b/src/hello.cpp index c125160..26f75bd 100644 --- a/src/hello.cpp +++ b/src/hello.cpp @@ -150,7 +150,7 @@ int main() return -1; GLuint shaderProgram = compileShaderProgram(); - //Icosphere sphere(0.5, 2); + Icosphere sphere(0.5, 2); Orbit orbit(30, glm::vec3(.5, .5, 0)); glEnable(GL_DEPTH_TEST); @@ -168,7 +168,7 @@ int main() updateModelViewProjectionMatrix(shaderProgram, glfwGetTime()); // Render objects - //sphere.render(); + sphere.render(); orbit.render(); glfwSwapBuffers(window); diff --git a/src/icosphere.cpp b/src/icosphere.cpp index 2270dfa..1672169 100644 --- a/src/icosphere.cpp +++ b/src/icosphere.cpp @@ -3,7 +3,7 @@ #include #include -Icosphere::Icosphere(int subdivisions) +Icosphere::Icosphere(float radius, int subdivisions) { VertexList vertices = _isocahedronVertices; TriangleList triangles = _isocahedronTriangles; @@ -16,6 +16,13 @@ Icosphere::Icosphere(int subdivisions) " vertices: " << vertices.size() << " triangles: " << triangles.size() << std::endl; + // Scale vertices by radius after subdivision as subdivision happens on a + // unit sphere + for (int i = 0; i < vertices.size(); i++) + { + vertices[i] *= radius; + } + glGenVertexArrays(1, &_vao); glGenBuffers(1, &_vbo); glGenBuffers(1, &_ebo); diff --git a/src/icosphere.hpp b/src/icosphere.hpp index 9e6df3f..4b7b136 100644 --- a/src/icosphere.hpp +++ b/src/icosphere.hpp @@ -10,7 +10,7 @@ class Icosphere { public: - Icosphere(int subdividision); + Icosphere(float radius, int subdividision); void render(); ~Icosphere();