@ -31,14 +31,14 @@
namespace Magnum { namespace Primitives {
Trade : : MeshData3D Capsule : : solid ( UnsignedInt hemisphereRings , UnsignedInt cylinderRings , UnsignedInt segments , Float length , TextureCoords textureCoords ) {
Trade : : MeshData3D Capsule : : solid ( UnsignedInt hemisphereRings , UnsignedInt cylinderRings , UnsignedInt segments , Float ha lfL ength, TextureCoords textureCoords ) {
CORRADE_ASSERT ( hemisphereRings > = 1 & & cylinderRings > = 1 & & segments > = 3 , " Capsule must have at least one hemisphere ring, one cylinder ring and three segments " , Trade : : MeshData3D ( Mesh : : Primitive : : Triangles , { } , { } , { } , { } ) ) ;
Implementation : : Spheroid capsule ( segments , textureCoords = = TextureCoords : : Generate ?
Implementation : : Spheroid : : TextureCoords : : Generate :
Implementation : : Spheroid : : TextureCoords : : DontGenerate ) ;
Float height = 2.0f + l ength;
Float height = 2.0f + 2.0f * halfL ength;
Float hemisphereTextureCoordsVIncrement = 1.0f / ( hemisphereRings * height ) ;
Rad hemisphereRingAngleIncrement ( Constants : : pi ( ) / ( 2 * hemisphereRings ) ) ;
@ -46,13 +46,13 @@ Trade::MeshData3D Capsule::solid(UnsignedInt hemisphereRings, UnsignedInt cylind
capsule . capVertex ( - height / 2 , - 1.0f , 0.0f ) ;
/* Rings of bottom hemisphere */
capsule . hemisphereVertexRings ( hemisphereRings - 1 , - length / 2 , - Rad ( Constants : : pi ( ) ) / 2 + hemisphereRingAngleIncrement , hemisphereRingAngleIncrement , hemisphereTextureCoordsVIncrement , hemisphereTextureCoordsVIncrement ) ;
capsule . hemisphereVertexRings ( hemisphereRings - 1 , - ha lfL ength, - Rad ( Constants : : pi ( ) ) / 2 + hemisphereRingAngleIncrement , hemisphereRingAngleIncrement , hemisphereTextureCoordsVIncrement , hemisphereTextureCoordsVIncrement ) ;
/* Rings of cylinder */
capsule . cylinderVertexRings ( cylinderRings + 1 , - length / 2 , l ength/ cylinderRings , 1.0f / height , l ength/ ( cylinderRings * height ) ) ;
capsule . cylinderVertexRings ( cylinderRings + 1 , - halfLength , 2.0f * halfL ength/ cylinderRings , 1.0f / height , 2.0f * halfL ength/ ( cylinderRings * height ) ) ;
/* Rings of top hemisphere */
capsule . hemisphereVertexRings ( hemisphereRings - 1 , length / 2 , hemisphereRingAngleIncrement , hemisphereRingAngleIncrement , ( 1.0f + l ength) / height + hemisphereTextureCoordsVIncrement , hemisphereTextureCoordsVIncrement ) ;
capsule . hemisphereVertexRings ( hemisphereRings - 1 , ha lfL ength, hemisphereRingAngleIncrement , hemisphereRingAngleIncrement , ( 1.0f + 2.0f * halfL ength) / height + hemisphereTextureCoordsVIncrement , hemisphereTextureCoordsVIncrement ) ;
/* Top cap vertex */
capsule . capVertex ( height / 2 , 1.0f , 1.0f ) ;
@ -65,23 +65,23 @@ Trade::MeshData3D Capsule::solid(UnsignedInt hemisphereRings, UnsignedInt cylind
return capsule . finalize ( ) ;
}
Trade : : MeshData3D Capsule : : wireframe ( const UnsignedInt hemisphereRings , const UnsignedInt cylinderRings , const UnsignedInt segments , const Float length ) {
Trade : : MeshData3D Capsule : : wireframe ( const UnsignedInt hemisphereRings , const UnsignedInt cylinderRings , const UnsignedInt segments , const Float ha lfL ength) {
CORRADE_ASSERT ( hemisphereRings > = 1 & & cylinderRings > = 1 & & segments > = 4 & & segments % 4 = = 0 , " Primitives::Capsule::wireframe(): improper parameters " , Trade : : MeshData3D ( Mesh : : Primitive : : Lines , { } , { } , { } , { } ) ) ;
Implementation : : WireframeSpheroid capsule ( segments / 4 ) ;
/* Bottom hemisphere */
capsule . bottomHemisphere ( - length / 2 , hemisphereRings ) ;
capsule . bottomHemisphere ( - ha lfL ength, hemisphereRings ) ;
/* Cylinder */
capsule . ring ( - length / 2 ) ;
capsule . ring ( - ha lfL ength) ;
for ( UnsignedInt i = 0 ; i ! = cylinderRings ; + + i ) {
capsule . cylinder ( ) ;
capsule . ring ( - length / 2 + ( i + 1 ) * ( l ength/ cylinderRings ) ) ;
capsule . ring ( - ha lfL ength + ( i + 1 ) * ( 2.0f * halfL ength/ cylinderRings ) ) ;
}
/* Top hemisphere */
capsule . topHemisphere ( length / 2 , hemisphereRings ) ;
capsule . topHemisphere ( ha lfL ength, hemisphereRings ) ;
return capsule . finalize ( ) ;
}