Browse Source

Primitives: get rid of useless classes.

All functionality is now available through free functions. The classes
are now just deprecated wrappers and/or typedefs and will be removed in
some future release.
pull/205/head
Vladimír Vondruš 8 years ago
parent
commit
c139e0384d
  1. 27
      doc/changelog.dox
  2. 12
      doc/generated/shaders.cpp
  3. 4
      doc/snippets/Magnum.cpp
  4. 4
      src/Magnum/DebugTools/Implementation/AbstractBoxRenderer.cpp
  5. 4
      src/Magnum/DebugTools/Implementation/CapsuleRenderer.cpp
  6. 4
      src/Magnum/DebugTools/Implementation/CylinderRenderer.cpp
  7. 4
      src/Magnum/DebugTools/Implementation/LineSegmentRenderer.cpp
  8. 4
      src/Magnum/DebugTools/Implementation/PointRenderer.cpp
  9. 4
      src/Magnum/DebugTools/Implementation/SphereRenderer.cpp
  10. 6
      src/Magnum/MeshTools/Test/SubdivideRemoveDuplicatesBenchmark.cpp
  11. 2
      src/Magnum/Primitives/Axis.h
  12. 31
      src/Magnum/Primitives/Capsule.cpp
  13. 159
      src/Magnum/Primitives/Capsule.h
  14. 18
      src/Magnum/Primitives/Circle.cpp
  15. 58
      src/Magnum/Primitives/Circle.h
  16. 14
      src/Magnum/Primitives/Crosshair.cpp
  17. 52
      src/Magnum/Primitives/Crosshair.h
  18. 20
      src/Magnum/Primitives/Cube.cpp
  19. 77
      src/Magnum/Primitives/Cube.h
  20. 36
      src/Magnum/Primitives/Cylinder.cpp
  21. 136
      src/Magnum/Primitives/Cylinder.h
  22. 8
      src/Magnum/Primitives/Icosphere.cpp
  23. 35
      src/Magnum/Primitives/Icosphere.h
  24. 14
      src/Magnum/Primitives/Line.cpp
  25. 48
      src/Magnum/Primitives/Line.h
  26. 16
      src/Magnum/Primitives/Plane.cpp
  27. 82
      src/Magnum/Primitives/Plane.h
  28. 16
      src/Magnum/Primitives/Square.cpp
  29. 80
      src/Magnum/Primitives/Square.h
  30. 8
      src/Magnum/Primitives/Test/CapsuleTest.cpp
  31. 4
      src/Magnum/Primitives/Test/CircleTest.cpp
  32. 4
      src/Magnum/Primitives/Test/CrosshairTest.cpp
  33. 6
      src/Magnum/Primitives/Test/CubeTest.cpp
  34. 6
      src/Magnum/Primitives/Test/CylinderTest.cpp
  35. 2
      src/Magnum/Primitives/Test/IcosphereTest.cpp
  36. 4
      src/Magnum/Primitives/Test/LineTest.cpp
  37. 4
      src/Magnum/Primitives/Test/PlaneTest.cpp
  38. 4
      src/Magnum/Primitives/Test/SquareTest.cpp
  39. 6
      src/Magnum/Primitives/Test/UVSphereTest.cpp
  40. 22
      src/Magnum/Primitives/UVSphere.cpp
  41. 95
      src/Magnum/Primitives/UVSphere.h

27
doc/changelog.dox

@ -53,6 +53,33 @@ See also:
@subsection changelog-latest-deprecated Deprecated APIs
- Class @cpp Primitives::Capsule2D @ce and @cpp Primitives::Capsule3D @ce is
deprecated, use @ref Primitives::capsule2DWireframe(),
@ref Primitives::capsule3DSolid() and @ref Primitives::capsule3DWireframe()
free functions instead
- Class @cpp Primitives::Circle @ce is deprecated, use
@ref Primitives::circle2DSolid() and @ref Primitives::circle2DWireframe()
instead
- Class @cpp Primitives::Crosshair2D @ce and @cpp Primitives::Crosshair3D @ce
is deprecated, use @ref Primitives::crosshair2D() and
@ref Primitives::crosshair3D() free function instead
- Class @cpp Primitives::Cube @ce is deprecated, use @ref Primitives::cubeSolid(),
@ref Primitives::cubeSolidStrip() and @ref Primitives::cubeWireframe() free
functions instead
- Class @cpp Primitives::Cylinder @ce is deprecated, use
@ref Primitives::cylinderSolid(), @ref Primitives::cylinderWireframe() free
functions instead
- Class @cpp Primitives::Icosphere @ce is deprecated, use the
@ref Primitives::icosphereSolid() free function instead
- Class @cpp Primitives::Plane @ce is deprecated, use
@ref Primitives::planeSolid() and @ref Primitives::planeWireframe() free
functions instead
- Class @cpp Primitives::Square @ce is deprecated, use
@ref Primitives::squareSolid() and @ref Primitives::squareWireframe() free
functions instead
- Class @cpp Primitives::UVSphere @ce is deprecated, use
@ref Primitives::uvSphereSolid() and @ref Primitives::uvSphereWireframe()
free functions instead
- @cpp Shaders::*Vector::setVectorTexture() @ce, @cpp Shaders::Flat::setTexture() @ce,
@cpp Shaders::Phong::setAmbientTexture() @ce, @cpp Shaders::Phong::setDiffuseTexture() @ce,
@cpp Shaders::Phong::setSpecularTexture() @ce and @cpp Shaders::Phong::setTextures() @ce

12
doc/generated/shaders.cpp

@ -152,7 +152,7 @@ namespace {
std::string ShaderVisualizer::phong() {
std::unique_ptr<Buffer> vertices, indices;
Mesh mesh{NoCreate};
std::tie(mesh, vertices, indices) = MeshTools::compile(Primitives::UVSphere::solid(16, 32), BufferUsage::StaticDraw);
std::tie(mesh, vertices, indices) = MeshTools::compile(Primitives::uvSphereSolid(16, 32), BufferUsage::StaticDraw);
Shaders::Phong shader;
shader.setAmbientColor(0x22272e_rgbf)
@ -171,7 +171,7 @@ std::string ShaderVisualizer::phong() {
std::string ShaderVisualizer::meshVisualizer() {
std::unique_ptr<Buffer> vertices, indices;
Mesh mesh{NoCreate};
std::tie(mesh, vertices, indices) = MeshTools::compile(Primitives::Icosphere::solid(1), BufferUsage::StaticDraw);
std::tie(mesh, vertices, indices) = MeshTools::compile(Primitives::icosphereSolid(1), BufferUsage::StaticDraw);
const Matrix4 projection = Projection*Transformation*
Matrix4::rotationZ(13.7_degf)*
@ -191,7 +191,7 @@ std::string ShaderVisualizer::meshVisualizer() {
std::string ShaderVisualizer::flat() {
std::unique_ptr<Buffer> vertices, indices;
Mesh mesh{NoCreate};
std::tie(mesh, vertices, indices) = MeshTools::compile(Primitives::UVSphere::solid(16, 32), BufferUsage::StaticDraw);
std::tie(mesh, vertices, indices) = MeshTools::compile(Primitives::uvSphereSolid(16, 32), BufferUsage::StaticDraw);
Shaders::Flat3D shader;
shader.setColor(BaseColor)
@ -203,7 +203,7 @@ std::string ShaderVisualizer::flat() {
}
std::string ShaderVisualizer::vertexColor() {
Trade::MeshData3D sphere = Primitives::UVSphere::solid(32, 64);
Trade::MeshData3D sphere = Primitives::uvSphereSolid(32, 64);
/* Color vertices nearest to given position */
auto target = Vector3{2.0f, 2.0f, 7.0f}.normalized();
@ -248,7 +248,7 @@ std::string ShaderVisualizer::vector() {
Mesh mesh{NoCreate};
std::unique_ptr<Buffer> vertices;
std::tie(mesh, vertices, std::ignore) = MeshTools::compile(Primitives::Square::solid(Primitives::Square::TextureCoords::Generate), BufferUsage::StaticDraw);
std::tie(mesh, vertices, std::ignore) = MeshTools::compile(Primitives::squareSolid(Primitives::SquareTextureCoords::Generate), BufferUsage::StaticDraw);
Shaders::Vector2D shader;
shader.setColor(BaseColor)
@ -282,7 +282,7 @@ std::string ShaderVisualizer::distanceFieldVector() {
Mesh mesh{NoCreate};
std::unique_ptr<Buffer> vertices;
std::tie(mesh, vertices, std::ignore) = MeshTools::compile(Primitives::Square::solid(Primitives::Square::TextureCoords::Generate), BufferUsage::StaticDraw);
std::tie(mesh, vertices, std::ignore) = MeshTools::compile(Primitives::squareSolid(Primitives::SquareTextureCoords::Generate), BufferUsage::StaticDraw);
Shaders::DistanceFieldVector2D shader;
shader.setColor(BaseColor)

4
doc/snippets/Magnum.cpp

@ -794,7 +794,7 @@ mesh.setPrimitive(MeshPrimitive::Triangles)
{
/* [Mesh-interleaved] */
/* Non-indexed primitive with positions and normals */
Trade::MeshData3D plane = Primitives::Plane::solid();
Trade::MeshData3D plane = Primitives::planeSolid();
/* Fill a vertex buffer with interleaved position and normal data */
Buffer buffer;
@ -844,7 +844,7 @@ mesh.setPrimitive(MeshPrimitive::Triangles)
{
/* [Mesh-indexed-tools] */
// Indexed primitive
Trade::MeshData3D cube = Primitives::Cube::solid();
Trade::MeshData3D cube = Primitives::cubeSolid();
// Fill vertex buffer with interleaved position and normal data
Buffer vertexBuffer;

4
src/Magnum/DebugTools/Implementation/AbstractBoxRenderer.cpp

@ -34,11 +34,11 @@
namespace Magnum { namespace DebugTools { namespace Implementation {
AbstractBoxRenderer<2>::AbstractBoxRenderer(): AbstractShapeRenderer<2>("box2d", "box2d-vertices", {}) {
if(!wireframeMesh) AbstractShapeRenderer<2>::createResources(Primitives::Square::wireframe());
if(!wireframeMesh) AbstractShapeRenderer<2>::createResources(Primitives::squareWireframe());
}
AbstractBoxRenderer<3>::AbstractBoxRenderer(): AbstractShapeRenderer<3>("box3d", "box3d-vertices", "box3d-indices") {
if(!wireframeMesh) AbstractShapeRenderer<3>::createResources(Primitives::Cube::wireframe());
if(!wireframeMesh) AbstractShapeRenderer<3>::createResources(Primitives::cubeWireframe());
}
template class AbstractBoxRenderer<2>;

4
src/Magnum/DebugTools/Implementation/CapsuleRenderer.cpp

@ -41,7 +41,7 @@ namespace Magnum { namespace DebugTools { namespace Implementation {
AbstractCapsuleRenderer<2>::AbstractCapsuleRenderer(): AbstractShapeRenderer<2>("capsule2d", "capsule2d-vertices", "capsule2d-indices") {
constexpr UnsignedInt rings = 10;
if(!wireframeMesh) createResources(Primitives::Capsule2D::wireframe(rings, 1, 1.0f));
if(!wireframeMesh) createResources(Primitives::capsule2DWireframe(rings, 1, 1.0f));
/* Bottom hemisphere */
if(!(bottom = ResourceManager::instance().get<MeshView>("capsule2d-bottom"))) {
@ -71,7 +71,7 @@ AbstractCapsuleRenderer<2>::AbstractCapsuleRenderer(): AbstractShapeRenderer<2>(
AbstractCapsuleRenderer<3>::AbstractCapsuleRenderer(): AbstractShapeRenderer<3>("capsule3d", "capsule3d-vertices", "capsule3d-indices") {
constexpr UnsignedInt rings = 10;
constexpr UnsignedInt segments = 40;
if(!wireframeMesh) createResources(Primitives::Capsule3D::wireframe(rings, 1, segments, 1.0f));
if(!wireframeMesh) createResources(Primitives::capsule3DWireframe(rings, 1, segments, 1.0f));
/* Bottom hemisphere */
if(!(bottom = ResourceManager::instance().get<MeshView>("capsule3d-bottom"))) {

4
src/Magnum/DebugTools/Implementation/CylinderRenderer.cpp

@ -39,11 +39,11 @@
namespace Magnum { namespace DebugTools { namespace Implementation {
AbstractCylinderRenderer<2>::AbstractCylinderRenderer(): AbstractShapeRenderer<2>("cylinder2d", "cylinder2d-vertices", {}) {
if(!wireframeMesh) createResources(Primitives::Square::wireframe());
if(!wireframeMesh) createResources(Primitives::squareWireframe());
}
AbstractCylinderRenderer<3>::AbstractCylinderRenderer(): AbstractShapeRenderer<3>("cylinder3d", "cylinder3d-vertices", "cylinder3d-indices") {
if(!wireframeMesh) createResources(Primitives::Cylinder::wireframe(1, 40, 1.0f));
if(!wireframeMesh) createResources(Primitives::cylinderWireframe(1, 40, 1.0f));
}
template<UnsignedInt dimensions> CylinderRenderer<dimensions>::CylinderRenderer(const Shapes::Implementation::AbstractShape<dimensions>& cylinder): cylinder(static_cast<const Shapes::Implementation::Shape<Shapes::Cylinder<dimensions>>&>(cylinder).shape) {}

4
src/Magnum/DebugTools/Implementation/LineSegmentRenderer.cpp

@ -47,8 +47,8 @@ namespace {
template<> inline ResourceKey vertexBufferKey<3>() { return ResourceKey("line3d-vertices"); }
template<UnsignedInt dimensions> typename MeshData<dimensions>::Type meshData();
template<> inline Trade::MeshData2D meshData<2>() { return Primitives::Line2D::wireframe(); }
template<> inline Trade::MeshData3D meshData<3>() { return Primitives::Line3D::wireframe(); }
template<> inline Trade::MeshData2D meshData<2>() { return Primitives::line2D(); }
template<> inline Trade::MeshData3D meshData<3>() { return Primitives::line3D(); }
}
template<UnsignedInt dimensions> LineSegmentRenderer<dimensions>::LineSegmentRenderer(const Shapes::Implementation::AbstractShape<dimensions>& line): AbstractShapeRenderer<dimensions>(meshKey<dimensions>(), vertexBufferKey<dimensions>(), {}), line(static_cast<const Shapes::Implementation::Shape<Shapes::LineSegment<dimensions>>&>(line).shape) {

4
src/Magnum/DebugTools/Implementation/PointRenderer.cpp

@ -45,8 +45,8 @@ namespace {
template<> inline ResourceKey vertexBufferKey<3>() { return ResourceKey("point3d-vertices"); }
template<UnsignedInt dimensions> typename MeshData<dimensions>::Type meshData();
template<> inline Trade::MeshData2D meshData<2>() { return Primitives::Crosshair2D::wireframe(); }
template<> inline Trade::MeshData3D meshData<3>() { return Primitives::Crosshair3D::wireframe(); }
template<> inline Trade::MeshData2D meshData<2>() { return Primitives::crosshair2D(); }
template<> inline Trade::MeshData3D meshData<3>() { return Primitives::crosshair3D(); }
}
template<UnsignedInt dimensions> PointRenderer<dimensions>::PointRenderer(const Shapes::Implementation::AbstractShape<dimensions>& point): AbstractShapeRenderer<dimensions>(meshKey<dimensions>(), vertexBufferKey<dimensions>(), {}), point(static_cast<const Shapes::Implementation::Shape<Shapes::Point<dimensions>>&>(point).shape) {

4
src/Magnum/DebugTools/Implementation/SphereRenderer.cpp

@ -37,11 +37,11 @@
namespace Magnum { namespace DebugTools { namespace Implementation {
AbstractSphereRenderer<2>::AbstractSphereRenderer(): AbstractShapeRenderer<2>("sphere2d", "sphere2d-vertices", {}) {
if(!wireframeMesh) createResources(Primitives::Circle::wireframe(40));
if(!wireframeMesh) createResources(Primitives::circle2DWireframe(40));
}
AbstractSphereRenderer<3>::AbstractSphereRenderer(): AbstractShapeRenderer<3>("sphere3d", "sphere3d-vertices", "sphere3d-indices") {
if(!wireframeMesh) createResources(Primitives::UVSphere::wireframe(20, 40));
if(!wireframeMesh) createResources(Primitives::uvSphereWireframe(20, 40));
}
template<UnsignedInt dimensions> SphereRenderer<dimensions>::SphereRenderer(const Shapes::Implementation::AbstractShape<dimensions>& sphere): sphere(static_cast<const Shapes::Implementation::Shape<Shapes::Sphere<dimensions>>&>(sphere).shape) {}

6
src/Magnum/MeshTools/Test/SubdivideRemoveDuplicatesBenchmark.cpp

@ -56,7 +56,7 @@ namespace {
void SubdivideRemoveDuplicatesBenchmark::subdivide() {
CORRADE_BENCHMARK(3) {
Trade::MeshData3D icosphere = Primitives::Icosphere::solid(0);
Trade::MeshData3D icosphere = Primitives::icosphereSolid(0);
/* Subdivide 5 times */
for(std::size_t i = 0; i != 5; ++i)
@ -66,7 +66,7 @@ void SubdivideRemoveDuplicatesBenchmark::subdivide() {
void SubdivideRemoveDuplicatesBenchmark::subdivideAndRemoveDuplicatesAfter() {
CORRADE_BENCHMARK(3) {
Trade::MeshData3D icosphere = Primitives::Icosphere::solid(0);
Trade::MeshData3D icosphere = Primitives::icosphereSolid(0);
/* Subdivide 5 times */
for(std::size_t i = 0; i != 5; ++i)
@ -79,7 +79,7 @@ void SubdivideRemoveDuplicatesBenchmark::subdivideAndRemoveDuplicatesAfter() {
void SubdivideRemoveDuplicatesBenchmark::subdivideAndRemoveDuplicatesInBetween() {
CORRADE_BENCHMARK(3) {
Trade::MeshData3D icosphere = Primitives::Icosphere::solid(0);
Trade::MeshData3D icosphere = Primitives::icosphereSolid(0);
/* Subdivide 5 times and remove duplicates during the operation */
for(std::size_t i = 0; i != 5; ++i) {

2
src/Magnum/Primitives/Axis.h

@ -39,6 +39,7 @@ namespace Magnum { namespace Primitives {
Two color-coded arrows for visualizing orientation (XY is RG). Indexed
@ref MeshPrimitive::Lines with vertex colors.
@see @ref axis3D(), @ref crosshair2D(), @ref line2D()
*/
MAGNUM_PRIMITIVES_EXPORT Trade::MeshData2D axis2D();
@ -47,6 +48,7 @@ MAGNUM_PRIMITIVES_EXPORT Trade::MeshData2D axis2D();
Three color-coded arrows for visualizing orientation (XYZ is RGB). Indexed
@ref MeshPrimitive::Lines with vertex colors.
@see @ref axis2D(), @ref crosshair3D(), @ref line3D()
*/
MAGNUM_PRIMITIVES_EXPORT Trade::MeshData3D axis3D();

31
src/Magnum/Primitives/Capsule.cpp

@ -35,8 +35,9 @@
namespace Magnum { namespace Primitives {
Trade::MeshData2D Capsule2D::wireframe(UnsignedInt hemisphereRings, UnsignedInt cylinderRings, Float halfLength) {
CORRADE_ASSERT(hemisphereRings >= 1 && cylinderRings >= 1, "Capsule must have at least one hemisphere ring, one cylinder ring and three segments",
Trade::MeshData2D capsule2DWireframe(const UnsignedInt hemisphereRings, const UnsignedInt cylinderRings, const Float halfLength) {
CORRADE_ASSERT(hemisphereRings >= 1 && cylinderRings >= 1,
"Primitives::capsule2DWireframe(): at least one hemisphere ring and one cylinder ring expected",
(Trade::MeshData2D{MeshPrimitive::Triangles, {}, {}, {}, {}, nullptr}));
std::vector<Vector2> positions;
@ -91,11 +92,12 @@ Trade::MeshData2D Capsule2D::wireframe(UnsignedInt hemisphereRings, UnsignedInt
return Trade::MeshData2D{MeshPrimitive::Lines, std::move(indices), {std::move(positions)}, {}, {}, nullptr};
}
Trade::MeshData3D Capsule3D::solid(UnsignedInt hemisphereRings, UnsignedInt cylinderRings, UnsignedInt segments, Float halfLength, 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 capsule3DSolid(const UnsignedInt hemisphereRings, const UnsignedInt cylinderRings, const UnsignedInt segments, const Float halfLength, const CapsuleTextureCoords textureCoords) {
CORRADE_ASSERT(hemisphereRings >= 1 && cylinderRings >= 1 && segments >= 3,
"Primitives::capsule3DSolid(): at least one hemisphere ring, one cylinder ring and three segments expected",
(Trade::MeshData3D{MeshPrimitive::Triangles, {}, {}, {}, {}, {}, nullptr}));
Implementation::Spheroid capsule(segments, textureCoords == TextureCoords::Generate ?
Implementation::Spheroid capsule(segments, textureCoords == CapsuleTextureCoords::Generate ?
Implementation::Spheroid::TextureCoords::Generate :
Implementation::Spheroid::TextureCoords::DontGenerate);
@ -126,8 +128,9 @@ Trade::MeshData3D Capsule3D::solid(UnsignedInt hemisphereRings, UnsignedInt cyli
return capsule.finalize();
}
Trade::MeshData3D Capsule3D::wireframe(const UnsignedInt hemisphereRings, const UnsignedInt cylinderRings, const UnsignedInt segments, const Float halfLength) {
CORRADE_ASSERT(hemisphereRings >= 1 && cylinderRings >= 1 && segments >= 4 && segments%4 == 0, "Primitives::Capsule::wireframe(): improper parameters",
Trade::MeshData3D capsule3DWireframe(const UnsignedInt hemisphereRings, const UnsignedInt cylinderRings, const UnsignedInt segments, const Float halfLength) {
CORRADE_ASSERT(hemisphereRings >= 1 && cylinderRings >= 1 && segments >= 4 && segments%4 == 0,
"Primitives::capsule3DWireframe(): at least one hemisphere and cylinder ring and multiples of 4 segments expected",
(Trade::MeshData3D{MeshPrimitive::Triangles, {}, {}, {}, {}, {}, nullptr}));
Implementation::WireframeSpheroid capsule(segments/4);
@ -148,4 +151,18 @@ Trade::MeshData3D Capsule3D::wireframe(const UnsignedInt hemisphereRings, const
return capsule.finalize();
}
#ifdef MAGNUM_BUILD_DEPRECATED
Trade::MeshData2D Capsule2D::wireframe(const UnsignedInt hemisphereRings, const UnsignedInt cylinderRings, const Float halfLength) {
return capsule2DWireframe(hemisphereRings, cylinderRings, halfLength);
}
Trade::MeshData3D Capsule3D::solid(const UnsignedInt hemisphereRings, const UnsignedInt cylinderRings, const UnsignedInt segments, const Float halfLength, const CapsuleTextureCoords textureCoords) {
return capsule3DSolid(hemisphereRings, cylinderRings, segments, halfLength, textureCoords);
}
Trade::MeshData3D Capsule3D::wireframe(const UnsignedInt hemisphereRings, const UnsignedInt cylinderRings, const UnsignedInt segments, const Float halfLength) {
return capsule3DWireframe(hemisphereRings, cylinderRings, segments, halfLength);
}
#endif
}}

159
src/Magnum/Primitives/Capsule.h

@ -26,84 +26,119 @@
*/
/** @file
* @brief Class @ref Magnum::Primitives::Capsule2D, @ref Magnum::Primitives::Capsule3D
* @brief Function @ref Magnum::Primitives::capsule2DWireframe(), @ref Magnum::Primitives::capsule3DSolid(), @ref Magnum::Primitives::capsule3DWireframe()
*/
#include "Magnum/Primitives/visibility.h"
#include "Magnum/Trade/Trade.h"
#ifdef MAGNUM_BUILD_DEPRECATED
#include <Corrade/Utility/Macros.h>
#endif
namespace Magnum { namespace Primitives {
/**
@brief 2D capsule primitive
@brief Wireframe 2D capsule
@param hemisphereRings Number of (line) rings for each hemisphere. Must be
larger or equal to @cpp 1 @ce.
@param cylinderRings Number of (line) rings for cylinder. Must be larger or
equal to @cpp 1 @ce.
@param halfLength Half the length of cylinder part
Cylinder of radius @cpp 1.0f @ce along Y axis with hemispheres instead of caps.
Indexed @ref MeshPrimitive::Lines.
@see @ref capsule3DSolid(), @ref capsule3DWireframe(), @ref circle2DWireframe(),
@ref squareWireframe()
*/
MAGNUM_PRIMITIVES_EXPORT Trade::MeshData2D capsule2DWireframe(UnsignedInt hemisphereRings, UnsignedInt cylinderRings, Float halfLength);
#ifdef MAGNUM_BUILD_DEPRECATED
/**
@brief 2D capsule
@deprecated Use @ref capsule2DWireframe() instead.
*/
struct MAGNUM_PRIMITIVES_EXPORT Capsule2D {
/** @copybrief capsule2DWireframe()
* @deprecated Use @ref capsule2DWireframe() instead.
*/
CORRADE_DEPRECATED("use capsule2DWireframe() instead") static Trade::MeshData2D wireframe(UnsignedInt hemisphereRings, UnsignedInt cylinderRings, Float halfLength);
};
#endif
/**
@brief Whether to generate capsule texture coordinates
Cylinder of radius `1` along Y axis with hemispheres instead of caps.
@see @ref capsule3DSolid()
*/
class MAGNUM_PRIMITIVES_EXPORT Capsule2D {
public:
/**
* @brief Wireframe capsule
* @param hemisphereRings Number of (line) rings for each hemisphere.
* Must be larger or equal to 1.
* @param cylinderRings Number of (line) rings for cylinder. Must be
* larger or equal to 1.
* @param halfLength Half the length of cylinder part
*
* Indexed @ref MeshPrimitive::Lines.
*/
static Trade::MeshData2D wireframe(UnsignedInt hemisphereRings, UnsignedInt cylinderRings, Float halfLength);
enum class CapsuleTextureCoords: UnsignedByte {
DontGenerate, /**< Don't generate texture coordinates */
Generate /**< Generate texture coordinates */
};
/**
@brief 3D capsule primitive
@brief Solid 3D capsule
@param hemisphereRings Number of (face) rings for each hemisphere. Must be
larger or equal to @cpp 1 @ce.
@param cylinderRings Number of (face) rings for cylinder. Must be larger or
equal to @cpp 1 @ce.
@param segments Number of (face) segments. Must be larger or equal to
@cpp 3 @ce.
@param halfLength Half the length of cylinder part
@param textureCoords Whether to generate texture coordinates
Cylinder of radius `1` along Y axis with hemispheres instead of caps.
Cylinder of radius @cpp 1.0f @ce along Y axis with hemispheres instead of caps.
Indexed @ref MeshPrimitive::Triangles with normals and optional 2D texture
coordinates. If texture coordinates are generated, vertices of one segment are
duplicated for texture wrapping.
The capsule is by default created with radius set to @f$ 1.0 @f$. In order to
get radius @f$ r @f$, length @f$ l @f$ and preserve correct normals, set
@p halfLength to @f$ 0.5 \frac{l}{r} @f$ and then scale all
@ref Trade::MeshData3D::positions() by @f$ r @f$, for example using
@ref MeshTools::transformPointsInPlace().
@see @ref capsule3DWireframe(), @ref capsule2DWireframe(), @ref cylinderSolid()
*/
MAGNUM_PRIMITIVES_EXPORT Trade::MeshData3D capsule3DSolid(UnsignedInt hemisphereRings, UnsignedInt cylinderRings, UnsignedInt segments, Float halfLength, CapsuleTextureCoords textureCoords = CapsuleTextureCoords::DontGenerate);
/**
@brief Wireframe 3D capsule
@param hemisphereRings Number of (line) rings for each hemisphere. Must be
larger or equal to @cpp 1 @ce.
@param cylinderRings Number of (line) rings for cylinder. Must be larger or
equal to @cpp 1 @ce.
@param segments Number of line segments. Must be larger or equal to
@cpp 4 @ce and multiple of @cpp 4 @ce.
@param halfLength Half the length of cylinder part
Cylinder of radius @cpp 1.0f @ce along Y axis with hemispheres instead of caps.
Indexed @ref MeshPrimitive::Lines.
@see @ref capsule2DWireframe(), @ref capsule3DSolid(), @ref cylinderSolid()
*/
class MAGNUM_PRIMITIVES_EXPORT Capsule3D {
public:
/** @brief Whether to generate texture coordinates */
enum class TextureCoords: UnsignedByte {
Generate, /**< Generate texture coordinates */
DontGenerate /**< Don't generate texture coordinates */
};
/**
* @brief Solid capsule
* @param hemisphereRings Number of (face) rings for each hemisphere.
* Must be larger or equal to 1.
* @param cylinderRings Number of (face) rings for cylinder. Must be
* larger or equal to 1.
* @param segments Number of (face) segments. Must be larger or
* equal to 3.
* @param halfLength Half the length of cylinder part
* @param textureCoords Whether to generate texture coordinates.
*
* Indexed @ref MeshPrimitive::Triangles with normals and optional 2D
* texture coordinates. If texture coordinates are generated, vertices
* of one segment are duplicated for texture wrapping.
*
* The capsule is by default created with radius set to @cpp 1.0f @ce.
* In order to get radius @f$ r @f$, length @f$ l @f$ and preserve
* correct normals, set @p halfLength to @f$ 0.5 \frac{l}{r} @f$ and
* then scale all @ref Trade::MeshData3D::positions() by @f$ r @f$, for
* example using @ref MeshTools::transformPointsInPlace().
*/
static Trade::MeshData3D solid(UnsignedInt hemisphereRings, UnsignedInt cylinderRings, UnsignedInt segments, Float halfLength, TextureCoords textureCoords = TextureCoords::DontGenerate);
/**
* @brief Wireframe capsule
* @param hemisphereRings Number of (line) rings for each hemisphere.
* Must be larger or equal to 1.
* @param cylinderRings Number of (line) rings for cylinder. Must be
* larger or equal to 1.
* @param segments Number of line segments. Must be larger or
* equal to 4 and multiple of 4.
* @param halfLength Half the length of cylinder part
*
* Indexed @ref MeshPrimitive::Lines.
*/
static Trade::MeshData3D wireframe(UnsignedInt hemisphereRings, UnsignedInt cylinderRings, UnsignedInt segments, Float halfLength);
MAGNUM_PRIMITIVES_EXPORT Trade::MeshData3D capsule3DWireframe(UnsignedInt hemisphereRings, UnsignedInt cylinderRings, UnsignedInt segments, Float halfLength);
#ifdef MAGNUM_BUILD_DEPRECATED
/**
@brief 3D capsule
@deprecated Use @ref capsule3DSolid() or @ref capsule3DWireframe() instead.
*/
struct MAGNUM_PRIMITIVES_EXPORT Capsule3D {
/** @brief @copybrief CapsuleTextureCoords
* @deprecated Use @ref CapsuleTextureCoords instead.
*/
typedef CORRADE_DEPRECATED("use CapsuleTextureCoords instead") CapsuleTextureCoords TextureCoords;
/** @brief @copybrief capsule3DSolid()
* @deprecated Use @ref capsule3DSolid() instead.
*/
CORRADE_DEPRECATED("use capsule3DSolid() instead") static Trade::MeshData3D solid(UnsignedInt hemisphereRings, UnsignedInt cylinderRings, UnsignedInt segments, Float halfLength, CapsuleTextureCoords textureCoords = CapsuleTextureCoords::DontGenerate);
/** @brief @copybrief capsule3DWireframe()
* @deprecated Use @ref capsule3DWireframe() instead.
*/
CORRADE_DEPRECATED("use capsule3DWireframe() instead") static Trade::MeshData3D wireframe(UnsignedInt hemisphereRings, UnsignedInt cylinderRings, UnsignedInt segments, Float halfLength);
};
#endif
}}

18
src/Magnum/Primitives/Circle.cpp

@ -32,8 +32,8 @@
namespace Magnum { namespace Primitives {
Trade::MeshData2D Circle::solid(UnsignedInt segments) {
CORRADE_ASSERT(segments >= 3, "Primitives::Circle::solid(): segments must be >= 3",
Trade::MeshData2D circle2DSolid(const UnsignedInt segments) {
CORRADE_ASSERT(segments >= 3, "Primitives::circle2DSolid(): segments must be >= 3",
(Trade::MeshData2D{MeshPrimitive::TriangleFan, {}, {}, {}, {}, nullptr}));
std::vector<Vector2> positions;
@ -53,8 +53,8 @@ Trade::MeshData2D Circle::solid(UnsignedInt segments) {
return Trade::MeshData2D{MeshPrimitive::TriangleFan, {}, {std::move(positions)}, {}, {}, nullptr};
}
Trade::MeshData2D Circle::wireframe(UnsignedInt segments) {
CORRADE_ASSERT(segments >= 3, "Primitives::Circle::wireframe(): segments must be >= 3",
Trade::MeshData2D circle2DWireframe(const UnsignedInt segments) {
CORRADE_ASSERT(segments >= 3, "Primitives::circle2DWireframe(): segments must be >= 3",
(Trade::MeshData2D{MeshPrimitive::LineLoop, {}, {}, {}, {}, nullptr}));
std::vector<Vector2> positions;
@ -70,4 +70,14 @@ Trade::MeshData2D Circle::wireframe(UnsignedInt segments) {
return Trade::MeshData2D{MeshPrimitive::LineLoop, {}, {std::move(positions)}, {}, {}, nullptr};
}
#ifdef MAGNUM_BUILD_DEPRECATED
Trade::MeshData2D Circle::solid(const UnsignedInt segments) {
return circle2DSolid(segments);
}
Trade::MeshData2D Circle::wireframe(const UnsignedInt segments) {
return circle2DWireframe(segments);
}
#endif
}}

58
src/Magnum/Primitives/Circle.h

@ -26,39 +26,53 @@
*/
/** @file
* @brief Class @ref Magnum::Primitives::Circle
* @brief Function @ref Magnum::Primitives::circle2DSolid(), @ref Magnum::Primitives::circle2DWireframe()
*/
#include "Magnum/Primitives/visibility.h"
#include "Magnum/Trade/Trade.h"
#ifdef MAGNUM_BUILD_DEPRECATED
#include <Corrade/Utility/Macros.h>
#endif
namespace Magnum { namespace Primitives {
/**
@brief 2D circle primitive
@brief Solid 2D circle
@param segments Number of segments. Must be greater or equal to @cpp 3 @ce.
Circle with radius @cpp 1.0f @ce. Non-indexed @ref MeshPrimitive::TriangleFan.
@see @ref circle2DWireframe()
*/
MAGNUM_PRIMITIVES_EXPORT Trade::MeshData2D circle2DSolid(UnsignedInt segments);
/**
@brief Wireframe 2D circle
@param segments Number of segments. Must be greater or equal to @cpp 3 @ce.
Circle with radius `1`.
Circle with radius @cpp 1.0f @ce. Non-indexed @ref MeshPrimitive::LineLoop.
@see @ref circle2DSolid()
*/
class MAGNUM_PRIMITIVES_EXPORT Circle {
public:
/**
* @brief Solid circle
* @param segments Number of segments. Must be greater or equal to 3.
*
* Non-indexed @ref MeshPrimitive::TriangleFan.
*/
static Trade::MeshData2D solid(UnsignedInt segments);
/**
* @brief Wireframe circle
* @param segments Number of segments. Must be greater or equal to 3.
*
* Non-indexed @ref MeshPrimitive::LineLoop.
*/
static Trade::MeshData2D wireframe(UnsignedInt segments);
Circle() = delete;
MAGNUM_PRIMITIVES_EXPORT Trade::MeshData2D circle2DWireframe(UnsignedInt segments);
#ifdef MAGNUM_BUILD_DEPRECATED
/**
@brief 2D circle primitive
@deprecated Use @ref circle2DSolid() or @ref circle2DWireframe() instead.
*/
struct MAGNUM_PRIMITIVES_EXPORT Circle {
/** @brief @copybrief circle2DSolid()
* @deprecated Use @ref circle2DSolid() instead.
*/
CORRADE_DEPRECATED("use circle2DSolid() instead") static Trade::MeshData2D solid(UnsignedInt segments);
/** @brief @copybrief circle2DWireframe()
* @deprecated Use @ref circle2DWireframe() instead.
*/
CORRADE_DEPRECATED("use circle2DWireframe() instead") static Trade::MeshData2D wireframe(UnsignedInt segments);
};
#endif
}}

14
src/Magnum/Primitives/Crosshair.cpp

@ -32,14 +32,14 @@
namespace Magnum { namespace Primitives {
Trade::MeshData2D Crosshair2D::wireframe() {
Trade::MeshData2D crosshair2D() {
return Trade::MeshData2D{MeshPrimitive::Lines, {}, {{
{-1.0f, 0.0f}, {1.0f, 0.0f},
{ 0.0f, -1.0f}, {0.0f, 1.0f}
}}, {}, {}, nullptr};
}
Trade::MeshData3D Crosshair3D::wireframe() {
Trade::MeshData3D crosshair3D() {
return Trade::MeshData3D{MeshPrimitive::Lines, {}, {{
{-1.0f, 0.0f, 0.0f}, {1.0f, 0.0f, 0.0f},
{ 0.0f, -1.0f, 0.0f}, {0.0f, 1.0f, 0.0f},
@ -47,4 +47,14 @@ Trade::MeshData3D Crosshair3D::wireframe() {
}}, {}, {}, {}, nullptr};
}
#ifdef MAGNUM_BUILD_DEPRECATED
Trade::MeshData2D Crosshair2D::wireframe() {
return crosshair2D();
}
Trade::MeshData3D Crosshair3D::wireframe() {
return crosshair3D();
}
#endif
}}

52
src/Magnum/Primitives/Crosshair.h

@ -26,41 +26,59 @@
*/
/** @file
* @brief Class @ref Magnum::Primitives::Crosshair2D, @ref Magnum::Primitives::Crosshair3D
* @brief Function @ref Magnum::Primitives::crosshair2D(), @ref Magnum::Primitives::crosshair3D()
*/
#include "Magnum/Primitives/visibility.h"
#include "Magnum/Trade/Trade.h"
#ifdef MAGNUM_BUILD_DEPRECATED
#include <Corrade/Utility/Macros.h>
#endif
namespace Magnum { namespace Primitives {
/**
@brief 2D crosshair primitive
@brief 2D crosshair
2x2 wireframe crosshair (two crossed lines), non-indexed
@ref MeshPrimitive::Lines.
2x2 crosshair (two crossed lines), non-indexed @ref MeshPrimitive::Lines.
@see @ref crosshair3D(), @ref axis2D(), @ref line2D()
*/
class MAGNUM_PRIMITIVES_EXPORT Crosshair2D {
public:
/** @brief Wireframe crosshair */
static Trade::MeshData2D wireframe();
MAGNUM_PRIMITIVES_EXPORT Trade::MeshData2D crosshair2D();
Crosshair2D() = delete;
#ifdef MAGNUM_BUILD_DEPRECATED
/**
@brief 2D crosshair
@deprecated Use @ref crosshair2D() instead.
*/
struct MAGNUM_PRIMITIVES_EXPORT Crosshair2D {
/** @brief @copybrief crosshair2D()
* @deprecated Use @ref crosshair2D() instead.
*/
CORRADE_DEPRECATED("use crosshair2D() instead") static Trade::MeshData2D wireframe();
};
#endif
/**
@brief 3D crosshair primitive
@brief 3D crosshair
2x2x2 wireframe crosshair (three crossed lines), non-indexed
@ref MeshPrimitive::Lines.
2x2x2 crosshair (three crossed lines), non-indexed @ref MeshPrimitive::Lines.
@see @ref crosshair2D(), @ref axis2D(), @ref line3D()
*/
class MAGNUM_PRIMITIVES_EXPORT Crosshair3D {
public:
/** @brief Wireframe crosshair */
static Trade::MeshData3D wireframe();
MAGNUM_PRIMITIVES_EXPORT Trade::MeshData3D crosshair3D();
Crosshair3D() = delete;
#ifdef MAGNUM_BUILD_DEPRECATED
/**
@brief 3D crosshair
@deprecated Use @ref crosshair3D() instead.
*/
struct MAGNUM_PRIMITIVES_EXPORT Crosshair3D {
/** @brief @copybrief crosshair3D()
* @deprecated Use @ref crosshair3D() instead.
*/
CORRADE_DEPRECATED("use crosshair3D() instead") static Trade::MeshData3D wireframe();
};
#endif
}}

20
src/Magnum/Primitives/Cube.cpp

@ -31,7 +31,7 @@
namespace Magnum { namespace Primitives {
Trade::MeshData3D Cube::solid() {
Trade::MeshData3D cubeSolid() {
return Trade::MeshData3D{MeshPrimitive::Triangles, {
0, 1, 2, 0, 2, 3, /* +Z */
4, 5, 6, 4, 6, 7, /* +X */
@ -102,7 +102,7 @@ Trade::MeshData3D Cube::solid() {
}}, {}, {}, nullptr};
}
Trade::MeshData3D Cube::solidStrip() {
Trade::MeshData3D cubeSolidStrip() {
/* Sources:
https://twitter.com/Donzanoid/status/436843034966507520
http://www.asmcommunity.net/forums/topic/?id=6284#post-45209
@ -144,7 +144,7 @@ Trade::MeshData3D Cube::solidStrip() {
}}, {}, {}, {}, nullptr};
}
Trade::MeshData3D Cube::wireframe() {
Trade::MeshData3D cubeWireframe() {
return Trade::MeshData3D{MeshPrimitive::Lines, {
0, 1, 1, 2, 2, 3, 3, 0, /* +Z */
4, 5, 5, 6, 6, 7, 7, 4, /* -Z */
@ -163,4 +163,18 @@ Trade::MeshData3D Cube::wireframe() {
}}, {}, {}, {}, nullptr};
}
#ifdef MAGNUM_BUILD_DEPRECATED
Trade::MeshData3D Cube::solid() {
return cubeSolid();
}
Trade::MeshData3D Cube::solidStrip() {
return cubeSolidStrip();
}
Trade::MeshData3D Cube::wireframe() {
return cubeWireframe();
}
#endif
}}

77
src/Magnum/Primitives/Cube.h

@ -26,45 +26,66 @@
*/
/** @file
* @brief Class @ref Magnum::Primitives::Cube
* @brief Function @ref Magnum::Primitives::cubeSolid(), @ref Magnum::Primitives::cubeSolidStrip(), @ref Magnum::Primitives::cubeWireframe()
*/
#include "Magnum/Primitives/visibility.h"
#include "Magnum/Trade/Trade.h"
#ifdef MAGNUM_BUILD_DEPRECATED
#include <Corrade/Utility/Macros.h>
#endif
namespace Magnum { namespace Primitives {
/**
@brief 3D cube primitive
@brief Solid 3D cube
Indexed @ref MeshPrimitive::Triangles with flat normals.
@see @ref cubeSolidStrip(), @ref cubeWireframe()
*/
MAGNUM_PRIMITIVES_EXPORT Trade::MeshData3D cubeSolid();
/**
@brief Solid 3D cube as a single strip
Non-indexed @ref MeshPrimitive::TriangleStrip. Just positions, no
normals or anything else.
@see @ref cubeSolid(), @ref cubeWireframe()
*/
MAGNUM_PRIMITIVES_EXPORT Trade::MeshData3D cubeSolidStrip();
/**
@brief Wireframe 3D cube
Indexed @ref MeshPrimitive::Lines.
@see @ref cubeSolid(), @ref cubeSolidStrip()
*/
MAGNUM_PRIMITIVES_EXPORT Trade::MeshData3D cubeWireframe();
2x2x2 cube.
#ifdef MAGNUM_BUILD_DEPRECATED
/**
@brief 3D cube
@deprecated Use @ref cubeSolid(), @ref cubeSolidStrip() or @ref cubeWireframe()
instead.
*/
class MAGNUM_PRIMITIVES_EXPORT Cube {
public:
/**
* @brief Solid cube
*
* Indexed @ref MeshPrimitive::Triangles with flat normals.
*/
static Trade::MeshData3D solid();
/**
* @brief Solid cube as a single strip
*
* Non-indexed @ref MeshPrimitive::TriangleStrip. Just positions, no
* normals or anything else.
*/
static Trade::MeshData3D solidStrip();
/**
* @brief Wireframe cube
*
* Indexed @ref MeshPrimitive::Lines.
*/
static Trade::MeshData3D wireframe();
Cube() = delete;
struct MAGNUM_PRIMITIVES_EXPORT Cube {
/** @brief @copybrief cubeSolid()
* @deprecated Use @ref cubeSolid() instead.
*/
CORRADE_DEPRECATED("use cubeSolid() instead") static Trade::MeshData3D solid();
/** @brief @copybrief cubeSolidStrip()
* @deprecated Use @ref cubeSolidStrip() instead.
*/
CORRADE_DEPRECATED("use cubeSolidStrip() instead") static Trade::MeshData3D solidStrip();
/** @brief @copybrief cubeWireframe()
* @deprecated Use @ref cubeWireframe() instead.
*/
CORRADE_DEPRECATED("use cubeWireframe() instead") static Trade::MeshData3D wireframe();
};
#endif
}}

36
src/Magnum/Primitives/Cylinder.cpp

@ -33,40 +33,42 @@
namespace Magnum { namespace Primitives {
Trade::MeshData3D Cylinder::solid(const UnsignedInt rings, const UnsignedInt segments, const Float halfLength, const Flags flags) {
CORRADE_ASSERT(rings >= 1 && segments >= 3, "Primitives::Cylinder::solid(): cylinder must have at least one ring and three segments",
Trade::MeshData3D cylinderSolid(const UnsignedInt rings, const UnsignedInt segments, const Float halfLength, const CylinderFlags flags) {
CORRADE_ASSERT(rings >= 1 && segments >= 3,
"Primitives::cylinderSolid(): at least one ring and three segments expected",
(Trade::MeshData3D{MeshPrimitive::Triangles, {}, {}, {}, {}, {}, nullptr}));
Implementation::Spheroid cylinder(segments, flags & Flag::GenerateTextureCoords ? Implementation::Spheroid::TextureCoords::Generate : Implementation::Spheroid::TextureCoords::DontGenerate);
Implementation::Spheroid cylinder(segments, flags & CylinderFlag::GenerateTextureCoords ? Implementation::Spheroid::TextureCoords::Generate : Implementation::Spheroid::TextureCoords::DontGenerate);
const Float length = 2.0f*halfLength;
const Float textureCoordsV = flags & Flag::CapEnds ? 1.0f/(length+2.0f) : 0.0f;
const Float textureCoordsV = flags & CylinderFlag::CapEnds ? 1.0f/(length+2.0f) : 0.0f;
/* Bottom cap */
if(flags & Flag::CapEnds) {
if(flags & CylinderFlag::CapEnds) {
cylinder.capVertex(-halfLength, -1.0f, 0.0f);
cylinder.capVertexRing(-halfLength, textureCoordsV, Vector3::yAxis(-1.0f));
}
/* Vertex rings */
cylinder.cylinderVertexRings(rings+1, -halfLength, length/rings, textureCoordsV, length/(rings*(flags & Flag::CapEnds ? length + 2.0f : length)));
cylinder.cylinderVertexRings(rings+1, -halfLength, length/rings, textureCoordsV, length/(rings*(flags & CylinderFlag::CapEnds ? length + 2.0f : length)));
/* Top cap */
if(flags & Flag::CapEnds) {
if(flags & CylinderFlag::CapEnds) {
cylinder.capVertexRing(halfLength, 1.0f - textureCoordsV, Vector3::yAxis(1.0f));
cylinder.capVertex(halfLength, 1.0f, 1.0f);
}
/* Faces */
if(flags & Flag::CapEnds) cylinder.bottomFaceRing();
cylinder.faceRings(rings, flags & Flag::CapEnds ? (1 + segments) : 0);
if(flags & Flag::CapEnds) cylinder.topFaceRing();
if(flags & CylinderFlag::CapEnds) cylinder.bottomFaceRing();
cylinder.faceRings(rings, flags & CylinderFlag::CapEnds ? (1 + segments) : 0);
if(flags & CylinderFlag::CapEnds) cylinder.topFaceRing();
return cylinder.finalize();
}
Trade::MeshData3D Cylinder::wireframe(const UnsignedInt rings, const UnsignedInt segments, const Float halfLength) {
CORRADE_ASSERT(rings >= 1 && segments >= 4 && segments%4 == 0, "Primitives::Cylinder::wireframe(): improper parameters",
Trade::MeshData3D cylinderWireframe(const UnsignedInt rings, const UnsignedInt segments, const Float halfLength) {
CORRADE_ASSERT(rings >= 1 && segments >= 4 && segments%4 == 0,
"Primitives::cylinderWireframe(): at least one ring and multiples of 4 segments expected",
(Trade::MeshData3D{MeshPrimitive::Lines, {}, {}, {}, {}, {}, nullptr}));
Implementation::WireframeSpheroid cylinder(segments/4);
@ -83,4 +85,14 @@ Trade::MeshData3D Cylinder::wireframe(const UnsignedInt rings, const UnsignedInt
return cylinder.finalize();
}
#ifdef MAGNUM_BUILD_DEPRECATED
Trade::MeshData3D Cylinder::solid(const UnsignedInt rings, const UnsignedInt segments, const Float halfLength, const CylinderFlags flags) {
return cylinderSolid(rings, segments, halfLength, flags);
}
Trade::MeshData3D Cylinder::wireframe(const UnsignedInt rings, const UnsignedInt segments, const Float halfLength) {
return cylinderWireframe(rings, segments, halfLength);
}
#endif
}}

136
src/Magnum/Primitives/Cylinder.h

@ -26,7 +26,7 @@
*/
/** @file
* @brief Class @ref Magnum::Primitives::Cylinder
* @brief Function @ref Magnum::Primitives::cylinderSolid(), @ref Magnum::Primitives::cylinderWireframe()
*/
#include <Corrade/Containers/EnumSet.h>
@ -38,65 +38,89 @@
namespace Magnum { namespace Primitives {
/**
@brief 3D cylinder primitive
@brief Cylinder flag
Cylinder along Y axis of radius `1`.
@see @ref CylinderFlags, @ref cylinderSolid()
*/
class MAGNUM_PRIMITIVES_EXPORT Cylinder {
public:
/**
* @brief Flag
*
* @see @ref Flags, @ref solid(), @ref wireframe()
*/
enum class Flag {
GenerateTextureCoords = 1, /**< Generate texture coordinates */
CapEnds /**< Cap ends */
};
/**
* @brief Flags
*
* @see @ref solid(), @ref wireframe()
*/
typedef Containers::EnumSet<Flag> Flags;
/**
* @brief Solid cylinder
* @param rings Number of (face) rings. Must be larger or
* equal to 1.
* @param segments Number of (face) segments. Must be larger or
* equal to 3.
* @param halfLength Half the cylinder length
* @param flags Flags
*
* Indexed @ref MeshPrimitive::Triangles with normals, optional 2D
* texture coordinates and optional capped ends. If texture coordinates
* are generated, vertices of one segment are duplicated for texture
* wrapping.
*
* The cylinder is by default created with radius set to @cpp 1.0f @ce.
* In order to get radius @f$ r @f$, length @f$ l @f$ and preserve
* correct normals, set @p halfLength to @f$ 0.5 \frac{l}{r} @f$ and
* then scale all @ref Trade::MeshData3D::positions() by @f$ r @f$, for
* example using @ref MeshTools::transformPointsInPlace().
*/
static Trade::MeshData3D solid(UnsignedInt rings, UnsignedInt segments, Float halfLength, Flags flags = Flags());
/**
* @brief Wireframe cylinder
* @param rings Number of (line) rings. Must be larger or equal
* to 1.
* @param segments Number of (line) segments. Must be larger or
* equal to 4 and multiple of 4.
* @param halfLength Half the cylinder length
*
* Indexed @ref MeshPrimitive::Lines.
*/
static Trade::MeshData3D wireframe(UnsignedInt rings, UnsignedInt segments, Float halfLength);
enum class CylinderFlag {
GenerateTextureCoords = 1 << 0, /**< Generate texture coordinates */
CapEnds = 1 << 1 /**< Cap ends */
};
CORRADE_ENUMSET_OPERATORS(Cylinder::Flags)
/**
@brief Cylinder flags
@see @ref cylinderSolid()
*/
typedef Containers::EnumSet<CylinderFlag> CylinderFlags;
CORRADE_ENUMSET_OPERATORS(CylinderFlags)
/**
@brief Solid 3D cylinder
@param rings Number of (face) rings. Must be larger or equal to
@cpp 1 @ce.
@param segments Number of (face) segments. Must be larger or equal to
@cpp 3 @ce.
@param halfLength Half the cylinder length
@param flags Flags
Cylinder along Y axis of radius @cpp 1.0f @ce. Indexed
@ref MeshPrimitive::Triangles with normals, optional 2D texture coordinates and
optional capped ends. If texture coordinates are generated, vertices of one
segment are duplicated for texture wrapping.
The cylinder is by default created with radius set to @f$ 1.0 @f$. In order to
get radius @f$ r @f$, length @f$ l @f$ and preserve correct normals, set
@p halfLength to @f$ 0.5 \frac{l}{r} @f$ and then scale all
@ref Trade::MeshData3D::positions() by @f$ r @f$, for example using
@ref MeshTools::transformPointsInPlace().
@see @ref cylinderWireframe()
*/
MAGNUM_PRIMITIVES_EXPORT Trade::MeshData3D cylinderSolid(UnsignedInt rings, UnsignedInt segments, Float halfLength, CylinderFlags flags = {});
/**
@brief Wireframe 3D cylinder
@param rings Number of (line) rings. Must be larger or equal to
@cpp 1 @ce.
@param segments Number of (line) segments. Must be larger or equal to
@cpp 4 @ce and multiple of @cpp 4 @ce.
@param halfLength Half the cylinder length
Cylinder along Y axis of radius @cpp 1.0f @ce. Indexed
@ref MeshPrimitive::Lines.
@see @ref cylinderSolid()
*/
MAGNUM_PRIMITIVES_EXPORT Trade::MeshData3D cylinderWireframe(UnsignedInt rings, UnsignedInt segments, Float halfLength);
#ifdef MAGNUM_BUILD_DEPRECATED
/**
@brief 3D cylinder
@deprecated Use @ref cylinderSolid() or @ref cylinderWireframe() instead.
*/
struct MAGNUM_PRIMITIVES_EXPORT Cylinder {
/** @brief @copybrief CylinderFlag
* @deprecated Use @ref CylinderFlag instead.
*/
typedef CORRADE_DEPRECATED("use CylinderFlag instead") CylinderFlag Flag;
/** @brief @copybrief CylinderFlags
* @deprecated Use @ref CylinderFlags instead.
*/
typedef CORRADE_DEPRECATED("use CylinderFlags instead") CylinderFlags Flags;
/** @brief @copybrief cylinderSolid()
* @deprecated Use @ref cylinderSolid() instead.
*/
CORRADE_DEPRECATED("use cylinderSolid() instead") static Trade::MeshData3D solid(UnsignedInt rings, UnsignedInt segments, Float halfLength, CylinderFlags flags = {});
/** @brief @copybrief cylinderWireframe()
* @deprecated Use @ref cylinderWireframe() instead.
*/
CORRADE_DEPRECATED("use cylinderWireframe() instead") static Trade::MeshData3D wireframe(UnsignedInt rings, UnsignedInt segments, Float halfLength);
};
#endif
}}

8
src/Magnum/Primitives/Icosphere.cpp

@ -34,7 +34,7 @@
namespace Magnum { namespace Primitives {
Trade::MeshData3D Icosphere::solid(const UnsignedInt subdivisions) {
Trade::MeshData3D icosphereSolid(const UnsignedInt subdivisions) {
std::vector<UnsignedInt> indices{
1, 2, 6,
1, 7, 2,
@ -84,4 +84,10 @@ Trade::MeshData3D Icosphere::solid(const UnsignedInt subdivisions) {
return Trade::MeshData3D{MeshPrimitive::Triangles, std::move(indices), {std::move(positions)}, {std::move(normals)}, {}, {}, nullptr};
}
#ifdef MAGNUM_BUILD_DEPRECATED
Trade::MeshData3D Icosphere::solid(const UnsignedInt subdivisions) {
return icosphereSolid(subdivisions);
}
#endif
}}

35
src/Magnum/Primitives/Icosphere.h

@ -26,29 +26,40 @@
*/
/** @file
* @brief Class @ref Magnum::Primitives::Icosphere
* @brief Function @ref Magnum::Primitives::icosphereSolid()
*/
#include "Magnum/Primitives/visibility.h"
#include "Magnum/Trade/Trade.h"
#ifdef MAGNUM_BUILD_DEPRECATED
#include <Corrade/Utility/Macros.h>
#endif
namespace Magnum { namespace Primitives {
/**
@brief 3D icosphere primitive
@brief Solid 3D icosphere
@param subdivisions Number of subdivisions
Sphere with radius @cpp 1.0f @ce. Indexed @ref MeshPrimitive::Triangles with
normals.
@see @ref uvSphereSolid(), @ref uvSphereWireframe()
*/
MAGNUM_PRIMITIVES_EXPORT Trade::MeshData3D icosphereSolid(UnsignedInt subdivisions);
Sphere with radius `1`.
#ifdef MAGNUM_BUILD_DEPRECATED
/**
@brief 3D icosphere
@deprecated Use @ref icosphereSolid() instead.
*/
class MAGNUM_PRIMITIVES_EXPORT Icosphere {
public:
/**
* @brief Solid icosphere
* @param subdivisions Number of subdivisions
*
* Indexed @ref MeshPrimitive::Triangles with normals.
*/
static Trade::MeshData3D solid(UnsignedInt subdivisions);
struct MAGNUM_PRIMITIVES_EXPORT Icosphere {
/** @brief @copybrief icosphereSolid()
* @deprecated Use @ref icosphereSolid() instead.
*/
CORRADE_DEPRECATED("use icosphereSolid() instead") static Trade::MeshData3D solid(UnsignedInt subdivisions);
};
#endif
}}

14
src/Magnum/Primitives/Line.cpp

@ -32,16 +32,26 @@
namespace Magnum { namespace Primitives {
Trade::MeshData2D Line2D::wireframe() {
Trade::MeshData2D line2D() {
return Trade::MeshData2D{MeshPrimitive::Lines, {}, {{
{0.0f, 0.0f}, {1.0f, 0.0f}
}}, {}, {}, nullptr};
}
Trade::MeshData3D Line3D::wireframe() {
Trade::MeshData3D line3D() {
return Trade::MeshData3D{MeshPrimitive::Lines, {}, {{
{0.0f, 0.0f, 0.0f}, {1.0f, 0.0f, 0.0f},
}}, {}, {}, {}, nullptr};
}
#ifdef MAGNUM_BUILD_DEPRECATED
Trade::MeshData2D Line2D::wireframe() {
return line2D();
}
Trade::MeshData3D Line3D::wireframe() {
return line3D();
}
#endif
}}

48
src/Magnum/Primitives/Line.h

@ -26,42 +26,60 @@
*/
/** @file
* @brief Class @ref Magnum::Primitives::Line2D, @ref Magnum::Primitives::Line3D
* @brief Function @ref Magnum::Primitives::line2D(), @ref Magnum::Primitives::line3D()
*/
#include "Magnum/Primitives/visibility.h"
#include "Magnum/Trade/Trade.h"
#ifdef MAGNUM_BUILD_DEPRECATED
#include <Corrade/Utility/Macros.h>
#endif
namespace Magnum { namespace Primitives {
/**
@brief 2D line primitive
@brief 2D line
Unit-size line in direction of positive X axis. Non-indexed
@ref MeshPrimitive::Lines.
@see @ref line3D(), @ref axis2D(), @ref crosshair2D()
*/
class MAGNUM_PRIMITIVES_EXPORT Line2D {
public:
/** @brief Wireframe line */
static Trade::MeshData2D wireframe();
Line2D() = delete;
};
MAGNUM_PRIMITIVES_EXPORT Trade::MeshData2D line2D();
/**
@brief 3D line primitive
@brief 3D line
Unit-size line in direction of positive X axis. Non-indexed
@ref MeshPrimitive::Lines.
@see @ref line2D(), @ref axis3D(), @ref crosshair3D()
*/
class MAGNUM_PRIMITIVES_EXPORT Line3D {
public:
/** @brief Wireframe line */
static Trade::MeshData3D wireframe();
MAGNUM_PRIMITIVES_EXPORT Trade::MeshData3D line3D();
Line3D() = delete;
#ifdef MAGNUM_BUILD_DEPRECATED
/**
@brief 2D line
@deprecated Use @ref line2D() instead.
*/
struct MAGNUM_PRIMITIVES_EXPORT Line2D {
/** @brief @copybrief line2D()
* @deprecated Use @ref line2D() instead.
*/
CORRADE_DEPRECATED("use line2D() instead") static Trade::MeshData2D wireframe();
};
/**
@brief 3D line
@deprecated Use @ref line3D() instead.
*/
struct MAGNUM_PRIMITIVES_EXPORT Line3D {
/** @brief @copybrief line3D()
* @deprecated Use @ref line3D() instead.
*/
CORRADE_DEPRECATED("use line3D() instead") static Trade::MeshData3D wireframe();
};
#endif
}}
#endif

16
src/Magnum/Primitives/Plane.cpp

@ -31,9 +31,9 @@
namespace Magnum { namespace Primitives {
Trade::MeshData3D Plane::solid(const TextureCoords textureCoords) {
Trade::MeshData3D planeSolid(const PlaneTextureCoords textureCoords) {
std::vector<std::vector<Vector2>> coords;
if(textureCoords == TextureCoords::Generate) coords.push_back({
if(textureCoords == PlaneTextureCoords::Generate) coords.push_back({
{1.0f, 0.0f},
{1.0f, 1.0f},
{0.0f, 0.0f},
@ -53,7 +53,7 @@ Trade::MeshData3D Plane::solid(const TextureCoords textureCoords) {
}}, std::move(coords), {}, nullptr};
}
Trade::MeshData3D Plane::wireframe() {
Trade::MeshData3D planeWireframe() {
return Trade::MeshData3D{MeshPrimitive::LineLoop, {}, {{
{-1.0f, -1.0f, 0.0f},
{1.0f, -1.0f, 0.0f},
@ -62,4 +62,14 @@ Trade::MeshData3D Plane::wireframe() {
}}, {}, {}, {}, nullptr};
}
#ifdef MAGNUM_BUILD_DEPRECATED
Trade::MeshData3D Plane::solid(const PlaneTextureCoords textureCoords) {
return planeSolid(textureCoords);
}
Trade::MeshData3D Plane::wireframe() {
return planeWireframe();
}
#endif
}}

82
src/Magnum/Primitives/Plane.h

@ -26,47 +26,69 @@
*/
/** @file
* @brief Class @ref Magnum::Primitives::Plane
* @brief Function @ref Magnum::Primitives::planeSolid(), @ref Magnum::Primitives::planeWireframe()
*/
#include "Magnum/Trade/Trade.h"
#include "Magnum/Primitives/visibility.h"
#ifdef MAGNUM_BUILD_DEPRECATED
#include <Corrade/Utility/Macros.h>
#endif
namespace Magnum { namespace Primitives {
/**
@brief 3D plane primitive
@brief Whether to generate plane texture coordinates
@see @ref planeSolid()
*/
enum class PlaneTextureCoords: UnsignedByte {
DontGenerate, /**< Don't generate texture coordinates */
/** Generate texture coordinates with origin in bottom left corner. */
Generate
};
/**
@brief Solid 3D plane
2x2 plane. Non-indexed @ref MeshPrimitive::TriangleStrip on the XY plane with
normals in positive Z direction.
@see @ref planeWireframe(), @ref squareSolid()
*/
MAGNUM_PRIMITIVES_EXPORT Trade::MeshData3D planeSolid(PlaneTextureCoords textureCoords = PlaneTextureCoords::DontGenerate);
/**
@brief Wireframe 3D plane
2x2 plane.
@see @ref Square
2x2 plane. Non-indexed @ref MeshPrimitive::LineLoop on the XY plane.
@see @ref planeSolid(), @ref squareWireframe()
*/
class MAGNUM_PRIMITIVES_EXPORT Plane {
public:
/** @brief Whether to generate texture coordinates */
enum class TextureCoords: UnsignedByte {
DontGenerate, /**< Don't generate texture coordinates */
/** Generate texture coordinates with origin in bottom left corner. */
Generate
};
/**
* @brief Solid plane
*
* Non-indexed @ref MeshPrimitive::TriangleStrip with normals in
* positive Z direction.
*/
static Trade::MeshData3D solid(TextureCoords textureCoords = TextureCoords::DontGenerate);
/**
* @brief Wireframe plane
*
* Non-indexed @ref MeshPrimitive::LineLoop.
*/
static Trade::MeshData3D wireframe();
Plane() = delete;
MAGNUM_PRIMITIVES_EXPORT Trade::MeshData3D planeWireframe();
#ifdef MAGNUM_BUILD_DEPRECATED
/**
@brief 3D plane
@deprecated Use @ref planeSolid() or @ref planeWireframe() instead.
*/
struct MAGNUM_PRIMITIVES_EXPORT Plane {
/** @brief @copybrief PlaneTextureCoords
* @deprecated Use @ref PlaneTextureCoords instead.
*/
typedef CORRADE_DEPRECATED("use PlaneTextureCoords instead") PlaneTextureCoords TextureCoords;
/** @brief @copybrief planeSolid()
* @deprecated Use @ref planeSolid() instead.
*/
CORRADE_DEPRECATED("use planeSolid() instead") static Trade::MeshData3D solid(PlaneTextureCoords textureCoords = PlaneTextureCoords::DontGenerate);
/** @brief @copybrief planeWireframe()
* @deprecated Use @ref planeWireframe() instead.
*/
CORRADE_DEPRECATED("use planeWireframe() instead") static Trade::MeshData3D wireframe();
};
#endif
}}

16
src/Magnum/Primitives/Square.cpp

@ -31,9 +31,9 @@
namespace Magnum { namespace Primitives {
Trade::MeshData2D Square::solid(const TextureCoords textureCoords) {
Trade::MeshData2D squareSolid(const SquareTextureCoords textureCoords) {
std::vector<std::vector<Vector2>> coords;
if(textureCoords == TextureCoords::Generate) coords.push_back({
if(textureCoords == SquareTextureCoords::Generate) coords.push_back({
{1.0f, 0.0f},
{1.0f, 1.0f},
{0.0f, 0.0f},
@ -48,7 +48,7 @@ Trade::MeshData2D Square::solid(const TextureCoords textureCoords) {
}}, std::move(coords), {}, nullptr};
}
Trade::MeshData2D Square::wireframe() {
Trade::MeshData2D squareWireframe() {
return Trade::MeshData2D{MeshPrimitive::LineLoop, {}, {{
{-1.0f, -1.0f},
{1.0f, -1.0f},
@ -57,4 +57,14 @@ Trade::MeshData2D Square::wireframe() {
}}, {}, {}, nullptr};
}
#ifdef MAGNUM_BUILD_DEPRECATED
Trade::MeshData2D Square::solid(const SquareTextureCoords textureCoords) {
return squareSolid(textureCoords);
}
Trade::MeshData2D Square::wireframe() {
return squareWireframe();
}
#endif
}}

80
src/Magnum/Primitives/Square.h

@ -26,46 +26,68 @@
*/
/** @file
* @brief Class @ref Magnum::Primitives::Square
* @brief Function @ref Magnum::Primitives::squareSolid(), @ref Magnum::Primitives::squareWireframe()
*/
#include "Magnum/Primitives/visibility.h"
#include "Magnum/Trade/Trade.h"
#ifdef MAGNUM_BUILD_DEPRECATED
#include <Corrade/Utility/Macros.h>
#endif
namespace Magnum { namespace Primitives {
/**
@brief 2D square primitive
@brief Whether to generate square texture coordinates
@see @ref squareSolid()
*/
enum class SquareTextureCoords: UnsignedByte {
DontGenerate, /**< Don't generate texture coordinates */
/** Generate texture coordinates with origin in bottom left corner. */
Generate
};
/**
@brief Solid 2D square
2x2 square. Non-indexed @ref MeshPrimitive::TriangleStrip.
@see @ref squareWireframe(), @ref planeSolid()
*/
MAGNUM_PRIMITIVES_EXPORT Trade::MeshData2D squareSolid(SquareTextureCoords textureCoords = SquareTextureCoords::DontGenerate);
/**
@brief Wireframe 2D square
2x2 square.
@see @ref Plane
2x2 square. Non-indexed @ref MeshPrimitive::LineLoop.
@see @ref squareSolid(), @ref planeWireframe()
*/
class MAGNUM_PRIMITIVES_EXPORT Square {
public:
/** @brief Whether to generate texture coordinates */
enum class TextureCoords: UnsignedByte {
DontGenerate, /**< Don't generate texture coordinates */
/** Generate texture coordinates with origin in bottom left corner. */
Generate
};
/**
* @brief Solid square
*
* Non-indexed @ref MeshPrimitive::TriangleStrip.
*/
static Trade::MeshData2D solid(TextureCoords textureCoords = TextureCoords::DontGenerate);
/**
* @brief Wireframe square
*
* Non-indexed @ref MeshPrimitive::LineLoop.
*/
static Trade::MeshData2D wireframe();
Square() = delete;
MAGNUM_PRIMITIVES_EXPORT Trade::MeshData2D squareWireframe();
#ifdef MAGNUM_BUILD_DEPRECATED
/**
@brief 2D square
@deprecated Use @ref squareSolid() or @ref squareWireframe() instead.
*/
struct MAGNUM_PRIMITIVES_EXPORT Square {
/** @brief @copybrief SquareTextureCoords
* @deprecated Use @ref SquareTextureCoords instead.
*/
typedef CORRADE_DEPRECATED("use SquareTextureCoords instead") SquareTextureCoords TextureCoords;
/** @brief @copybrief squareSolid()
* @deprecated Use @ref squareWireframe() instead.
*/
CORRADE_DEPRECATED("use squareSolid() instead") static Trade::MeshData2D solid(SquareTextureCoords textureCoords = SquareTextureCoords::DontGenerate);
/** @brief @copybrief squareWireframe()
* @deprecated Use @ref squareWireframe() instead.
*/
CORRADE_DEPRECATED("use squareWireframe() instead") static Trade::MeshData2D wireframe();
};
#endif
}}

8
src/Magnum/Primitives/Test/CapsuleTest.cpp

@ -51,7 +51,7 @@ CapsuleTest::CapsuleTest() {
}
void CapsuleTest::wireframe2D() {
Trade::MeshData2D capsule = Capsule2D::wireframe(2, 4, 0.5f);
Trade::MeshData2D capsule = capsule2DWireframe(2, 4, 0.5f);
CORRADE_COMPARE_AS(capsule.positions(0), (std::vector<Vector2>{
{0.0f, -1.5f},
@ -95,7 +95,7 @@ void CapsuleTest::wireframe2D() {
}
void CapsuleTest::solid3DWithoutTextureCoords() {
Trade::MeshData3D capsule = Capsule3D::solid(2, 4, 3, 0.5f);
Trade::MeshData3D capsule = capsule3DSolid(2, 4, 3, 0.5f);
CORRADE_COMPARE_AS(capsule.positions(0), (std::vector<Vector3>{
{0.0f, -1.5f, 0.0f},
@ -178,7 +178,7 @@ void CapsuleTest::solid3DWithoutTextureCoords() {
}
void CapsuleTest::solid3DWithTextureCoords() {
Trade::MeshData3D capsule = Capsule3D::solid(2, 2, 3, 0.5f, Capsule3D::TextureCoords::Generate);
Trade::MeshData3D capsule = capsule3DSolid(2, 2, 3, 0.5f, CapsuleTextureCoords::Generate);
CORRADE_COMPARE_AS(capsule.positions(0), (std::vector<Vector3>{
{0.0f, -1.5f, 0.0f},
@ -253,7 +253,7 @@ void CapsuleTest::solid3DWithTextureCoords() {
}
void CapsuleTest::wireframe3D() {
Trade::MeshData3D capsule = Capsule3D::wireframe(2, 2, 8, 0.5f);
Trade::MeshData3D capsule = capsule3DWireframe(2, 2, 8, 0.5f);
CORRADE_COMPARE_AS(capsule.positions(0), (std::vector<Vector3>{
{0.0f, -1.5f, 0.0f},

4
src/Magnum/Primitives/Test/CircleTest.cpp

@ -45,7 +45,7 @@ CircleTest::CircleTest() {
}
void CircleTest::solid() {
Trade::MeshData2D circle = Primitives::Circle::solid(8);
Trade::MeshData2D circle = Primitives::circle2DSolid(8);
CORRADE_VERIFY(!circle.isIndexed());
CORRADE_COMPARE(circle.primitive(), MeshPrimitive::TriangleFan);
@ -60,7 +60,7 @@ void CircleTest::solid() {
}
void CircleTest::wireframe() {
Trade::MeshData2D circle = Primitives::Circle::wireframe(8);
Trade::MeshData2D circle = Primitives::circle2DWireframe(8);
CORRADE_VERIFY(!circle.isIndexed());
CORRADE_COMPARE(circle.primitive(), MeshPrimitive::LineLoop);

4
src/Magnum/Primitives/Test/CrosshairTest.cpp

@ -46,7 +46,7 @@ CrosshairTest::CrosshairTest() {
}
void CrosshairTest::twoDimensions() {
Trade::MeshData2D crosshair = Primitives::Crosshair2D::wireframe();
Trade::MeshData2D crosshair = Primitives::crosshair2D();
CORRADE_VERIFY(!crosshair.isIndexed());
CORRADE_COMPARE(crosshair.primitive(), MeshPrimitive::Lines);
@ -54,7 +54,7 @@ void CrosshairTest::twoDimensions() {
}
void CrosshairTest::threeDimensions() {
Trade::MeshData3D crosshair = Primitives::Crosshair3D::wireframe();
Trade::MeshData3D crosshair = Primitives::crosshair3D();
CORRADE_VERIFY(!crosshair.isIndexed());
CORRADE_COMPARE(crosshair.primitive(), MeshPrimitive::Lines);

6
src/Magnum/Primitives/Test/CubeTest.cpp

@ -47,7 +47,7 @@ CubeTest::CubeTest() {
}
void CubeTest::solid() {
Trade::MeshData3D cube = Primitives::Cube::solid();
Trade::MeshData3D cube = Primitives::cubeSolid();
CORRADE_COMPARE(cube.primitive(), MeshPrimitive::Triangles);
CORRADE_COMPARE(cube.indices().size(), 36);
@ -56,7 +56,7 @@ void CubeTest::solid() {
}
void CubeTest::solidStrip() {
Trade::MeshData3D cube = Primitives::Cube::solidStrip();
Trade::MeshData3D cube = Primitives::cubeSolidStrip();
CORRADE_VERIFY(!cube.isIndexed());
CORRADE_COMPARE(cube.primitive(), MeshPrimitive::TriangleStrip);
@ -65,7 +65,7 @@ void CubeTest::solidStrip() {
}
void CubeTest::wireframe() {
Trade::MeshData3D cube = Primitives::Cube::wireframe();
Trade::MeshData3D cube = Primitives::cubeWireframe();
CORRADE_COMPARE(cube.primitive(), MeshPrimitive::Lines);
CORRADE_COMPARE(cube.indices().size(), 24);

6
src/Magnum/Primitives/Test/CylinderTest.cpp

@ -47,7 +47,7 @@ CylinderTest::CylinderTest() {
}
void CylinderTest::solidWithoutAnything() {
Trade::MeshData3D cylinder = Cylinder::solid(2, 3, 1.5f);
Trade::MeshData3D cylinder = cylinderSolid(2, 3, 1.5f);
CORRADE_COMPARE_AS(cylinder.positions(0), (std::vector<Vector3>{
{0.0f, -1.5f, 1.0f},
@ -84,7 +84,7 @@ void CylinderTest::solidWithoutAnything() {
}
void CylinderTest::solidWithTextureCoordsAndCaps() {
Trade::MeshData3D cylinder = Cylinder::solid(2, 3, 1.5f, Cylinder::Flag::GenerateTextureCoords|Cylinder::Flag::CapEnds);
Trade::MeshData3D cylinder = cylinderSolid(2, 3, 1.5f, CylinderFlag::GenerateTextureCoords|CylinderFlag::CapEnds);
/* First and last ring are duplicated because they have different normals */
CORRADE_COMPARE_AS(cylinder.positions(0), (std::vector<Vector3>{
@ -191,7 +191,7 @@ void CylinderTest::solidWithTextureCoordsAndCaps() {
}
void CylinderTest::wireframe() {
Trade::MeshData3D cylinder = Cylinder::wireframe(2, 8, 0.5f);
Trade::MeshData3D cylinder = cylinderWireframe(2, 8, 0.5f);
CORRADE_COMPARE_AS(cylinder.positions(0), (std::vector<Vector3>{
{0.0f, -0.5f, 1.0f},

2
src/Magnum/Primitives/Test/IcosphereTest.cpp

@ -42,7 +42,7 @@ IcosphereTest::IcosphereTest() {
}
void IcosphereTest::count() {
Trade::MeshData3D data = Primitives::Icosphere::solid(2);
Trade::MeshData3D data = Primitives::icosphereSolid(2);
CORRADE_COMPARE(data.positionArrayCount(), 1);
CORRADE_COMPARE(data.normalArrayCount(), 1);

4
src/Magnum/Primitives/Test/LineTest.cpp

@ -46,7 +46,7 @@ LineTest::LineTest() {
}
void LineTest::twoDimensions() {
Trade::MeshData2D line = Primitives::Line2D::wireframe();
Trade::MeshData2D line = Primitives::line2D();
CORRADE_VERIFY(!line.isIndexed());
CORRADE_COMPARE(line.primitive(), MeshPrimitive::Lines);
@ -54,7 +54,7 @@ void LineTest::twoDimensions() {
}
void LineTest::threeDimensions() {
Trade::MeshData3D line = Primitives::Line3D::wireframe();
Trade::MeshData3D line = Primitives::line3D();
CORRADE_VERIFY(!line.isIndexed());
CORRADE_COMPARE(line.primitive(), MeshPrimitive::Lines);

4
src/Magnum/Primitives/Test/PlaneTest.cpp

@ -45,7 +45,7 @@ PlaneTest::PlaneTest() {
}
void PlaneTest::solid() {
Trade::MeshData3D plane = Primitives::Plane::solid();
Trade::MeshData3D plane = Primitives::planeSolid();
CORRADE_VERIFY(!plane.isIndexed());
CORRADE_COMPARE(plane.primitive(), MeshPrimitive::TriangleStrip);
@ -54,7 +54,7 @@ void PlaneTest::solid() {
}
void PlaneTest::wireframe() {
Trade::MeshData3D plane = Primitives::Plane::wireframe();
Trade::MeshData3D plane = Primitives::planeWireframe();
CORRADE_VERIFY(!plane.isIndexed());
CORRADE_COMPARE(plane.primitive(), MeshPrimitive::LineLoop);

4
src/Magnum/Primitives/Test/SquareTest.cpp

@ -45,7 +45,7 @@ SquareTest::SquareTest() {
}
void SquareTest::solid() {
Trade::MeshData2D square = Primitives::Square::solid();
Trade::MeshData2D square = Primitives::squareSolid();
CORRADE_VERIFY(!square.isIndexed());
CORRADE_COMPARE(square.primitive(), MeshPrimitive::TriangleStrip);
@ -53,7 +53,7 @@ void SquareTest::solid() {
}
void SquareTest::wireframe() {
Trade::MeshData2D square = Primitives::Square::wireframe();
Trade::MeshData2D square = Primitives::squareWireframe();
CORRADE_VERIFY(!square.isIndexed());
CORRADE_COMPARE(square.primitive(), MeshPrimitive::LineLoop);

6
src/Magnum/Primitives/Test/UVSphereTest.cpp

@ -47,7 +47,7 @@ UVSphereTest::UVSphereTest() {
}
void UVSphereTest::solidWithoutTextureCoords() {
Trade::MeshData3D sphere = UVSphere::solid(3, 3);
Trade::MeshData3D sphere = uvSphereSolid(3, 3);
CORRADE_COMPARE_AS(sphere.positions(0), (std::vector<Vector3>{
{0.0f, -1.0f, 0.0f},
@ -85,7 +85,7 @@ void UVSphereTest::solidWithoutTextureCoords() {
}
void UVSphereTest::solidWithTextureCoords() {
Trade::MeshData3D sphere = UVSphere::solid(3, 3, UVSphere::TextureCoords::Generate);
Trade::MeshData3D sphere = uvSphereSolid(3, 3, UVSphereTextureCoords::Generate);
CORRADE_COMPARE_AS(sphere.positions(0), (std::vector<Vector3>{
{0.0f, -1.0f, 0.0f},
@ -127,7 +127,7 @@ void UVSphereTest::solidWithTextureCoords() {
}
void UVSphereTest::wireframe() {
Trade::MeshData3D sphere = UVSphere::wireframe(6, 8);
Trade::MeshData3D sphere = uvSphereWireframe(6, 8);
CORRADE_COMPARE_AS(sphere.positions(0), (std::vector<Vector3>{
{0.0f, -1.0f, 0.0f},

22
src/Magnum/Primitives/UVSphere.cpp

@ -33,11 +33,12 @@
namespace Magnum { namespace Primitives {
Trade::MeshData3D UVSphere::solid(UnsignedInt rings, UnsignedInt segments, TextureCoords textureCoords) {
CORRADE_ASSERT(rings >= 2 && segments >= 3, "UVSphere must have at least two rings and three segments",
Trade::MeshData3D uvSphereSolid(UnsignedInt rings, UnsignedInt segments, UVSphereTextureCoords textureCoords) {
CORRADE_ASSERT(rings >= 2 && segments >= 3,
"Primitives::uvSphereSolid(): at least two rings and three segments expected",
(Trade::MeshData3D{MeshPrimitive::Triangles, {}, {}, {}, {}, {}, nullptr}));
Implementation::Spheroid sphere(segments, textureCoords == TextureCoords::Generate ?
Implementation::Spheroid sphere(segments, textureCoords == UVSphereTextureCoords::Generate ?
Implementation::Spheroid::TextureCoords::Generate :
Implementation::Spheroid::TextureCoords::DontGenerate);
@ -61,8 +62,9 @@ Trade::MeshData3D UVSphere::solid(UnsignedInt rings, UnsignedInt segments, Textu
return sphere.finalize();
}
Trade::MeshData3D UVSphere::wireframe(const UnsignedInt rings, const UnsignedInt segments) {
CORRADE_ASSERT(rings >= 2 && rings%2 == 0 && segments >= 4 && segments%2 == 0, "Primitives::UVSphere::wireframe(): improper parameters",
Trade::MeshData3D uvSphereWireframe(const UnsignedInt rings, const UnsignedInt segments) {
CORRADE_ASSERT(rings >= 2 && rings%2 == 0 && segments >= 4 && segments%2 == 0,
"Primitives::uvSphereWireframe(): multiples of 2 rings and multiples of 4 segments expected",
(Trade::MeshData3D{MeshPrimitive::Triangles, {}, {}, {}, {}, {}, nullptr}));
Implementation::WireframeSpheroid sphere(segments/4);
@ -75,4 +77,14 @@ Trade::MeshData3D UVSphere::wireframe(const UnsignedInt rings, const UnsignedInt
return sphere.finalize();
}
#ifdef MAGNUM_BUILD_DEPRECATED
Trade::MeshData3D UVSphere::solid(const UnsignedInt rings, const UnsignedInt segments, const UVSphereTextureCoords textureCoords) {
return uvSphereSolid(rings, segments, textureCoords);
}
Trade::MeshData3D UVSphere::wireframe(const UnsignedInt rings, const UnsignedInt segments) {
return uvSphereWireframe(rings, segments);
}
#endif
}}

95
src/Magnum/Primitives/UVSphere.h

@ -26,53 +26,78 @@
*/
/** @file
* @brief Class @ref Magnum::Primitives::UVSphere
* @brief Class @ref Magnum::Primitives::uvSphereSolid(), @ref Magnum::Primitives::uvSphereWireframe()
*/
#include "Magnum/Trade/Trade.h"
#include "Magnum/Primitives/visibility.h"
#ifdef MAGNUM_BUILD_DEPRECATED
#include <Corrade/Utility/Macros.h>
#endif
namespace Magnum { namespace Primitives {
/**
@brief 3D UV sphere primitive
@brief Whether to generate UV sphere texture coordinates
Sphere with radius `1`.
@see @ref uvSphereSolid()
*/
class MAGNUM_PRIMITIVES_EXPORT UVSphere {
public:
/** @brief Whether to generate texture coordinates */
enum class TextureCoords: UnsignedByte {
Generate, /**< Generate texture coordinates */
DontGenerate /**< Don't generate texture coordinates */
};
/**
* @brief Solid UV sphere
* @param rings Number of (face) rings. Must be larger or equal
* to 2.
* @param segments Number of (face) segments. Must be larger or
* equal to 3.
* @param textureCoords Whether to generate texture coordinates.
*
* Indexed @ref MeshPrimitive::Triangles with normals and optional 2D
* texture coordinates. If texture coordinates are generated, vertices
* of one segment are duplicated for texture wrapping.
*/
static Trade::MeshData3D solid(UnsignedInt rings, UnsignedInt segments, TextureCoords textureCoords = TextureCoords::DontGenerate);
/**
* @brief Wireframe UV sphere
* @param rings Number of (line) rings. Must be larger or equal
* to 2 and multiple of 2.
* @param segments Number of (line) segments. Must be larger or
* equal to 4 and multiple of 4.
*
* Indexed @ref MeshPrimitive::Lines.
*/
static Trade::MeshData3D wireframe(UnsignedInt rings, UnsignedInt segments);
enum class UVSphereTextureCoords: UnsignedByte {
DontGenerate, /**< Don't generate texture coordinates */
Generate /**< Generate texture coordinates */
};
/**
@brief Solid 3D UV sphere
@param rings Number of (face) rings. Must be larger or equal to
@cpp 2 @ce.
@param segments Number of (face) segments. Must be larger or
equal to @cpp 3 @ce.
@param textureCoords Whether to generate texture coordinates
Sphere with radius @cpp 1.0f @ce. Indexed @ref MeshPrimitive::Triangles with
normals and optional 2D texture coordinates. If texture coordinates are
generated, vertices of one segment are duplicated for texture wrapping.
@see @ref icosphereSolid()
*/
MAGNUM_PRIMITIVES_EXPORT Trade::MeshData3D uvSphereSolid(UnsignedInt rings, UnsignedInt segments, UVSphereTextureCoords textureCoords = UVSphereTextureCoords::DontGenerate);
/**
@brief Wireframe 3D UV sphere
@param rings Number of (line) rings. Must be larger or equal to
@cpp 2 @ce and multiple of @cpp 2 @ce.
@param segments Number of (line) segments. Must be larger or equal to
@cpp 4 @ce and multiple of @cpp 4 @ce.
Sphere with radius @cpp 1.0f @ce. Indexed @ref MeshPrimitive::Lines.
@see @ref icosphereSolid()
*/
MAGNUM_PRIMITIVES_EXPORT Trade::MeshData3D uvSphereWireframe(UnsignedInt rings, UnsignedInt segments);
#ifdef MAGNUM_BUILD_DEPRECATED
/**
@brief 3D UV sphere
@deprecated Use @ref uvSphereSolid() or @ref uvSphereWireframe() instead.
*/
struct MAGNUM_PRIMITIVES_EXPORT UVSphere {
/** @brief @copybrief UVSphereTextureCoords
* @deprecated Use @ref UVSphereTextureCoords instead.
*/
typedef CORRADE_DEPRECATED("use UVSphereTextureCoords instead") UVSphereTextureCoords TextureCoords;
/** @brief @copybrief uvSphereSolid()
* @deprecated Use @ref uvSphereSolid() instead.
*/
CORRADE_DEPRECATED("use uvSphereSolid() instead") static Trade::MeshData3D solid(UnsignedInt rings, UnsignedInt segments, UVSphereTextureCoords textureCoords = UVSphereTextureCoords::DontGenerate);
/** @brief @copybrief uvSphereWireframe()
* @deprecated Use @ref uvSphereWireframe() instead.
*/
CORRADE_DEPRECATED("use uvSphereWireframe() instead") static Trade::MeshData3D wireframe(UnsignedInt rings, UnsignedInt segments);
};
#endif
}}
#endif

Loading…
Cancel
Save