diff --git a/openVulkanoCpp/Scene/GeometryFactory.cpp b/openVulkanoCpp/Scene/GeometryFactory.cpp index c015c51..137e97f 100644 --- a/openVulkanoCpp/Scene/GeometryFactory.cpp +++ b/openVulkanoCpp/Scene/GeometryFactory.cpp @@ -307,4 +307,48 @@ namespace OpenVulkano::Scene return result; } -} \ No newline at end of file + + Geometry GeometryFactory::MakeArchStrip(float radius, float width, float endRadius, int segments, const Math::Vector4f& color, float endVCoord, bool indexBuffer) + { + Geometry result; + segments = std::max(2, segments); + result.Init(2 * segments, indexBuffer ? 6 * segments : 0); + const float segmentAngle = endRadius / static_cast(segments - 1); + width /= 2; + const float segmentV = endVCoord / (segments - 1); + float segV = 0; + for(int i = 0, seg = 0; seg < segments; seg++) + { + float angle = seg * segmentAngle; + float z = std::cos(angle) * radius; + float y = std::sin(angle) * radius; + + //TODO normals + result.vertices[i].color = color; + result.vertices[i++].Set(width, y, z, +0, +0, +1, +1, +segV); + result.vertices[i].color = color; + result.vertices[i++].Set(-width, y, z, +0, +0, +1, +0, +segV); + segV += segmentV; + } + if (indexBuffer) + { + uint32_t* indices = new uint32_t[result.GetIndexCount()]; + for (uint32_t i = 0, segment = 0; segment < segments; ++segment) + { + uint32_t first = segment * 2; + uint32_t second = first + 1; + + indices[i++] = first; + indices[i++] = second; + indices[i++] = first + 2; + + indices[i++] = first + 2; + indices[i++] = second; + indices[i++] = second + 2; + } + result.SetIndices(indices, result.GetIndexCount()); + } + + return result; + } +} diff --git a/openVulkanoCpp/Scene/GeometryFactory.hpp b/openVulkanoCpp/Scene/GeometryFactory.hpp index cd5e478..45e383d 100644 --- a/openVulkanoCpp/Scene/GeometryFactory.hpp +++ b/openVulkanoCpp/Scene/GeometryFactory.hpp @@ -20,5 +20,6 @@ namespace OpenVulkano::Scene static Geometry MakeTriangle(const Math::Vector3f& p1, const Math::Vector3f& p2, const Math::Vector3f& p3, const Math::Vector4f& color = Math::Vector4f(1)); static Geometry MakeCylinder(float radius, float height, uint32_t segments, const Math::Vector4f& color = Math::Vector4f(1)); static Geometry MakePyramid(float baseLength = 1, float height = 1, const Math::Vector4f& color = Math::Vector4f(1)); + static Geometry MakeArchStrip(float radius = 1, float width = 0.2, float endRadius = std::numbers::pi, int segments = 16, const Math::Vector4f& color = Math::Vector4f(1), float endVCoord = 1, bool indexBuffer = true); }; }