|
|
|
|
@ -25,11 +25,10 @@
|
|
|
|
|
|
|
|
|
|
#include "WireframeSpheroid.h" |
|
|
|
|
|
|
|
|
|
#include <Corrade/Containers/GrowableArray.h> |
|
|
|
|
|
|
|
|
|
#include "Magnum/Math/Functions.h" |
|
|
|
|
#include "Magnum/Math/Color.h" |
|
|
|
|
#include "Magnum/Mesh.h" |
|
|
|
|
#include "Magnum/Trade/ArrayAllocator.h" |
|
|
|
|
#include "Magnum/Trade/MeshData.h" |
|
|
|
|
|
|
|
|
|
namespace Magnum { namespace Primitives { namespace Implementation { |
|
|
|
|
@ -40,11 +39,12 @@ void WireframeSpheroid::bottomHemisphere(const Float endY, const UnsignedInt rin
|
|
|
|
|
CORRADE_INTERNAL_ASSERT(_vertexData.empty()); |
|
|
|
|
|
|
|
|
|
/* Initial vertex */ |
|
|
|
|
arrayAppend(_vertexData, Vector3::yAxis(endY - 1.0f)); |
|
|
|
|
Containers::arrayAppend<Trade::ArrayAllocator>(_vertexData, |
|
|
|
|
Vector3::yAxis(endY - 1.0f)); |
|
|
|
|
|
|
|
|
|
/* Connect initial vertex to first ring */ |
|
|
|
|
for(UnsignedInt i = 0; i != 4; ++i) |
|
|
|
|
arrayAppend(_indexData, {0u, i+1}); |
|
|
|
|
Containers::arrayAppend<Trade::ArrayAllocator>(_indexData, {0u, i+1}); |
|
|
|
|
|
|
|
|
|
/* Hemisphere vertices and indices */ |
|
|
|
|
const Rad ringAngleIncrement(Constants::piHalf()/rings); |
|
|
|
|
@ -52,7 +52,7 @@ void WireframeSpheroid::bottomHemisphere(const Float endY, const UnsignedInt rin
|
|
|
|
|
const Rad angle = Float(j+1)*ringAngleIncrement; |
|
|
|
|
const std::pair<Float, Float> sincos = Math::sincos(angle); |
|
|
|
|
|
|
|
|
|
arrayAppend(_vertexData, { |
|
|
|
|
Containers::arrayAppend<Trade::ArrayAllocator>(_vertexData, { |
|
|
|
|
{0.0f, endY - sincos.second, sincos.first}, |
|
|
|
|
{sincos.first, endY - sincos.second, 0.0f}, |
|
|
|
|
{0.0f, endY - sincos.second, -sincos.first}, |
|
|
|
|
@ -61,7 +61,8 @@ void WireframeSpheroid::bottomHemisphere(const Float endY, const UnsignedInt rin
|
|
|
|
|
|
|
|
|
|
/* Connect vertices to next ring */ |
|
|
|
|
for(UnsignedInt i = 0; i != 4; ++i) { |
|
|
|
|
arrayAppend(_indexData, {UnsignedInt(_vertexData.size()) - 4 + i, UnsignedInt(_vertexData.size()) + i}); |
|
|
|
|
Containers::arrayAppend<Trade::ArrayAllocator>(_indexData, |
|
|
|
|
{UnsignedInt(_vertexData.size()) - 4 + i, UnsignedInt(_vertexData.size()) + i}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -69,7 +70,8 @@ void WireframeSpheroid::bottomHemisphere(const Float endY, const UnsignedInt rin
|
|
|
|
|
void WireframeSpheroid::topHemisphere(const Float startY, const UnsignedInt rings) { |
|
|
|
|
/* Connect previous ring to following vertices (if any) */ |
|
|
|
|
if(rings > 1) for(UnsignedInt i = 0; i != 4; ++i) { |
|
|
|
|
arrayAppend(_indexData, {UnsignedInt(_vertexData.size()) - 4*_segments + i, UnsignedInt(_vertexData.size()) + i}); |
|
|
|
|
Containers::arrayAppend<Trade::ArrayAllocator>(_indexData, |
|
|
|
|
{UnsignedInt(_vertexData.size()) - 4*_segments + i, UnsignedInt(_vertexData.size()) + i}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* Hemisphere vertices and indices */ |
|
|
|
|
@ -80,10 +82,11 @@ void WireframeSpheroid::topHemisphere(const Float startY, const UnsignedInt ring
|
|
|
|
|
|
|
|
|
|
/* Connect previous hemisphere ring to current vertices */ |
|
|
|
|
if(j != 0) for(UnsignedInt i = 0; i != 4; ++i) { |
|
|
|
|
arrayAppend(_indexData, {UnsignedInt(_vertexData.size()) - 4 + i, UnsignedInt(_vertexData.size()) + i}); |
|
|
|
|
Containers::arrayAppend<Trade::ArrayAllocator>(_indexData, |
|
|
|
|
{UnsignedInt(_vertexData.size()) - 4 + i, UnsignedInt(_vertexData.size()) + i}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
arrayAppend(_vertexData, { |
|
|
|
|
Containers::arrayAppend<Trade::ArrayAllocator>(_vertexData, { |
|
|
|
|
{0.0f, startY + sincos.first, sincos.second}, |
|
|
|
|
{sincos.second, startY + sincos.first, 0.0f}, |
|
|
|
|
{0.0f, startY + sincos.first, -sincos.second}, |
|
|
|
|
@ -92,13 +95,16 @@ void WireframeSpheroid::topHemisphere(const Float startY, const UnsignedInt ring
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* Final vertex */ |
|
|
|
|
arrayAppend(_vertexData, Vector3::yAxis(startY + 1.0f)); |
|
|
|
|
Containers::arrayAppend<Trade::ArrayAllocator>(_vertexData, |
|
|
|
|
Vector3::yAxis(startY + 1.0f)); |
|
|
|
|
|
|
|
|
|
/* Connect last ring to final vertex */ |
|
|
|
|
if(rings > 1) for(UnsignedInt i = 0; i != 4; ++i) |
|
|
|
|
arrayAppend(_indexData, {UnsignedInt(_vertexData.size()) - 5 + i, UnsignedInt(_vertexData.size()) - 1}); |
|
|
|
|
Containers::arrayAppend<Trade::ArrayAllocator>(_indexData, |
|
|
|
|
{UnsignedInt(_vertexData.size()) - 5 + i, UnsignedInt(_vertexData.size()) - 1}); |
|
|
|
|
else for(UnsignedInt i = 0; i != 4; ++i) |
|
|
|
|
arrayAppend(_indexData, {UnsignedInt(_vertexData.size()) - 4*_segments + i - 1, UnsignedInt(_vertexData.size()) - 1}); |
|
|
|
|
Containers::arrayAppend<Trade::ArrayAllocator>(_indexData, |
|
|
|
|
{UnsignedInt(_vertexData.size()) - 4*_segments + i - 1, UnsignedInt(_vertexData.size()) - 1}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void WireframeSpheroid::ring(const Float y) { |
|
|
|
|
@ -108,20 +114,24 @@ void WireframeSpheroid::ring(const Float y) {
|
|
|
|
|
for(UnsignedInt i = 0; i != 4; ++i) { |
|
|
|
|
const Rad segmentAngle = Rad(Float(i)*Constants::piHalf()) + Float(j)*segmentAngleIncrement; |
|
|
|
|
const std::pair<Float, Float> sincos = Math::sincos(segmentAngle); |
|
|
|
|
if(j != 0) arrayAppend(_indexData, {UnsignedInt(_vertexData.size() - 4), UnsignedInt(_vertexData.size())}); |
|
|
|
|
arrayAppend(_vertexData, {sincos.first, y, sincos.second}); |
|
|
|
|
if(j != 0) Containers::arrayAppend<Trade::ArrayAllocator>(_indexData, |
|
|
|
|
{UnsignedInt(_vertexData.size() - 4), UnsignedInt(_vertexData.size())}); |
|
|
|
|
Containers::arrayAppend<Trade::ArrayAllocator>(_vertexData, |
|
|
|
|
{sincos.first, y, sincos.second}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* Close the ring */ |
|
|
|
|
for(UnsignedInt i = 0; i != 4; ++i) |
|
|
|
|
arrayAppend(_indexData, {UnsignedInt(_vertexData.size()) - 4 + i, UnsignedInt(_vertexData.size()) - 4*_segments + (i + 1)%4}); |
|
|
|
|
Containers::arrayAppend<Trade::ArrayAllocator>(_indexData, |
|
|
|
|
{UnsignedInt(_vertexData.size()) - 4 + i, UnsignedInt(_vertexData.size()) - 4*_segments + (i + 1)%4}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void WireframeSpheroid::cylinder() { |
|
|
|
|
/* Connect four vertex pairs of previous and next ring */ |
|
|
|
|
for(UnsignedInt i = 0; i != 4; ++i) |
|
|
|
|
arrayAppend(_indexData, {UnsignedInt(_vertexData.size()) - 4*_segments + i, UnsignedInt(_vertexData.size()) + i}); |
|
|
|
|
Containers::arrayAppend<Trade::ArrayAllocator>(_indexData, |
|
|
|
|
{UnsignedInt(_vertexData.size()) - 4*_segments + i, UnsignedInt(_vertexData.size()) + i}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
namespace { |
|
|
|
|
@ -138,8 +148,8 @@ Trade::MeshData WireframeSpheroid::finalize() {
|
|
|
|
|
Trade::MeshAttributeData positions{Trade::MeshAttribute::Position, Containers::arrayView(_vertexData)}; |
|
|
|
|
const UnsignedInt vertexCount = _vertexData.size(); |
|
|
|
|
return Trade::MeshData{MeshPrimitive::Lines, |
|
|
|
|
Containers::arrayAllocatorCast<char>(std::move(_indexData)), indices, |
|
|
|
|
Containers::arrayAllocatorCast<char>(std::move(_vertexData)), |
|
|
|
|
Containers::arrayAllocatorCast<char, Trade::ArrayAllocator>(std::move(_indexData)), indices, |
|
|
|
|
Containers::arrayAllocatorCast<char, Trade::ArrayAllocator>(std::move(_vertexData)), |
|
|
|
|
Trade::meshAttributeDataNonOwningArray(AttributeData), vertexCount}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|