From da4d088d9d7abeb9e00aa6f165758e0e511bc555 Mon Sep 17 00:00:00 2001 From: Peder Bergebakken Sundt Date: Tue, 19 Mar 2019 20:18:13 +0100 Subject: [PATCH] Add texture coordinates to spheres --- src/utilities/shapes.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/utilities/shapes.cpp b/src/utilities/shapes.cpp index 0a9a6b3..f64d3ff 100644 --- a/src/utilities/shapes.cpp +++ b/src/utilities/shapes.cpp @@ -216,10 +216,12 @@ Mesh generateSphere(float sphereRadius, int slices, int layers) { vector vertices; vector normals; vector indices; + vector texcoords; vertices.reserve(3 * triangleCount); normals.reserve(3 * triangleCount); indices.reserve(3 * triangleCount); + texcoords.reserve(3 * triangleCount); // Slices require us to define a full revolution worth of triangles. // Layers only requires angle varying between the bottom and the top (a layer only covers half a circle worth of angles) @@ -304,7 +306,14 @@ Mesh generateSphere(float sphereRadius, int slices, int layers) { indices.emplace_back(i + 3); indices.emplace_back(i + 4); indices.emplace_back(i + 5); - + + texcoords.emplace_back( currentSliceAngleDegrees /360., currentAngleZDegrees /180. ); + texcoords.emplace_back( nextSliceAngleDegrees /360., currentAngleZDegrees /180. ); + texcoords.emplace_back( nextSliceAngleDegrees /360., nextAngleZDegrees /180. ); + texcoords.emplace_back( currentSliceAngleDegrees /360., currentAngleZDegrees /180. ); + texcoords.emplace_back( nextSliceAngleDegrees /360., nextAngleZDegrees /180. ); + texcoords.emplace_back( currentSliceAngleDegrees /360., nextAngleZDegrees /180. ); + i += 6; } } @@ -313,6 +322,7 @@ Mesh generateSphere(float sphereRadius, int slices, int layers) { mesh.vertices = vertices; mesh.normals = normals; mesh.indices = indices; + mesh.textureCoordinates = texcoords; return mesh; }