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