Browse Source

Make cube primitive indexed.

Saves 300 bytes if using uncompressed vertex and normal data.
pull/7/head
Vladimír Vondruš 14 years ago
parent
commit
33a36c9dc6
  1. 36
      src/Primitives/Cube.cpp
  2. 2
      src/Primitives/Cube.h

36
src/Primitives/Cube.cpp

@ -19,91 +19,73 @@
namespace Magnum { namespace Primitives {
Cube::Cube(): MeshData3D("", Mesh::Primitive::Triangles, nullptr, {new std::vector<Point3D>{
Cube::Cube(): MeshData3D("", Mesh::Primitive::Triangles, new std::vector<std::uint32_t>{
0, 1, 2, 0, 2, 3, /* +Z */
4, 5, 6, 4, 6, 7, /* +X */
8, 9, 10, 8, 10, 11, /* +Y */
12, 13, 14, 12, 14, 15, /* -Z */
16, 17, 18, 16, 18, 19, /* -Y */
20, 21, 22, 20, 22, 23 /* -X */
}, {new std::vector<Point3D>{
{-1.0f, -1.0f, 1.0f},
{ 1.0f, -1.0f, 1.0f},
{ 1.0f, 1.0f, 1.0f}, /* +Z */
{-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, 1.0f, -1.0f}, /* +X */
{ 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, 1.0f, -1.0f}, /* +Y */
{-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, 1.0f, -1.0f}, /* -Z */
{ 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, -1.0f, 1.0f}, /* -Y */
{-1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ube.h

@ -26,7 +26,7 @@ namespace Magnum { namespace Primitives {
/**
@brief 3D cube primitive
2x2x2 cube. Non-indexed triangle mesh with flat normals.
2x2x2 cube. Indexed triangle mesh with flat normals.
*/
class Cube: public Trade::MeshData3D {
public:

Loading…
Cancel
Save