feat: scale down sphere

This commit is contained in:
Cat Flynn 2023-08-06 12:44:34 +02:00
parent fdabe9aadd
commit c161f3e54a
3 changed files with 11 additions and 4 deletions

View File

@ -150,7 +150,7 @@ int main()
return -1; return -1;
GLuint shaderProgram = compileShaderProgram(); GLuint shaderProgram = compileShaderProgram();
//Icosphere sphere(0.5, 2); Icosphere sphere(0.5, 2);
Orbit orbit(30, glm::vec3(.5, .5, 0)); Orbit orbit(30, glm::vec3(.5, .5, 0));
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
@ -168,7 +168,7 @@ int main()
updateModelViewProjectionMatrix(shaderProgram, glfwGetTime()); updateModelViewProjectionMatrix(shaderProgram, glfwGetTime());
// Render objects // Render objects
//sphere.render(); sphere.render();
orbit.render(); orbit.render();
glfwSwapBuffers(window); glfwSwapBuffers(window);

View File

@ -3,7 +3,7 @@
#include <iostream> #include <iostream>
#include <array> #include <array>
Icosphere::Icosphere(int subdivisions) Icosphere::Icosphere(float radius, int subdivisions)
{ {
VertexList vertices = _isocahedronVertices; VertexList vertices = _isocahedronVertices;
TriangleList triangles = _isocahedronTriangles; TriangleList triangles = _isocahedronTriangles;
@ -16,6 +16,13 @@ Icosphere::Icosphere(int subdivisions)
" vertices: " << vertices.size() << " vertices: " << vertices.size() <<
" triangles: " << triangles.size() << std::endl; " 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); glGenVertexArrays(1, &_vao);
glGenBuffers(1, &_vbo); glGenBuffers(1, &_vbo);
glGenBuffers(1, &_ebo); glGenBuffers(1, &_ebo);

View File

@ -10,7 +10,7 @@
class Icosphere class Icosphere
{ {
public: public:
Icosphere(int subdividision); Icosphere(float radius, int subdividision);
void render(); void render();
~Icosphere(); ~Icosphere();