From d1e5371aeb9dbed222eca26a9c19e91579f02041 Mon Sep 17 00:00:00 2001
From: Tobias Frisch <tfrisch@uni-koblenz.de>
Date: Fri, 14 Oct 2022 00:20:52 +0200
Subject: [PATCH] Adjust facing of generated geometry from module

Signed-off-by: Tobias Frisch <tfrisch@uni-koblenz.de>
---
 modules/geometry/src/vkcv/geometry/Cuboid.cpp |  4 +--
 .../geometry/src/vkcv/geometry/Cylinder.cpp   | 26 +++++++++++++------
 projects/first_mesh/src/main.cpp              |  1 -
 3 files changed, 20 insertions(+), 11 deletions(-)

diff --git a/modules/geometry/src/vkcv/geometry/Cuboid.cpp b/modules/geometry/src/vkcv/geometry/Cuboid.cpp
index 3e5c2d88..73a701b2 100644
--- a/modules/geometry/src/vkcv/geometry/Cuboid.cpp
+++ b/modules/geometry/src/vkcv/geometry/Cuboid.cpp
@@ -41,12 +41,12 @@ namespace vkcv::geometry {
 				+0.5f, +0.5f, +0.5f,
 				
 				-0.5f, -0.5f, -0.5f,
-				-0.5f, -0.5f, +0.5f,
 				+0.5f, -0.5f, -0.5f,
+				-0.5f, -0.5f, +0.5f,
 				+0.5f, -0.5f, +0.5f,
 				-0.5f, +0.5f, -0.5f,
-				-0.5f, +0.5f, +0.5f,
 				+0.5f, +0.5f, -0.5f,
+				-0.5f, +0.5f, +0.5f,
 				+0.5f, +0.5f, +0.5f,
 				
 				-0.5f, -0.5f, -0.5f,
diff --git a/modules/geometry/src/vkcv/geometry/Cylinder.cpp b/modules/geometry/src/vkcv/geometry/Cylinder.cpp
index 79e31496..67b62f69 100644
--- a/modules/geometry/src/vkcv/geometry/Cylinder.cpp
+++ b/modules/geometry/src/vkcv/geometry/Cylinder.cpp
@@ -73,7 +73,7 @@ namespace vkcv::geometry {
 		size_t offset = 0;
 		
 		for (i = 0; i < resolution; i++) {
-			u = static_cast<float>(i) / static_cast<float>(resolution);
+			u = static_cast<float>(i) / static_cast<float>(resolution - 1);
 			phi = 2.0f * std::numbers::pi_v<float> * u;
 			
 			sinPhi = std::sin(phi);
@@ -95,13 +95,23 @@ namespace vkcv::geometry {
 				cylinderNormals.push_back(glm::vec3(sinPhi, 0.0f, cosPhi));
 				cylinderUVCoords.push_back(glm::vec2(u, v));
 				
-				cylinderIndices.push_back(2 + (offset + j * 2) % (vertexCount - 2));
-				cylinderIndices.push_back(2 + (offset + j * 2 + 4) % (vertexCount - 2));
-				cylinderIndices.push_back(j);
-				
-				cylinderIndices.push_back(2 + (offset + j * 2 + 1) % (vertexCount - 2));
-				cylinderIndices.push_back(2 + (offset + j * 2 + 5) % (vertexCount - 2));
-				cylinderIndices.push_back(2 + (offset + j * 2 + 3) % (vertexCount - 2));
+				if (j == 1) {
+					cylinderIndices.push_back(2 + (offset + j * 2) % (vertexCount - 2));
+					cylinderIndices.push_back(2 + (offset + j * 2 + 4) % (vertexCount - 2));
+					cylinderIndices.push_back(j);
+					
+					cylinderIndices.push_back(2 + (offset + j * 2 + 5) % (vertexCount - 2));
+					cylinderIndices.push_back(2 + (offset + j * 2 + 1) % (vertexCount - 2));
+					cylinderIndices.push_back(2 + (offset + j * 2 + 3) % (vertexCount - 2));
+				} else {
+					cylinderIndices.push_back(2 + (offset + j * 2 + 4) % (vertexCount - 2));
+					cylinderIndices.push_back(2 + (offset + j * 2) % (vertexCount - 2));
+					cylinderIndices.push_back(j);
+					
+					cylinderIndices.push_back(2 + (offset + j * 2 + 1) % (vertexCount - 2));
+					cylinderIndices.push_back(2 + (offset + j * 2 + 5) % (vertexCount - 2));
+					cylinderIndices.push_back(2 + (offset + j * 2 + 3) % (vertexCount - 2));
+				}
 			}
 			
 			offset += 4;
diff --git a/projects/first_mesh/src/main.cpp b/projects/first_mesh/src/main.cpp
index ecb1d979..886d6e82 100644
--- a/projects/first_mesh/src/main.cpp
+++ b/projects/first_mesh/src/main.cpp
@@ -1,5 +1,4 @@
 #include <iostream>
-#include <vkcv/Buffer.hpp>
 #include <vkcv/Core.hpp>
 #include <vkcv/Image.hpp>
 #include <vkcv/Pass.hpp>
-- 
GitLab