// L============================================================================= // L This software is distributed under the MIT license. // L Copyright 2021 Péter Kardos // L============================================================================= #pragma once #include "../Matrix/MatrixImpl.hpp" #include "../Vector.hpp" #include "IdentityBuilder.hpp" namespace mathter { template class TranslationBuilder { public: TranslationBuilder(const Vector& translation) : translation(translation) {} TranslationBuilder& operator=(const TranslationBuilder&) = delete; template operator Matrix() const { Matrix m; Set(m); return m; } template operator Matrix() const { Matrix m; Set(m); return m; } template operator Matrix() const { Matrix m; Set(m); return m; } private: template void Set(Matrix& m) const { m = Identity(); if constexpr (Order == eMatrixOrder::FOLLOW_VECTOR) { for (int i = 0; i < translation.Dimension(); ++i) { m(Rows - 1, i) = U(translation(i)); } } else { for (int i = 0; i < translation.Dimension(); ++i) { m(i, Columns - 1) = U(translation(i)); } } } const Vector translation; }; /// Creates a translation matrix. /// The movement vector. template auto Translation(const Vector& translation) { return TranslationBuilder{ translation }; } /// Creates a translation matrix. /// A list of scalars that specify movement along repsective axes. template ::type...>::value), int>::type = 0> auto Translation(const Args&... coordinates) { using PromotedT = decltype((0 + ... + coordinates)); return TranslationBuilder{ Vector(coordinates...) }; } } // namespace mathter