From 72ffca1dade0605f0b79ecaaa630e2ba89a5e457 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 21 Nov 2012 14:37:20 +0100 Subject: [PATCH] Cube primitive has now flat normals. Exactly how would everyone expect. --- src/Primitives/Cube.cpp | 95 +++++++++++++++++++++++++++++++++-------- src/Primitives/Cube.h | 3 +- 2 files changed, 79 insertions(+), 19 deletions(-) diff --git a/src/Primitives/Cube.cpp b/src/Primitives/Cube.cpp index 739f2e6dd..12d92139f 100644 --- a/src/Primitives/Cube.cpp +++ b/src/Primitives/Cube.cpp @@ -21,30 +21,91 @@ using namespace std; namespace Magnum { namespace Primitives { -Cube::Cube(): MeshData3D("", Mesh::Primitive::Triangles, new vector{ - 0, 2, 1, - 2, 3, 1, - 1, 3, 5, - 3, 7, 5, - 5, 7, 4, - 7, 6, 4, - 4, 6, 0, - 6, 2, 0, - 2, 7, 3, - 2, 6, 7, - 4, 1, 5, - 4, 0, 1 -}, {new vector}, {new vector{ +Cube::Cube(): MeshData3D("", Mesh::Primitive::Triangles, nullptr, {new vector{ + {-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}, + { 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}, /* -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} +}}, {new vector{ + { 0.0f, 0.0f, 1.0f}, + { 0.0f, 0.0f, 1.0f}, + { 0.0f, 0.0f, 1.0f}, /* +Z */ + { 0.0f, 0.0f, 1.0f}, + { 0.0f, 0.0f, 1.0f}, + { 0.0f, 0.0f, 1.0f}, + + { 1.0f, 0.0f, 0.0f}, + { 1.0f, 0.0f, 0.0f}, + { 1.0f, 0.0f, 0.0f}, /* +X */ + { 1.0f, 0.0f, 0.0f}, + { 1.0f, 0.0f, 0.0f}, + { 1.0f, 0.0f, 0.0f}, + + { 0.0f, 1.0f, 0.0f}, + { 0.0f, 1.0f, 0.0f}, + { 0.0f, 1.0f, 0.0f}, /* +Y */ + { 0.0f, 1.0f, 0.0f}, + { 0.0f, 1.0f, 0.0f}, + { 0.0f, 1.0f, 0.0f}, + + { 0.0f, 0.0f, -1.0f}, + { 0.0f, 0.0f, -1.0f}, + { 0.0f, 0.0f, -1.0f}, /* -Z */ + { 0.0f, 0.0f, -1.0f}, + { 0.0f, 0.0f, -1.0f}, + { 0.0f, 0.0f, -1.0f}, + + { 0.0f, -1.0f, 0.0f}, + { 0.0f, -1.0f, 0.0f}, + { 0.0f, -1.0f, 0.0f}, /* -Y */ + { 0.0f, -1.0f, 0.0f}, + { 0.0f, -1.0f, 0.0f}, + { 0.0f, -1.0f, 0.0f}, + + {-1.0f, 0.0f, 0.0f}, + {-1.0f, 0.0f, 0.0f}, + {-1.0f, 0.0f, 0.0f}, /* -X */ + {-1.0f, 0.0f, 0.0f}, + {-1.0f, 0.0f, 0.0f}, + {-1.0f, 0.0f, 0.0f} }}, {}) { - positions(0)->assign(normals(0)->begin(), normals(0)->end()); } }} diff --git a/src/Primitives/Cube.h b/src/Primitives/Cube.h index e3ed55951..cf390389f 100644 --- a/src/Primitives/Cube.h +++ b/src/Primitives/Cube.h @@ -26,8 +26,7 @@ namespace Magnum { namespace Primitives { /** @brief 3D cube primitive -Indexed triangle mesh with smooth normals. -@todo Does anyone EVER want smooth normals on a cube?! +2x2x2 cube. Non-indexed triangle mesh with flat normals. */ class Cube: public Trade::MeshData3D { public: