Add ArchStrip
This commit is contained in:
@@ -307,4 +307,48 @@ namespace OpenVulkano::Scene
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
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<float>(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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user