@ -20,11 +20,11 @@
namespace Magnum { namespace Primitives {
Capsule : : Capsule ( std : : uint32_t hemisphereRings , std : : uint32_t cylinderRings , std : : uint32_t segments , GLf loat length , TextureCoords textureCoords ) : MeshData3D ( Mesh : : Primitive : : Triangles , new std : : vector < std : : uint32_ t> , { new std : : vector < Vector3 > ( ) } , { new std : : vector < Vector3 > ( ) } , textureCoords = = TextureCoords : : Generate ? std : : vector < std : : vector < Vector2 > * > { new std : : vector < Vector2 > ( ) } : std : : vector < std : : vector < Vector2 > * > ( ) ) , segments ( segments ) , textureCoords ( textureCoords ) {
Capsule : : Capsule ( UnsignedInt hemisphereRings , UnsignedInt cylinderRings , UnsignedInt segments , F loat length , TextureCoords textureCoords ) : MeshData3D ( Mesh : : Primitive : : Triangles , new std : : vector < UnsignedIn t> , { new std : : vector < Vector3 > ( ) } , { new std : : vector < Vector3 > ( ) } , textureCoords = = TextureCoords : : Generate ? std : : vector < std : : vector < Vector2 > * > { new std : : vector < Vector2 > ( ) } : std : : vector < std : : vector < Vector2 > * > ( ) ) , segments ( segments ) , textureCoords ( textureCoords ) {
CORRADE_ASSERT ( hemisphereRings > = 1 & & cylinderRings > = 1 & & segments > = 3 , " Capsule must have at least one hemisphere ring, one cylinder ring and three segments " , ) ;
GLf loat height = 2.0f + length ;
GLf loat hemisphereTextureCoordsVIncrement = 1.0f / ( hemisphereRings * height ) ;
F loat height = 2.0f + length ;
F loat hemisphereTextureCoordsVIncrement = 1.0f / ( hemisphereRings * height ) ;
Rad hemisphereRingAngleIncrement = Rad ( Constants : : pi ( ) ) / ( 2 * hemisphereRings ) ;
/* Bottom cap vertex */
@ -48,9 +48,9 @@ Capsule::Capsule(std::uint32_t hemisphereRings, std::uint32_t cylinderRings, std
topFaceRing ( ) ;
}
Capsule : : Capsule ( std : : uint32_ t segments , TextureCoords textureCoords ) : MeshData3D ( Mesh : : Primitive : : Triangles , new std : : vector < std : : uint32_ t> , { new std : : vector < Vector3 > ( ) } , { new std : : vector < Vector3 > ( ) } , textureCoords = = TextureCoords : : Generate ? std : : vector < std : : vector < Vector2 > * > { new std : : vector < Vector2 > ( ) } : std : : vector < std : : vector < Vector2 > * > ( ) ) , segments ( segments ) , textureCoords ( textureCoords ) { }
Capsule : : Capsule ( UnsignedIn t segments , TextureCoords textureCoords ) : MeshData3D ( Mesh : : Primitive : : Triangles , new std : : vector < UnsignedIn t> , { new std : : vector < Vector3 > ( ) } , { new std : : vector < Vector3 > ( ) } , textureCoords = = TextureCoords : : Generate ? std : : vector < std : : vector < Vector2 > * > { new std : : vector < Vector2 > ( ) } : std : : vector < std : : vector < Vector2 > * > ( ) ) , segments ( segments ) , textureCoords ( textureCoords ) { }
void Capsule : : capVertex ( GLfloat y , GLfloat normalY , GLf loat textureCoordsV ) {
void Capsule : : capVertex ( Float y , Float normalY , F loat textureCoordsV ) {
positions ( 0 ) - > push_back ( { 0.0f , y , 0.0f } ) ;
normals ( 0 ) - > push_back ( { 0.0f , normalY , 0.0f } ) ;
@ -58,15 +58,15 @@ void Capsule::capVertex(GLfloat y, GLfloat normalY, GLfloat textureCoordsV) {
textureCoords2D ( 0 ) - > push_back ( { 0.5 , textureCoordsV } ) ;
}
void Capsule : : hemisphereVertexRings ( std : : uint32_t count , GLf loat centerY , Rad startRingAngle , Rad ringAngleIncrement , GLfloat startTextureCoordsV , GLf loat textureCoordsVIncrement ) {
void Capsule : : hemisphereVertexRings ( UnsignedInt count , F loat centerY , Rad startRingAngle , Rad ringAngleIncrement , Float startTextureCoordsV , F loat textureCoordsVIncrement ) {
Rad segmentAngleIncrement = 2 * Rad ( Constants : : pi ( ) ) / segments ;
GLf loat x , y , z ;
for ( std : : uint32_ t i = 0 ; i ! = count ; + + i ) {
F loat x , y , z ;
for ( UnsignedIn t i = 0 ; i ! = count ; + + i ) {
Rad ringAngle = startRingAngle + i * ringAngleIncrement ;
x = z = Math : : cos ( ringAngle ) ;
y = Math : : sin ( ringAngle ) ;
for ( std : : uint32_ t j = 0 ; j ! = segments ; + + j ) {
for ( UnsignedIn t j = 0 ; j ! = segments ; + + j ) {
Rad segmentAngle = j * segmentAngleIncrement ;
positions ( 0 ) - > push_back ( { x * Math : : sin ( segmentAngle ) , centerY + y , z * Math : : cos ( segmentAngle ) } ) ;
normals ( 0 ) - > push_back ( { x * Math : : sin ( segmentAngle ) , y , z * Math : : cos ( segmentAngle ) } ) ;
@ -84,10 +84,10 @@ void Capsule::hemisphereVertexRings(std::uint32_t count, GLfloat centerY, Rad st
}
}
void Capsule : : cylinderVertexRings ( std : : uint32_t count , GLfloat startY , GLfloat yIncrement , GLfloat startTextureCoordsV , GLf loat textureCoordsVIncrement ) {
void Capsule : : cylinderVertexRings ( UnsignedInt count , Float startY , Float yIncrement , Float startTextureCoordsV , F loat textureCoordsVIncrement ) {
Rad segmentAngleIncrement = 2 * Rad ( Constants : : pi ( ) ) / segments ;
for ( std : : uint32_ t i = 0 ; i ! = count ; + + i ) {
for ( std : : uint32_ t j = 0 ; j ! = segments ; + + j ) {
for ( UnsignedIn t i = 0 ; i ! = count ; + + i ) {
for ( UnsignedIn t j = 0 ; j ! = segments ; + + j ) {
Rad segmentAngle = j * segmentAngleIncrement ;
positions ( 0 ) - > push_back ( { Math : : sin ( segmentAngle ) , startY , Math : : cos ( segmentAngle ) } ) ;
normals ( 0 ) - > push_back ( { Math : : sin ( segmentAngle ) , 0.0f , Math : : cos ( segmentAngle ) } ) ;
@ -108,7 +108,7 @@ void Capsule::cylinderVertexRings(std::uint32_t count, GLfloat startY, GLfloat y
}
void Capsule : : bottomFaceRing ( ) {
for ( std : : uint32_ t j = 0 ; j ! = segments ; + + j ) {
for ( UnsignedIn t j = 0 ; j ! = segments ; + + j ) {
/* Bottom vertex */
indices ( ) - > push_back ( 0 ) ;
@ -121,16 +121,16 @@ void Capsule::bottomFaceRing() {
}
}
void Capsule : : faceRings ( std : : uint32_t count , std : : uint32_ t offset ) {
std : : uint32_ t vertexSegments = segments + ( textureCoords = = TextureCoords : : Generate ? 1 : 0 ) ;
void Capsule : : faceRings ( UnsignedInt count , UnsignedIn t offset ) {
UnsignedIn t vertexSegments = segments + ( textureCoords = = TextureCoords : : Generate ? 1 : 0 ) ;
for ( std : : uint32_ t i = 0 ; i ! = count ; + + i ) {
for ( std : : uint32_ t j = 0 ; j ! = segments ; + + j ) {
std : : uint32_ t bottomLeft = i * vertexSegments + j + offset ;
std : : uint32_ t bottomRight = ( ( j ! = segments - 1 | | textureCoords = = TextureCoords : : Generate ) ?
for ( UnsignedIn t i = 0 ; i ! = count ; + + i ) {
for ( UnsignedIn t j = 0 ; j ! = segments ; + + j ) {
UnsignedIn t bottomLeft = i * vertexSegments + j + offset ;
UnsignedIn t bottomRight = ( ( j ! = segments - 1 | | textureCoords = = TextureCoords : : Generate ) ?
i * vertexSegments + j + 1 + offset : i * segments + offset ) ;
std : : uint32_ t topLeft = bottomLeft + vertexSegments ;
std : : uint32_ t topRight = bottomRight + vertexSegments ;
UnsignedIn t topLeft = bottomLeft + vertexSegments ;
UnsignedIn t topRight = bottomRight + vertexSegments ;
indices ( ) - > push_back ( bottomLeft ) ;
indices ( ) - > push_back ( bottomRight ) ;
@ -143,9 +143,9 @@ void Capsule::faceRings(std::uint32_t count, std::uint32_t offset) {
}
void Capsule : : topFaceRing ( ) {
std : : uint32_ t vertexSegments = segments + ( textureCoords = = TextureCoords : : Generate ? 1 : 0 ) ;
UnsignedIn t vertexSegments = segments + ( textureCoords = = TextureCoords : : Generate ? 1 : 0 ) ;
for ( std : : uint32_ t j = 0 ; j ! = segments ; + + j ) {
for ( UnsignedIn t j = 0 ; j ! = segments ; + + j ) {
/* Bottom left vertex */
indices ( ) - > push_back ( normals ( 0 ) - > size ( ) - vertexSegments + j - 1 ) ;