86 lines
2.8 KiB
C++
86 lines
2.8 KiB
C++
// =====================================================================================================================
|
|
// fennec, a free and open source game engine
|
|
// Copyright © 2025 Medusa Slockbower
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// This program 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 General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
// =====================================================================================================================
|
|
|
|
///
|
|
/// \file swizzle.h
|
|
/// \brief part of the \ref fennec_math_vector,
|
|
///
|
|
///
|
|
/// \details
|
|
/// \author Medusa Slockbower
|
|
///
|
|
/// \copyright Copyright © 2025 Medusa Slockbower ([GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html))
|
|
///
|
|
///
|
|
|
|
#ifndef FENNEC_MATH_SWIZZLE_H
|
|
#define FENNEC_MATH_SWIZZLE_H
|
|
|
|
#include <fennec/lang/sequences.h>
|
|
#include <fennec/math/swizzle_storage.h>
|
|
|
|
namespace fennec
|
|
{
|
|
|
|
///
|
|
/// \brief Structure for Handling Vector Swizzling
|
|
///
|
|
/// \details
|
|
/// \tparam VectorT Vector Type
|
|
/// \tparam DataT Base Data Type
|
|
/// \tparam ScalarT Scalar Base Type
|
|
/// \tparam IndicesV Swizzle Indices
|
|
template<typename VectorT, typename DataT, typename ScalarT, size_t...IndicesV>
|
|
struct swizzle : public detail::swizzle_storage<DataT, ScalarT, IndicesV...>
|
|
{
|
|
public:
|
|
|
|
///
|
|
/// \brief alias for the scalar type
|
|
using scalar_t = ScalarT;
|
|
|
|
///
|
|
/// \name aliases for the size
|
|
/// @{
|
|
inline static constexpr size_t dimension = sizeof...(IndicesV); ///< \brief dimension of the swizzle
|
|
inline static constexpr size_t num_components = sizeof...(IndicesV); ///< \brief number of components
|
|
inline static constexpr size_t size = sizeof...(IndicesV); ///< \brief size of the swizzle
|
|
inline static constexpr size_t N = sizeof...(IndicesV); ///< \brief size of the swizzle
|
|
/// @}
|
|
|
|
///
|
|
/// \brief Decay the Swizzle into a Vector
|
|
/// \return The Value of the Swizzle as a Vector
|
|
constexpr VectorT decay() const { VectorT res; return decay_impl(res, make_index_sequence<size>{}); }
|
|
|
|
///
|
|
/// \brief Vector Cast Operator
|
|
/// \returns The Value of the Swizzle as a Vector
|
|
constexpr explicit operator VectorT() const { return decay(); }
|
|
|
|
swizzle() = default;
|
|
|
|
private:
|
|
template<size_t...VecIndicesV>
|
|
constexpr VectorT& decay_impl(VectorT& vec, index_sequence<VecIndicesV...>) { return ((vec[VecIndicesV] = this->data[IndicesV]), ..., vec); }
|
|
};
|
|
|
|
}
|
|
|
|
#endif // FENNEC_MATH_SWIZZLE_H
|