From b2679d32f8e2893f063518bb5d3057f28d7f1b99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 26 Sep 2012 00:30:05 +0200 Subject: [PATCH] MeshTools: added transform() function. In the future it will use multithreading/GPU transform feedback for large arrays. --- src/MeshTools/CMakeLists.txt | 1 + src/MeshTools/Transform.h | 44 ++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 src/MeshTools/Transform.h diff --git a/src/MeshTools/CMakeLists.txt b/src/MeshTools/CMakeLists.txt index 095431bf7..4fb800958 100644 --- a/src/MeshTools/CMakeLists.txt +++ b/src/MeshTools/CMakeLists.txt @@ -11,6 +11,7 @@ set(MagnumMeshTools_HEADERS Interleave.h Subdivide.h Tipsify.h + Transform.h magnumMeshToolsVisibility.h) add_library(MagnumMeshToolsObjects OBJECT ${MagnumMeshTools_SRCS}) diff --git a/src/MeshTools/Transform.h b/src/MeshTools/Transform.h new file mode 100644 index 000000000..7e09e59ae --- /dev/null +++ b/src/MeshTools/Transform.h @@ -0,0 +1,44 @@ +#ifndef Magnum_MeshTools_Transform_h +#define Magnum_MeshTools_Transform_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Function Magnum::MeshTools::transform() + */ + +#include "Math/Matrix.h" + +namespace Magnum { namespace MeshTools { + +/** +@brief Transform vertices using given matrix + +Usable for mesh transformations that would otherwise negatively affect +dependent objects, such as (uneven) scaling. Example usage: + +@code +std::vector vertices; +MeshTools::transform(Matrix4::scaling({2.0f, 0.5f, 0.0f}), vertices); +@endcode +*/ +template inline void transform(const Math::Matrix& matrix, U& vertices) { + for(Math::Vector& vertex: vertices) + vertex = matrix*vertex; +} + +}} + +#endif