Browse Source

Primitives: added texture coordinates to Plane and Square primitives.

pull/23/head
Vladimír Vondruš 13 years ago
parent
commit
06f750068a
  1. 12
      src/Primitives/Plane.cpp
  2. 11
      src/Primitives/Plane.h
  3. 12
      src/Primitives/Square.cpp
  4. 11
      src/Primitives/Square.h

12
src/Primitives/Plane.cpp

@ -29,7 +29,15 @@
namespace Magnum { namespace Primitives { namespace Magnum { namespace Primitives {
Trade::MeshData3D Plane::solid() { Trade::MeshData3D Plane::solid(const TextureCoords textureCoords) {
std::vector<std::vector<Vector2>> coords;
if(textureCoords == TextureCoords::Generate) coords.push_back({
{1.0f, 0.0f},
{1.0f, 1.0f},
{0.0f, 0.0f},
{0.0f, 1.0f}
});
return Trade::MeshData3D(Mesh::Primitive::TriangleStrip, {}, {{ return Trade::MeshData3D(Mesh::Primitive::TriangleStrip, {}, {{
{1.0f, -1.0f, 0.0f}, {1.0f, -1.0f, 0.0f},
{1.0f, 1.0f, 0.0f}, {1.0f, 1.0f, 0.0f},
@ -40,7 +48,7 @@ Trade::MeshData3D Plane::solid() {
{0.0f, 0.0f, 1.0f}, {0.0f, 0.0f, 1.0f},
{0.0f, 0.0f, 1.0f}, {0.0f, 0.0f, 1.0f},
{0.0f, 0.0f, 1.0f} {0.0f, 0.0f, 1.0f}
}}, {}); }}, std::move(coords));
} }
Trade::MeshData3D Plane::wireframe() { Trade::MeshData3D Plane::wireframe() {

11
src/Primitives/Plane.h

@ -38,16 +38,25 @@ namespace Magnum { namespace Primitives {
@brief 3D plane primitive @brief 3D plane primitive
2x2 plane. 2x2 plane.
@see @ref Square
*/ */
class MAGNUM_PRIMITIVES_EXPORT Plane { class MAGNUM_PRIMITIVES_EXPORT Plane {
public: 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 * @brief Solid plane
* *
* Non-indexed @ref Mesh::Primitive "TriangleStrip" with normals in * Non-indexed @ref Mesh::Primitive "TriangleStrip" with normals in
* positive Z direction. * positive Z direction.
*/ */
static Trade::MeshData3D solid(); static Trade::MeshData3D solid(TextureCoords textureCoords = TextureCoords::DontGenerate);
/** /**
* @brief Wireframe plane * @brief Wireframe plane

12
src/Primitives/Square.cpp

@ -29,13 +29,21 @@
namespace Magnum { namespace Primitives { namespace Magnum { namespace Primitives {
Trade::MeshData2D Square::solid() { Trade::MeshData2D Square::solid(const TextureCoords textureCoords) {
std::vector<std::vector<Vector2>> coords;
if(textureCoords == TextureCoords::Generate) coords.push_back({
{1.0f, 0.0f},
{1.0f, 1.0f},
{0.0f, 0.0f},
{0.0f, 1.0f}
});
return Trade::MeshData2D(Mesh::Primitive::TriangleStrip, {}, {{ return Trade::MeshData2D(Mesh::Primitive::TriangleStrip, {}, {{
{1.0f, -1.0f}, {1.0f, -1.0f},
{1.0f, 1.0f}, {1.0f, 1.0f},
{-1.0f, -1.0f}, {-1.0f, -1.0f},
{-1.0f, 1.0f} {-1.0f, 1.0f}
}}, {}); }}, std::move(coords));
} }
Trade::MeshData2D Square::wireframe() { Trade::MeshData2D Square::wireframe() {

11
src/Primitives/Square.h

@ -38,15 +38,24 @@ namespace Magnum { namespace Primitives {
@brief 2D square primitive @brief 2D square primitive
2x2 square. 2x2 square.
@see @ref Plane
*/ */
class MAGNUM_PRIMITIVES_EXPORT Square { class MAGNUM_PRIMITIVES_EXPORT Square {
public: 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 * @brief Solid square
* *
* Non-indexed @ref Mesh::Primitive "TriangleStrip". * Non-indexed @ref Mesh::Primitive "TriangleStrip".
*/ */
static Trade::MeshData2D solid(); static Trade::MeshData2D solid(TextureCoords textureCoords = TextureCoords::DontGenerate);
/** /**
* @brief Wireframe square * @brief Wireframe square

Loading…
Cancel
Save