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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user