#pragma once #include "data_type.hpp" namespace internal { namespace model_matrix { enum class axis { x, y, z }; template struct helper { static paired_model_matrix get() { paired_model_matrix res{}; Eigen::Vector3d src{1, 0, 0}, to{}; if constexpr (to_axis == axis::x) to = {1, 0, 0}; else if constexpr (to_axis == axis::y) to = {0, 1, 0}; else to = {0, 0, 1}; if constexpr (flip) to = -to; Eigen::Isometry3d local_to_world{}; auto rot = Eigen::Quaterniond::FromTwoVectors(src, to); local_to_world.linear() = rot.toRotationMatrix(); local_to_world.translation() = Eigen::Vector3d{dx, dy, dz}; res.local_to_world = local_to_world; res.world_to_local = local_to_world.inverse(); for (auto i = 0; i < res.local_to_world.matrix().size(); ++i) { if (std::abs(res.local_to_world.data()[i]) < epsilon) res.local_to_world.data()[i] = 0; if (std::abs(res.world_to_local.data()[i]) < epsilon) res.world_to_local.data()[i] = 0; } return res; } static paired_model_matrix matrices; }; template paired_model_matrix helper::matrices = helper::get(); } // namespace model_matrix template static const paired_model_matrix_ptr_t matrices_ptr = make_pointer_wrapper(model_matrix::helper::matrices); template static const paired_model_matrix_ptr_t trans_by_target_axis_matrices_ptr; template static const paired_model_matrix_ptr_t trans_by_target_axis_matrices_ptr = matrices_ptr < model_matrix::axis::x, flip, flip ? -static_cast(translation) : static_cast(translation), 0, 0 > ; template static const paired_model_matrix_ptr_t trans_by_target_axis_matrices_ptr = matrices_ptr < model_matrix::axis::y, flip, 0, flip ? -static_cast(translation) : static_cast(translation), 0 > ; template static const paired_model_matrix_ptr_t trans_by_target_axis_matrices_ptr = matrices_ptr < model_matrix::axis::z, flip, 0, 0, flip ? -static_cast(translation) : static_cast(translation) > ; static const auto identity_model_matrix_ptr = matrices_ptr<>; } // namespace internal