From 6f67371bb1b46579ae837d0e0c61ac1b291be743 Mon Sep 17 00:00:00 2001 From: LaG1924 <12997935+LaG1924@users.noreply.github.com> Date: Sat, 13 Jan 2018 07:51:33 +0500 Subject: Directory renamed --- external/include/glm/gtc/bitfield.hpp | 207 +++++++ external/include/glm/gtc/bitfield.inl | 515 +++++++++++++++ external/include/glm/gtc/color_encoding.inl | 65 ++ external/include/glm/gtc/color_space.hpp | 56 ++ external/include/glm/gtc/color_space.inl | 75 +++ external/include/glm/gtc/constants.hpp | 176 ++++++ external/include/glm/gtc/constants.inl | 181 ++++++ external/include/glm/gtc/epsilon.hpp | 73 +++ external/include/glm/gtc/epsilon.inl | 125 ++++ external/include/glm/gtc/functions.hpp | 53 ++ external/include/glm/gtc/functions.inl | 31 + external/include/glm/gtc/integer.hpp | 102 +++ external/include/glm/gtc/integer.inl | 71 +++ external/include/glm/gtc/matrix_access.hpp | 59 ++ external/include/glm/gtc/matrix_access.inl | 63 ++ external/include/glm/gtc/matrix_integer.hpp | 486 +++++++++++++++ external/include/glm/gtc/matrix_inverse.hpp | 49 ++ external/include/glm/gtc/matrix_inverse.inl | 120 ++++ external/include/glm/gtc/matrix_transform.hpp | 465 ++++++++++++++ external/include/glm/gtc/matrix_transform.inl | 575 +++++++++++++++++ external/include/glm/gtc/noise.hpp | 60 ++ external/include/glm/gtc/noise.inl | 808 ++++++++++++++++++++++++ external/include/glm/gtc/packing.hpp | 579 +++++++++++++++++ external/include/glm/gtc/packing.inl | 781 +++++++++++++++++++++++ external/include/glm/gtc/quaternion.hpp | 397 ++++++++++++ external/include/glm/gtc/quaternion.inl | 795 ++++++++++++++++++++++++ external/include/glm/gtc/quaternion_simd.inl | 198 ++++++ external/include/glm/gtc/random.hpp | 98 +++ external/include/glm/gtc/random.inl | 350 +++++++++++ external/include/glm/gtc/reciprocal.hpp | 135 ++++ external/include/glm/gtc/reciprocal.inl | 192 ++++++ external/include/glm/gtc/round.hpp | 174 ++++++ external/include/glm/gtc/round.inl | 344 ++++++++++ external/include/glm/gtc/type_aligned.hpp | 362 +++++++++++ external/include/glm/gtc/type_precision.hpp | 861 ++++++++++++++++++++++++++ external/include/glm/gtc/type_precision.inl | 7 + external/include/glm/gtc/type_ptr.hpp | 149 +++++ external/include/glm/gtc/type_ptr.inl | 450 ++++++++++++++ external/include/glm/gtc/ulp.hpp | 63 ++ external/include/glm/gtc/ulp.inl | 321 ++++++++++ external/include/glm/gtc/vec1.hpp | 164 +++++ external/include/glm/gtc/vec1.inl | 2 + 42 files changed, 10837 insertions(+) create mode 100644 external/include/glm/gtc/bitfield.hpp create mode 100644 external/include/glm/gtc/bitfield.inl create mode 100644 external/include/glm/gtc/color_encoding.inl create mode 100644 external/include/glm/gtc/color_space.hpp create mode 100644 external/include/glm/gtc/color_space.inl create mode 100644 external/include/glm/gtc/constants.hpp create mode 100644 external/include/glm/gtc/constants.inl create mode 100644 external/include/glm/gtc/epsilon.hpp create mode 100644 external/include/glm/gtc/epsilon.inl create mode 100644 external/include/glm/gtc/functions.hpp create mode 100644 external/include/glm/gtc/functions.inl create mode 100644 external/include/glm/gtc/integer.hpp create mode 100644 external/include/glm/gtc/integer.inl create mode 100644 external/include/glm/gtc/matrix_access.hpp create mode 100644 external/include/glm/gtc/matrix_access.inl create mode 100644 external/include/glm/gtc/matrix_integer.hpp create mode 100644 external/include/glm/gtc/matrix_inverse.hpp create mode 100644 external/include/glm/gtc/matrix_inverse.inl create mode 100644 external/include/glm/gtc/matrix_transform.hpp create mode 100644 external/include/glm/gtc/matrix_transform.inl create mode 100644 external/include/glm/gtc/noise.hpp create mode 100644 external/include/glm/gtc/noise.inl create mode 100644 external/include/glm/gtc/packing.hpp create mode 100644 external/include/glm/gtc/packing.inl create mode 100644 external/include/glm/gtc/quaternion.hpp create mode 100644 external/include/glm/gtc/quaternion.inl create mode 100644 external/include/glm/gtc/quaternion_simd.inl create mode 100644 external/include/glm/gtc/random.hpp create mode 100644 external/include/glm/gtc/random.inl create mode 100644 external/include/glm/gtc/reciprocal.hpp create mode 100644 external/include/glm/gtc/reciprocal.inl create mode 100644 external/include/glm/gtc/round.hpp create mode 100644 external/include/glm/gtc/round.inl create mode 100644 external/include/glm/gtc/type_aligned.hpp create mode 100644 external/include/glm/gtc/type_precision.hpp create mode 100644 external/include/glm/gtc/type_precision.inl create mode 100644 external/include/glm/gtc/type_ptr.hpp create mode 100644 external/include/glm/gtc/type_ptr.inl create mode 100644 external/include/glm/gtc/ulp.hpp create mode 100644 external/include/glm/gtc/ulp.inl create mode 100644 external/include/glm/gtc/vec1.hpp create mode 100644 external/include/glm/gtc/vec1.inl (limited to 'external/include/glm/gtc') diff --git a/external/include/glm/gtc/bitfield.hpp b/external/include/glm/gtc/bitfield.hpp new file mode 100644 index 0000000..38a38b6 --- /dev/null +++ b/external/include/glm/gtc/bitfield.hpp @@ -0,0 +1,207 @@ +/// @ref gtc_bitfield +/// @file glm/gtc/bitfield.hpp +/// +/// @see core (dependence) +/// @see gtc_bitfield (dependence) +/// +/// @defgroup gtc_bitfield GLM_GTC_bitfield +/// @ingroup gtc +/// +/// @brief Allow to perform bit operations on integer values +/// +/// need to be included to use these functionalities. + +#pragma once + +// Dependencies +#include "../detail/setup.hpp" +#include "../detail/precision.hpp" +#include "../detail/type_int.hpp" +#include "../detail/_vectorize.hpp" +#include + +#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED) +# pragma message("GLM: GLM_GTC_bitfield extension included") +#endif + +namespace glm +{ + /// @addtogroup gtc_bitfield + /// @{ + + /// Build a mask of 'count' bits + /// + /// @see gtc_bitfield + template + GLM_FUNC_DECL genIUType mask(genIUType Bits); + + /// Build a mask of 'count' bits + /// + /// @see gtc_bitfield + template class vecIUType> + GLM_FUNC_DECL vecIUType mask(vecIUType const & v); + + /// Rotate all bits to the right. All the bits dropped in the right side are inserted back on the left side. + /// + /// @see gtc_bitfield + template + GLM_FUNC_DECL genIUType bitfieldRotateRight(genIUType In, int Shift); + + /// Rotate all bits to the right. All the bits dropped in the right side are inserted back on the left side. + /// + /// @see gtc_bitfield + template class vecType> + GLM_FUNC_DECL vecType bitfieldRotateRight(vecType const & In, int Shift); + + /// Rotate all bits to the left. All the bits dropped in the left side are inserted back on the right side. + /// + /// @see gtc_bitfield + template + GLM_FUNC_DECL genIUType bitfieldRotateLeft(genIUType In, int Shift); + + /// Rotate all bits to the left. All the bits dropped in the left side are inserted back on the right side. + /// + /// @see gtc_bitfield + template class vecType> + GLM_FUNC_DECL vecType bitfieldRotateLeft(vecType const & In, int Shift); + + /// Set to 1 a range of bits. + /// + /// @see gtc_bitfield + template + GLM_FUNC_DECL genIUType bitfieldFillOne(genIUType Value, int FirstBit, int BitCount); + + /// Set to 1 a range of bits. + /// + /// @see gtc_bitfield + template class vecType> + GLM_FUNC_DECL vecType bitfieldFillOne(vecType const & Value, int FirstBit, int BitCount); + + /// Set to 0 a range of bits. + /// + /// @see gtc_bitfield + template + GLM_FUNC_DECL genIUType bitfieldFillZero(genIUType Value, int FirstBit, int BitCount); + + /// Set to 0 a range of bits. + /// + /// @see gtc_bitfield + template class vecType> + GLM_FUNC_DECL vecType bitfieldFillZero(vecType const & Value, int FirstBit, int BitCount); + + /// Interleaves the bits of x and y. + /// The first bit is the first bit of x followed by the first bit of y. + /// The other bits are interleaved following the previous sequence. + /// + /// @see gtc_bitfield + GLM_FUNC_DECL int16 bitfieldInterleave(int8 x, int8 y); + + /// Interleaves the bits of x and y. + /// The first bit is the first bit of x followed by the first bit of y. + /// The other bits are interleaved following the previous sequence. + /// + /// @see gtc_bitfield + GLM_FUNC_DECL uint16 bitfieldInterleave(uint8 x, uint8 y); + + /// Interleaves the bits of x and y. + /// The first bit is the first bit of x followed by the first bit of y. + /// The other bits are interleaved following the previous sequence. + /// + /// @see gtc_bitfield + GLM_FUNC_DECL int32 bitfieldInterleave(int16 x, int16 y); + + /// Interleaves the bits of x and y. + /// The first bit is the first bit of x followed by the first bit of y. + /// The other bits are interleaved following the previous sequence. + /// + /// @see gtc_bitfield + GLM_FUNC_DECL uint32 bitfieldInterleave(uint16 x, uint16 y); + + /// Interleaves the bits of x and y. + /// The first bit is the first bit of x followed by the first bit of y. + /// The other bits are interleaved following the previous sequence. + /// + /// @see gtc_bitfield + GLM_FUNC_DECL int64 bitfieldInterleave(int32 x, int32 y); + + /// Interleaves the bits of x and y. + /// The first bit is the first bit of x followed by the first bit of y. + /// The other bits are interleaved following the previous sequence. + /// + /// @see gtc_bitfield + GLM_FUNC_DECL uint64 bitfieldInterleave(uint32 x, uint32 y); + + /// Interleaves the bits of x, y and z. + /// The first bit is the first bit of x followed by the first bit of y and the first bit of z. + /// The other bits are interleaved following the previous sequence. + /// + /// @see gtc_bitfield + GLM_FUNC_DECL int32 bitfieldInterleave(int8 x, int8 y, int8 z); + + /// Interleaves the bits of x, y and z. + /// The first bit is the first bit of x followed by the first bit of y and the first bit of z. + /// The other bits are interleaved following the previous sequence. + /// + /// @see gtc_bitfield + GLM_FUNC_DECL uint32 bitfieldInterleave(uint8 x, uint8 y, uint8 z); + + /// Interleaves the bits of x, y and z. + /// The first bit is the first bit of x followed by the first bit of y and the first bit of z. + /// The other bits are interleaved following the previous sequence. + /// + /// @see gtc_bitfield + GLM_FUNC_DECL int64 bitfieldInterleave(int16 x, int16 y, int16 z); + + /// Interleaves the bits of x, y and z. + /// The first bit is the first bit of x followed by the first bit of y and the first bit of z. + /// The other bits are interleaved following the previous sequence. + /// + /// @see gtc_bitfield + GLM_FUNC_DECL uint64 bitfieldInterleave(uint16 x, uint16 y, uint16 z); + + /// Interleaves the bits of x, y and z. + /// The first bit is the first bit of x followed by the first bit of y and the first bit of z. + /// The other bits are interleaved following the previous sequence. + /// + /// @see gtc_bitfield + GLM_FUNC_DECL int64 bitfieldInterleave(int32 x, int32 y, int32 z); + + /// Interleaves the bits of x, y and z. + /// The first bit is the first bit of x followed by the first bit of y and the first bit of z. + /// The other bits are interleaved following the previous sequence. + /// + /// @see gtc_bitfield + GLM_FUNC_DECL uint64 bitfieldInterleave(uint32 x, uint32 y, uint32 z); + + /// Interleaves the bits of x, y, z and w. + /// The first bit is the first bit of x followed by the first bit of y, the first bit of z and finally the first bit of w. + /// The other bits are interleaved following the previous sequence. + /// + /// @see gtc_bitfield + GLM_FUNC_DECL int32 bitfieldInterleave(int8 x, int8 y, int8 z, int8 w); + + /// Interleaves the bits of x, y, z and w. + /// The first bit is the first bit of x followed by the first bit of y, the first bit of z and finally the first bit of w. + /// The other bits are interleaved following the previous sequence. + /// + /// @see gtc_bitfield + GLM_FUNC_DECL uint32 bitfieldInterleave(uint8 x, uint8 y, uint8 z, uint8 w); + + /// Interleaves the bits of x, y, z and w. + /// The first bit is the first bit of x followed by the first bit of y, the first bit of z and finally the first bit of w. + /// The other bits are interleaved following the previous sequence. + /// + /// @see gtc_bitfield + GLM_FUNC_DECL int64 bitfieldInterleave(int16 x, int16 y, int16 z, int16 w); + + /// Interleaves the bits of x, y, z and w. + /// The first bit is the first bit of x followed by the first bit of y, the first bit of z and finally the first bit of w. + /// The other bits are interleaved following the previous sequence. + /// + /// @see gtc_bitfield + GLM_FUNC_DECL uint64 bitfieldInterleave(uint16 x, uint16 y, uint16 z, uint16 w); + + /// @} +} //namespace glm + +#include "bitfield.inl" diff --git a/external/include/glm/gtc/bitfield.inl b/external/include/glm/gtc/bitfield.inl new file mode 100644 index 0000000..490cfb3 --- /dev/null +++ b/external/include/glm/gtc/bitfield.inl @@ -0,0 +1,515 @@ +/// @ref gtc_bitfield +/// @file glm/gtc/bitfield.inl + +#include "../simd/integer.h" + +namespace glm{ +namespace detail +{ + template + GLM_FUNC_DECL RET bitfieldInterleave(PARAM x, PARAM y); + + template + GLM_FUNC_DECL RET bitfieldInterleave(PARAM x, PARAM y, PARAM z); + + template + GLM_FUNC_DECL RET bitfieldInterleave(PARAM x, PARAM y, PARAM z, PARAM w); + + template <> + GLM_FUNC_QUALIFIER glm::uint16 bitfieldInterleave(glm::uint8 x, glm::uint8 y) + { + glm::uint16 REG1(x); + glm::uint16 REG2(y); + + REG1 = ((REG1 << 4) | REG1) & glm::uint16(0x0F0F); + REG2 = ((REG2 << 4) | REG2) & glm::uint16(0x0F0F); + + REG1 = ((REG1 << 2) | REG1) & glm::uint16(0x3333); + REG2 = ((REG2 << 2) | REG2) & glm::uint16(0x3333); + + REG1 = ((REG1 << 1) | REG1) & glm::uint16(0x5555); + REG2 = ((REG2 << 1) | REG2) & glm::uint16(0x5555); + + return REG1 | (REG2 << 1); + } + + template <> + GLM_FUNC_QUALIFIER glm::uint32 bitfieldInterleave(glm::uint16 x, glm::uint16 y) + { + glm::uint32 REG1(x); + glm::uint32 REG2(y); + + REG1 = ((REG1 << 8) | REG1) & glm::uint32(0x00FF00FF); + REG2 = ((REG2 << 8) | REG2) & glm::uint32(0x00FF00FF); + + REG1 = ((REG1 << 4) | REG1) & glm::uint32(0x0F0F0F0F); + REG2 = ((REG2 << 4) | REG2) & glm::uint32(0x0F0F0F0F); + + REG1 = ((REG1 << 2) | REG1) & glm::uint32(0x33333333); + REG2 = ((REG2 << 2) | REG2) & glm::uint32(0x33333333); + + REG1 = ((REG1 << 1) | REG1) & glm::uint32(0x55555555); + REG2 = ((REG2 << 1) | REG2) & glm::uint32(0x55555555); + + return REG1 | (REG2 << 1); + } + + template <> + GLM_FUNC_QUALIFIER glm::uint64 bitfieldInterleave(glm::uint32 x, glm::uint32 y) + { + glm::uint64 REG1(x); + glm::uint64 REG2(y); + + REG1 = ((REG1 << 16) | REG1) & glm::uint64(0x0000FFFF0000FFFFull); + REG2 = ((REG2 << 16) | REG2) & glm::uint64(0x0000FFFF0000FFFFull); + + REG1 = ((REG1 << 8) | REG1) & glm::uint64(0x00FF00FF00FF00FFull); + REG2 = ((REG2 << 8) | REG2) & glm::uint64(0x00FF00FF00FF00FFull); + + REG1 = ((REG1 << 4) | REG1) & glm::uint64(0x0F0F0F0F0F0F0F0Full); + REG2 = ((REG2 << 4) | REG2) & glm::uint64(0x0F0F0F0F0F0F0F0Full); + + REG1 = ((REG1 << 2) | REG1) & glm::uint64(0x3333333333333333ull); + REG2 = ((REG2 << 2) | REG2) & glm::uint64(0x3333333333333333ull); + + REG1 = ((REG1 << 1) | REG1) & glm::uint64(0x5555555555555555ull); + REG2 = ((REG2 << 1) | REG2) & glm::uint64(0x5555555555555555ull); + + return REG1 | (REG2 << 1); + } + + template <> + GLM_FUNC_QUALIFIER glm::uint32 bitfieldInterleave(glm::uint8 x, glm::uint8 y, glm::uint8 z) + { + glm::uint32 REG1(x); + glm::uint32 REG2(y); + glm::uint32 REG3(z); + + REG1 = ((REG1 << 16) | REG1) & glm::uint32(0x00FF0000FF0000FF); + REG2 = ((REG2 << 16) | REG2) & glm::uint32(0x00FF0000FF0000FF); + REG3 = ((REG3 << 16) | REG3) & glm::uint32(0x00FF0000FF0000FF); + + REG1 = ((REG1 << 8) | REG1) & glm::uint32(0xF00F00F00F00F00F); + REG2 = ((REG2 << 8) | REG2) & glm::uint32(0xF00F00F00F00F00F); + REG3 = ((REG3 << 8) | REG3) & glm::uint32(0xF00F00F00F00F00F); + + REG1 = ((REG1 << 4) | REG1) & glm::uint32(0x30C30C30C30C30C3); + REG2 = ((REG2 << 4) | REG2) & glm::uint32(0x30C30C30C30C30C3); + REG3 = ((REG3 << 4) | REG3) & glm::uint32(0x30C30C30C30C30C3); + + REG1 = ((REG1 << 2) | REG1) & glm::uint32(0x9249249249249249); + REG2 = ((REG2 << 2) | REG2) & glm::uint32(0x9249249249249249); + REG3 = ((REG3 << 2) | REG3) & glm::uint32(0x9249249249249249); + + return REG1 | (REG2 << 1) | (REG3 << 2); + } + + template <> + GLM_FUNC_QUALIFIER glm::uint64 bitfieldInterleave(glm::uint16 x, glm::uint16 y, glm::uint16 z) + { + glm::uint64 REG1(x); + glm::uint64 REG2(y); + glm::uint64 REG3(z); + + REG1 = ((REG1 << 32) | REG1) & glm::uint64(0xFFFF00000000FFFFull); + REG2 = ((REG2 << 32) | REG2) & glm::uint64(0xFFFF00000000FFFFull); + REG3 = ((REG3 << 32) | REG3) & glm::uint64(0xFFFF00000000FFFFull); + + REG1 = ((REG1 << 16) | REG1) & glm::uint64(0x00FF0000FF0000FFull); + REG2 = ((REG2 << 16) | REG2) & glm::uint64(0x00FF0000FF0000FFull); + REG3 = ((REG3 << 16) | REG3) & glm::uint64(0x00FF0000FF0000FFull); + + REG1 = ((REG1 << 8) | REG1) & glm::uint64(0xF00F00F00F00F00Full); + REG2 = ((REG2 << 8) | REG2) & glm::uint64(0xF00F00F00F00F00Full); + REG3 = ((REG3 << 8) | REG3) & glm::uint64(0xF00F00F00F00F00Full); + + REG1 = ((REG1 << 4) | REG1) & glm::uint64(0x30C30C30C30C30C3ull); + REG2 = ((REG2 << 4) | REG2) & glm::uint64(0x30C30C30C30C30C3ull); + REG3 = ((REG3 << 4) | REG3) & glm::uint64(0x30C30C30C30C30C3ull); + + REG1 = ((REG1 << 2) | REG1) & glm::uint64(0x9249249249249249ull); + REG2 = ((REG2 << 2) | REG2) & glm::uint64(0x9249249249249249ull); + REG3 = ((REG3 << 2) | REG3) & glm::uint64(0x9249249249249249ull); + + return REG1 | (REG2 << 1) | (REG3 << 2); + } + + template <> + GLM_FUNC_QUALIFIER glm::uint64 bitfieldInterleave(glm::uint32 x, glm::uint32 y, glm::uint32 z) + { + glm::uint64 REG1(x); + glm::uint64 REG2(y); + glm::uint64 REG3(z); + + REG1 = ((REG1 << 32) | REG1) & glm::uint64(0xFFFF00000000FFFFull); + REG2 = ((REG2 << 32) | REG2) & glm::uint64(0xFFFF00000000FFFFull); + REG3 = ((REG3 << 32) | REG3) & glm::uint64(0xFFFF00000000FFFFull); + + REG1 = ((REG1 << 16) | REG1) & glm::uint64(0x00FF0000FF0000FFull); + REG2 = ((REG2 << 16) | REG2) & glm::uint64(0x00FF0000FF0000FFull); + REG3 = ((REG3 << 16) | REG3) & glm::uint64(0x00FF0000FF0000FFull); + + REG1 = ((REG1 << 8) | REG1) & glm::uint64(0xF00F00F00F00F00Full); + REG2 = ((REG2 << 8) | REG2) & glm::uint64(0xF00F00F00F00F00Full); + REG3 = ((REG3 << 8) | REG3) & glm::uint64(0xF00F00F00F00F00Full); + + REG1 = ((REG1 << 4) | REG1) & glm::uint64(0x30C30C30C30C30C3ull); + REG2 = ((REG2 << 4) | REG2) & glm::uint64(0x30C30C30C30C30C3ull); + REG3 = ((REG3 << 4) | REG3) & glm::uint64(0x30C30C30C30C30C3ull); + + REG1 = ((REG1 << 2) | REG1) & glm::uint64(0x9249249249249249ull); + REG2 = ((REG2 << 2) | REG2) & glm::uint64(0x9249249249249249ull); + REG3 = ((REG3 << 2) | REG3) & glm::uint64(0x9249249249249249ull); + + return REG1 | (REG2 << 1) | (REG3 << 2); + } + + template <> + GLM_FUNC_QUALIFIER glm::uint32 bitfieldInterleave(glm::uint8 x, glm::uint8 y, glm::uint8 z, glm::uint8 w) + { + glm::uint32 REG1(x); + glm::uint32 REG2(y); + glm::uint32 REG3(z); + glm::uint32 REG4(w); + + REG1 = ((REG1 << 12) | REG1) & glm::uint32(0x000F000F000F000F); + REG2 = ((REG2 << 12) | REG2) & glm::uint32(0x000F000F000F000F); + REG3 = ((REG3 << 12) | REG3) & glm::uint32(0x000F000F000F000F); + REG4 = ((REG4 << 12) | REG4) & glm::uint32(0x000F000F000F000F); + + REG1 = ((REG1 << 6) | REG1) & glm::uint32(0x0303030303030303); + REG2 = ((REG2 << 6) | REG2) & glm::uint32(0x0303030303030303); + REG3 = ((REG3 << 6) | REG3) & glm::uint32(0x0303030303030303); + REG4 = ((REG4 << 6) | REG4) & glm::uint32(0x0303030303030303); + + REG1 = ((REG1 << 3) | REG1) & glm::uint32(0x1111111111111111); + REG2 = ((REG2 << 3) | REG2) & glm::uint32(0x1111111111111111); + REG3 = ((REG3 << 3) | REG3) & glm::uint32(0x1111111111111111); + REG4 = ((REG4 << 3) | REG4) & glm::uint32(0x1111111111111111); + + return REG1 | (REG2 << 1) | (REG3 << 2) | (REG4 << 3); + } + + template <> + GLM_FUNC_QUALIFIER glm::uint64 bitfieldInterleave(glm::uint16 x, glm::uint16 y, glm::uint16 z, glm::uint16 w) + { + glm::uint64 REG1(x); + glm::uint64 REG2(y); + glm::uint64 REG3(z); + glm::uint64 REG4(w); + + REG1 = ((REG1 << 24) | REG1) & glm::uint64(0x000000FF000000FFull); + REG2 = ((REG2 << 24) | REG2) & glm::uint64(0x000000FF000000FFull); + REG3 = ((REG3 << 24) | REG3) & glm::uint64(0x000000FF000000FFull); + REG4 = ((REG4 << 24) | REG4) & glm::uint64(0x000000FF000000FFull); + + REG1 = ((REG1 << 12) | REG1) & glm::uint64(0x000F000F000F000Full); + REG2 = ((REG2 << 12) | REG2) & glm::uint64(0x000F000F000F000Full); + REG3 = ((REG3 << 12) | REG3) & glm::uint64(0x000F000F000F000Full); + REG4 = ((REG4 << 12) | REG4) & glm::uint64(0x000F000F000F000Full); + + REG1 = ((REG1 << 6) | REG1) & glm::uint64(0x0303030303030303ull); + REG2 = ((REG2 << 6) | REG2) & glm::uint64(0x0303030303030303ull); + REG3 = ((REG3 << 6) | REG3) & glm::uint64(0x0303030303030303ull); + REG4 = ((REG4 << 6) | REG4) & glm::uint64(0x0303030303030303ull); + + REG1 = ((REG1 << 3) | REG1) & glm::uint64(0x1111111111111111ull); + REG2 = ((REG2 << 3) | REG2) & glm::uint64(0x1111111111111111ull); + REG3 = ((REG3 << 3) | REG3) & glm::uint64(0x1111111111111111ull); + REG4 = ((REG4 << 3) | REG4) & glm::uint64(0x1111111111111111ull); + + return REG1 | (REG2 << 1) | (REG3 << 2) | (REG4 << 3); + } +}//namespace detail + + template + GLM_FUNC_QUALIFIER genIUType mask(genIUType Bits) + { + GLM_STATIC_ASSERT(std::numeric_limits::is_integer, "'mask' accepts only integer values"); + + return Bits >= sizeof(genIUType) * 8 ? ~static_cast(0) : (static_cast(1) << Bits) - static_cast(1); + } + + template class vecIUType> + GLM_FUNC_QUALIFIER vecIUType mask(vecIUType const& v) + { + GLM_STATIC_ASSERT(std::numeric_limits::is_integer, "'mask' accepts only integer values"); + + return detail::functor1::call(mask, v); + } + + template + GLM_FUNC_QUALIFIER genIType bitfieldRotateRight(genIType In, int Shift) + { + GLM_STATIC_ASSERT(std::numeric_limits::is_integer, "'bitfieldRotateRight' accepts only integer values"); + + int const BitSize = static_cast(sizeof(genIType) * 8); + return (In << static_cast(Shift)) | (In >> static_cast(BitSize - Shift)); + } + + template class vecType> + GLM_FUNC_QUALIFIER vecType bitfieldRotateRight(vecType const & In, int Shift) + { + GLM_STATIC_ASSERT(std::numeric_limits::is_integer, "'bitfieldRotateRight' accepts only integer values"); + + int const BitSize = static_cast(sizeof(T) * 8); + return (In << static_cast(Shift)) | (In >> static_cast(BitSize - Shift)); + } + + template + GLM_FUNC_QUALIFIER genIType bitfieldRotateLeft(genIType In, int Shift) + { + GLM_STATIC_ASSERT(std::numeric_limits::is_integer, "'bitfieldRotateLeft' accepts only integer values"); + + int const BitSize = static_cast(sizeof(genIType) * 8); + return (In >> static_cast(Shift)) | (In << static_cast(BitSize - Shift)); + } + + template class vecType> + GLM_FUNC_QUALIFIER vecType bitfieldRotateLeft(vecType const& In, int Shift) + { + GLM_STATIC_ASSERT(std::numeric_limits::is_integer, "'bitfieldRotateLeft' accepts only integer values"); + + int const BitSize = static_cast(sizeof(T) * 8); + return (In >> static_cast(Shift)) | (In << static_cast(BitSize - Shift)); + } + + template + GLM_FUNC_QUALIFIER genIUType bitfieldFillOne(genIUType Value, int FirstBit, int BitCount) + { + return Value | static_cast(mask(BitCount) << FirstBit); + } + + template class vecType> + GLM_FUNC_QUALIFIER vecType bitfieldFillOne(vecType const& Value, int FirstBit, int BitCount) + { + return Value | static_cast(mask(BitCount) << FirstBit); + } + + template + GLM_FUNC_QUALIFIER genIUType bitfieldFillZero(genIUType Value, int FirstBit, int BitCount) + { + return Value & static_cast(~(mask(BitCount) << FirstBit)); + } + + template class vecType> + GLM_FUNC_QUALIFIER vecType bitfieldFillZero(vecType const& Value, int FirstBit, int BitCount) + { + return Value & static_cast(~(mask(BitCount) << FirstBit)); + } + + GLM_FUNC_QUALIFIER int16 bitfieldInterleave(int8 x, int8 y) + { + union sign8 + { + int8 i; + uint8 u; + } sign_x, sign_y; + + union sign16 + { + int16 i; + uint16 u; + } result; + + sign_x.i = x; + sign_y.i = y; + result.u = bitfieldInterleave(sign_x.u, sign_y.u); + + return result.i; + } + + GLM_FUNC_QUALIFIER uint16 bitfieldInterleave(uint8 x, uint8 y) + { + return detail::bitfieldInterleave(x, y); + } + + GLM_FUNC_QUALIFIER int32 bitfieldInterleave(int16 x, int16 y) + { + union sign16 + { + int16 i; + uint16 u; + } sign_x, sign_y; + + union sign32 + { + int32 i; + uint32 u; + } result; + + sign_x.i = x; + sign_y.i = y; + result.u = bitfieldInterleave(sign_x.u, sign_y.u); + + return result.i; + } + + GLM_FUNC_QUALIFIER uint32 bitfieldInterleave(uint16 x, uint16 y) + { + return detail::bitfieldInterleave(x, y); + } + + GLM_FUNC_QUALIFIER int64 bitfieldInterleave(int32 x, int32 y) + { + union sign32 + { + int32 i; + uint32 u; + } sign_x, sign_y; + + union sign64 + { + int64 i; + uint64 u; + } result; + + sign_x.i = x; + sign_y.i = y; + result.u = bitfieldInterleave(sign_x.u, sign_y.u); + + return result.i; + } + + GLM_FUNC_QUALIFIER uint64 bitfieldInterleave(uint32 x, uint32 y) + { + return detail::bitfieldInterleave(x, y); + } + + GLM_FUNC_QUALIFIER int32 bitfieldInterleave(int8 x, int8 y, int8 z) + { + union sign8 + { + int8 i; + uint8 u; + } sign_x, sign_y, sign_z; + + union sign32 + { + int32 i; + uint32 u; + } result; + + sign_x.i = x; + sign_y.i = y; + sign_z.i = z; + result.u = bitfieldInterleave(sign_x.u, sign_y.u, sign_z.u); + + return result.i; + } + + GLM_FUNC_QUALIFIER uint32 bitfieldInterleave(uint8 x, uint8 y, uint8 z) + { + return detail::bitfieldInterleave(x, y, z); + } + + GLM_FUNC_QUALIFIER int64 bitfieldInterleave(int16 x, int16 y, int16 z) + { + union sign16 + { + int16 i; + uint16 u; + } sign_x, sign_y, sign_z; + + union sign64 + { + int64 i; + uint64 u; + } result; + + sign_x.i = x; + sign_y.i = y; + sign_z.i = z; + result.u = bitfieldInterleave(sign_x.u, sign_y.u, sign_z.u); + + return result.i; + } + + GLM_FUNC_QUALIFIER uint64 bitfieldInterleave(uint16 x, uint16 y, uint16 z) + { + return detail::bitfieldInterleave(x, y, z); + } + + GLM_FUNC_QUALIFIER int64 bitfieldInterleave(int32 x, int32 y, int32 z) + { + union sign16 + { + int32 i; + uint32 u; + } sign_x, sign_y, sign_z; + + union sign64 + { + int64 i; + uint64 u; + } result; + + sign_x.i = x; + sign_y.i = y; + sign_z.i = z; + result.u = bitfieldInterleave(sign_x.u, sign_y.u, sign_z.u); + + return result.i; + } + + GLM_FUNC_QUALIFIER uint64 bitfieldInterleave(uint32 x, uint32 y, uint32 z) + { + return detail::bitfieldInterleave(x, y, z); + } + + GLM_FUNC_QUALIFIER int32 bitfieldInterleave(int8 x, int8 y, int8 z, int8 w) + { + union sign8 + { + int8 i; + uint8 u; + } sign_x, sign_y, sign_z, sign_w; + + union sign32 + { + int32 i; + uint32 u; + } result; + + sign_x.i = x; + sign_y.i = y; + sign_z.i = z; + sign_w.i = w; + result.u = bitfieldInterleave(sign_x.u, sign_y.u, sign_z.u, sign_w.u); + + return result.i; + } + + GLM_FUNC_QUALIFIER uint32 bitfieldInterleave(uint8 x, uint8 y, uint8 z, uint8 w) + { + return detail::bitfieldInterleave(x, y, z, w); + } + + GLM_FUNC_QUALIFIER int64 bitfieldInterleave(int16 x, int16 y, int16 z, int16 w) + { + union sign16 + { + int16 i; + uint16 u; + } sign_x, sign_y, sign_z, sign_w; + + union sign64 + { + int64 i; + uint64 u; + } result; + + sign_x.i = x; + sign_y.i = y; + sign_z.i = z; + sign_w.i = w; + result.u = bitfieldInterleave(sign_x.u, sign_y.u, sign_z.u, sign_w.u); + + return result.i; + } + + GLM_FUNC_QUALIFIER uint64 bitfieldInterleave(uint16 x, uint16 y, uint16 z, uint16 w) + { + return detail::bitfieldInterleave(x, y, z, w); + } +}//namespace glm diff --git a/external/include/glm/gtc/color_encoding.inl b/external/include/glm/gtc/color_encoding.inl new file mode 100644 index 0000000..68570cb --- /dev/null +++ b/external/include/glm/gtc/color_encoding.inl @@ -0,0 +1,65 @@ +/// @ref gtc_color_encoding +/// @file glm/gtc/color_encoding.inl + +namespace glm +{ + template + GLM_FUNC_QUALIFIER tvec3 convertLinearSRGBToD65XYZ(tvec3 const& ColorLinearSRGB) + { + tvec3 const M(0.490f, 0.17697f, 0.2f); + tvec3 const N(0.31f, 0.8124f, 0.01063f); + tvec3 const O(0.490f, 0.01f, 0.99f); + + return (M * ColorLinearSRGB + N * ColorLinearSRGB + O * ColorLinearSRGB) * static_cast(5.650675255693055f); + } + + template + GLM_FUNC_QUALIFIER tvec3 convertD65XYZToLinearSRGB(tvec3 const& ColorD65XYZ) + { + tvec3 const M(0.41847f, -0.091169f, 0.0009209f); + tvec3 const N(-0.15866f, 0.25243f, 0.015708f); + tvec3 const O(0.0009209f, -0.0025498f, 0.1786f); + + return M * ColorD65XYZ + N * ColorD65XYZ + O * ColorD65XYZ; + } + + template + GLM_FUNC_QUALIFIER tvec3 convertLinearSRGBToD50XYZ(tvec3 const& ColorLinearSRGB) + { + tvec3 const M(0.436030342570117f, 0.222438466210245f, 0.013897440074263f); + tvec3 const N(0.385101860087134f, 0.716942745571917f, 0.097076381494207f); + tvec3 const O(0.143067806654203f, 0.060618777416563f, 0.713926257896652f); + + return M * ColorLinearSRGB + N * ColorLinearSRGB + O * ColorLinearSRGB; + } + + template + GLM_FUNC_QUALIFIER tvec3 convertD50XYZToLinearSRGB(tvec3 const& ColorD50XYZ) + { + tvec3 const M(); + tvec3 const N(); + tvec3 const O(); + + return M * ColorD65XYZ + N * ColorD65XYZ + O * ColorD65XYZ; + } + + template + GLM_FUNC_QUALIFIER tvec3 convertD65XYZToD50XYZ(tvec3 const& ColorD65XYZ) + { + tvec3 const M(+1.047844353856414f, +0.029549007606644f, -0.009250984365223f); + tvec3 const N(+0.022898981050086f, +0.990508028941971f, +0.015072338237051f); + tvec3 const O(-0.050206647741605f, -0.017074711360960f, +0.751717835079977f); + + return M * ColorD65XYZ + N * ColorD65XYZ + O * ColorD65XYZ; + } + + template + GLM_FUNC_QUALIFIER tvec3 convertD50XYZToD65XYZ(tvec3 const& ColorD50XYZ) + { + tvec3 const M(); + tvec3 const N(); + tvec3 const O(); + + return M * ColorD50XYZ + N * ColorD50XYZ + O * ColorD50XYZ; + } +}//namespace glm diff --git a/external/include/glm/gtc/color_space.hpp b/external/include/glm/gtc/color_space.hpp new file mode 100644 index 0000000..08ece8f --- /dev/null +++ b/external/include/glm/gtc/color_space.hpp @@ -0,0 +1,56 @@ +/// @ref gtc_color_space +/// @file glm/gtc/color_space.hpp +/// +/// @see core (dependence) +/// @see gtc_color_space (dependence) +/// +/// @defgroup gtc_color_space GLM_GTC_color_space +/// @ingroup gtc +/// +/// @brief Allow to perform bit operations on integer values +/// +/// need to be included to use these functionalities. + +#pragma once + +// Dependencies +#include "../detail/setup.hpp" +#include "../detail/precision.hpp" +#include "../exponential.hpp" +#include "../vec3.hpp" +#include "../vec4.hpp" +#include + +#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED) +# pragma message("GLM: GLM_GTC_color_space extension included") +#endif + +namespace glm +{ + /// @addtogroup gtc_color_space + /// @{ + + /// Convert a linear color to sRGB color using a standard gamma correction. + /// IEC 61966-2-1:1999 specification https://www.w3.org/Graphics/Color/srgb + template class vecType> + GLM_FUNC_DECL vecType convertLinearToSRGB(vecType const & ColorLinear); + + /// Convert a linear color to sRGB color using a custom gamma correction. + /// IEC 61966-2-1:1999 specification https://www.w3.org/Graphics/Color/srgb + template class vecType> + GLM_FUNC_DECL vecType convertLinearToSRGB(vecType const & ColorLinear, T Gamma); + + /// Convert a sRGB color to linear color using a standard gamma correction. + /// IEC 61966-2-1:1999 specification https://www.w3.org/Graphics/Color/srgb + template class vecType> + GLM_FUNC_DECL vecType convertSRGBToLinear(vecType const & ColorSRGB); + + /// Convert a sRGB color to linear color using a custom gamma correction. + // IEC 61966-2-1:1999 specification https://www.w3.org/Graphics/Color/srgb + template class vecType> + GLM_FUNC_DECL vecType convertSRGBToLinear(vecType const & ColorSRGB, T Gamma); + + /// @} +} //namespace glm + +#include "color_space.inl" diff --git a/external/include/glm/gtc/color_space.inl b/external/include/glm/gtc/color_space.inl new file mode 100644 index 0000000..c9a44ef --- /dev/null +++ b/external/include/glm/gtc/color_space.inl @@ -0,0 +1,75 @@ +/// @ref gtc_color_space +/// @file glm/gtc/color_space.inl + +namespace glm{ +namespace detail +{ + template class vecType> + struct compute_rgbToSrgb + { + GLM_FUNC_QUALIFIER static vecType call(vecType const& ColorRGB, T GammaCorrection) + { + vecType const ClampedColor(clamp(ColorRGB, static_cast(0), static_cast(1))); + + return mix( + pow(ClampedColor, vecType(GammaCorrection)) * static_cast(1.055) - static_cast(0.055), + ClampedColor * static_cast(12.92), + lessThan(ClampedColor, vecType(static_cast(0.0031308)))); + } + }; + + template + struct compute_rgbToSrgb + { + GLM_FUNC_QUALIFIER static tvec4 call(tvec4 const& ColorRGB, T GammaCorrection) + { + return tvec4(compute_rgbToSrgb::call(tvec3(ColorRGB), GammaCorrection), ColorRGB.w); + } + }; + + template class vecType> + struct compute_srgbToRgb + { + GLM_FUNC_QUALIFIER static vecType call(vecType const& ColorSRGB, T Gamma) + { + return mix( + pow((ColorSRGB + static_cast(0.055)) * static_cast(0.94786729857819905213270142180095), vecType(Gamma)), + ColorSRGB * static_cast(0.07739938080495356037151702786378), + lessThanEqual(ColorSRGB, vecType(static_cast(0.04045)))); + } + }; + + template + struct compute_srgbToRgb + { + GLM_FUNC_QUALIFIER static tvec4 call(tvec4 const& ColorSRGB, T Gamma) + { + return tvec4(compute_srgbToRgb::call(tvec3(ColorSRGB), Gamma), ColorSRGB.w); + } + }; +}//namespace detail + + template class vecType> + GLM_FUNC_QUALIFIER vecType convertLinearToSRGB(vecType const& ColorLinear) + { + return detail::compute_rgbToSrgb::call(ColorLinear, static_cast(0.41666)); + } + + template class vecType> + GLM_FUNC_QUALIFIER vecType convertLinearToSRGB(vecType const& ColorLinear, T Gamma) + { + return detail::compute_rgbToSrgb::call(ColorLinear, static_cast(1) / Gamma); + } + + template class vecType> + GLM_FUNC_QUALIFIER vecType convertSRGBToLinear(vecType const& ColorSRGB) + { + return detail::compute_srgbToRgb::call(ColorSRGB, static_cast(2.4)); + } + + template class vecType> + GLM_FUNC_QUALIFIER vecType convertSRGBToLinear(vecType const& ColorSRGB, T Gamma) + { + return detail::compute_srgbToRgb::call(ColorSRGB, Gamma); + } +}//namespace glm diff --git a/external/include/glm/gtc/constants.hpp b/external/include/glm/gtc/constants.hpp new file mode 100644 index 0000000..d3358c7 --- /dev/null +++ b/external/include/glm/gtc/constants.hpp @@ -0,0 +1,176 @@ +/// @ref gtc_constants +/// @file glm/gtc/constants.hpp +/// +/// @see core (dependence) +/// @see gtc_half_float (dependence) +/// +/// @defgroup gtc_constants GLM_GTC_constants +/// @ingroup gtc +/// +/// @brief Provide a list of constants and precomputed useful values. +/// +/// need to be included to use these features. + +#pragma once + +// Dependencies +#include "../detail/setup.hpp" + +#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED) +# pragma message("GLM: GLM_GTC_constants extension included") +#endif + +namespace glm +{ + /// @addtogroup gtc_constants + /// @{ + + /// Return the epsilon constant for floating point types. + /// @see gtc_constants + template + GLM_FUNC_DECL GLM_CONSTEXPR genType epsilon(); + + /// Return 0. + /// @see gtc_constants + template + GLM_FUNC_DECL GLM_CONSTEXPR genType zero(); + + /// Return 1. + /// @see gtc_constants + template + GLM_FUNC_DECL GLM_CONSTEXPR genType one(); + + /// Return the pi constant. + /// @see gtc_constants + template + GLM_FUNC_DECL GLM_CONSTEXPR genType pi(); + + /// Return pi * 2. + /// @see gtc_constants + template + GLM_FUNC_DECL GLM_CONSTEXPR genType two_pi(); + + /// Return square root of pi. + /// @see gtc_constants + template + GLM_FUNC_DECL GLM_CONSTEXPR genType root_pi(); + + /// Return pi / 2. + /// @see gtc_constants + template + GLM_FUNC_DECL GLM_CONSTEXPR genType half_pi(); + + /// Return pi / 2 * 3. + /// @see gtc_constants + template + GLM_FUNC_DECL GLM_CONSTEXPR genType three_over_two_pi(); + + /// Return pi / 4. + /// @see gtc_constants + template + GLM_FUNC_DECL GLM_CONSTEXPR genType quarter_pi(); + + /// Return 1 / pi. + /// @see gtc_constants + template + GLM_FUNC_DECL GLM_CONSTEXPR genType one_over_pi(); + + /// Return 1 / (pi * 2). + /// @see gtc_constants + template + GLM_FUNC_DECL GLM_CONSTEXPR genType one_over_two_pi(); + + /// Return 2 / pi. + /// @see gtc_constants + template + GLM_FUNC_DECL GLM_CONSTEXPR genType two_over_pi(); + + /// Return 4 / pi. + /// @see gtc_constants + template + GLM_FUNC_DECL GLM_CONSTEXPR genType four_over_pi(); + + /// Return 2 / sqrt(pi). + /// @see gtc_constants + template + GLM_FUNC_DECL GLM_CONSTEXPR genType two_over_root_pi(); + + /// Return 1 / sqrt(2). + /// @see gtc_constants + template + GLM_FUNC_DECL GLM_CONSTEXPR genType one_over_root_two(); + + /// Return sqrt(pi / 2). + /// @see gtc_constants + template + GLM_FUNC_DECL GLM_CONSTEXPR genType root_half_pi(); + + /// Return sqrt(2 * pi). + /// @see gtc_constants + template + GLM_FUNC_DECL GLM_CONSTEXPR genType root_two_pi(); + + /// Return sqrt(ln(4)). + /// @see gtc_constants + template + GLM_FUNC_DECL GLM_CONSTEXPR genType root_ln_four(); + + /// Return e constant. + /// @see gtc_constants + template + GLM_FUNC_DECL GLM_CONSTEXPR genType e(); + + /// Return Euler's constant. + /// @see gtc_constants + template + GLM_FUNC_DECL GLM_CONSTEXPR genType euler(); + + /// Return sqrt(2). + /// @see gtc_constants + template + GLM_FUNC_DECL GLM_CONSTEXPR genType root_two(); + + /// Return sqrt(3). + /// @see gtc_constants + template + GLM_FUNC_DECL GLM_CONSTEXPR genType root_three(); + + /// Return sqrt(5). + /// @see gtc_constants + template + GLM_FUNC_DECL GLM_CONSTEXPR genType root_five(); + + /// Return ln(2). + /// @see gtc_constants + template + GLM_FUNC_DECL GLM_CONSTEXPR genType ln_two(); + + /// Return ln(10). + /// @see gtc_constants + template + GLM_FUNC_DECL GLM_CONSTEXPR genType ln_ten(); + + /// Return ln(ln(2)). + /// @see gtc_constants + template + GLM_FUNC_DECL GLM_CONSTEXPR genType ln_ln_two(); + + /// Return 1 / 3. + /// @see gtc_constants + template + GLM_FUNC_DECL GLM_CONSTEXPR genType third(); + + /// Return 2 / 3. + /// @see gtc_constants + template + GLM_FUNC_DECL GLM_CONSTEXPR genType two_thirds(); + + /// Return the golden ratio constant. + /// @see gtc_constants + template + GLM_FUNC_DECL GLM_CONSTEXPR genType golden_ratio(); + + /// @} +} //namespace glm + +#include "constants.inl" diff --git a/external/include/glm/gtc/constants.inl b/external/include/glm/gtc/constants.inl new file mode 100644 index 0000000..cb451d0 --- /dev/null +++ b/external/include/glm/gtc/constants.inl @@ -0,0 +1,181 @@ +/// @ref gtc_constants +/// @file glm/gtc/constants.inl + +#include + +namespace glm +{ + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR genType epsilon() + { + return std::numeric_limits::epsilon(); + } + + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR genType zero() + { + return genType(0); + } + + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR genType one() + { + return genType(1); + } + + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR genType pi() + { + return genType(3.14159265358979323846264338327950288); + } + + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR genType two_pi() + { + return genType(6.28318530717958647692528676655900576); + } + + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR genType root_pi() + { + return genType(1.772453850905516027); + } + + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR genType half_pi() + { + return genType(1.57079632679489661923132169163975144); + } + + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR genType three_over_two_pi() + { + return genType(4.71238898038468985769396507491925432); + } + + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR genType quarter_pi() + { + return genType(0.785398163397448309615660845819875721); + } + + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR genType one_over_pi() + { + return genType(0.318309886183790671537767526745028724); + } + + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR genType one_over_two_pi() + { + return genType(0.159154943091895335768883763372514362); + } + + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR genType two_over_pi() + { + return genType(0.636619772367581343075535053490057448); + } + + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR genType four_over_pi() + { + return genType(1.273239544735162686151070106980114898); + } + + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR genType two_over_root_pi() + { + return genType(1.12837916709551257389615890312154517); + } + + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR genType one_over_root_two() + { + return genType(0.707106781186547524400844362104849039); + } + + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR genType root_half_pi() + { + return genType(1.253314137315500251); + } + + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR genType root_two_pi() + { + return genType(2.506628274631000502); + } + + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR genType root_ln_four() + { + return genType(1.17741002251547469); + } + + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR genType e() + { + return genType(2.71828182845904523536); + } + + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR genType euler() + { + return genType(0.577215664901532860606); + } + + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR genType root_two() + { + return genType(1.41421356237309504880168872420969808); + } + + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR genType root_three() + { + return genType(1.73205080756887729352744634150587236); + } + + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR genType root_five() + { + return genType(2.23606797749978969640917366873127623); + } + + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR genType ln_two() + { + return genType(0.693147180559945309417232121458176568); + } + + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR genType ln_ten() + { + return genType(2.30258509299404568401799145468436421); + } + + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR genType ln_ln_two() + { + return genType(-0.3665129205816643); + } + + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR genType third() + { + return genType(0.3333333333333333333333333333333333333333); + } + + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR genType two_thirds() + { + return genType(0.666666666666666666666666666666666666667); + } + + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR genType golden_ratio() + { + return genType(1.61803398874989484820458683436563811); + } +} //namespace glm diff --git a/external/include/glm/gtc/epsilon.hpp b/external/include/glm/gtc/epsilon.hpp new file mode 100644 index 0000000..289f5b7 --- /dev/null +++ b/external/include/glm/gtc/epsilon.hpp @@ -0,0 +1,73 @@ +/// @ref gtc_epsilon +/// @file glm/gtc/epsilon.hpp +/// +/// @see core (dependence) +/// @see gtc_half_float (dependence) +/// @see gtc_quaternion (dependence) +/// +/// @defgroup gtc_epsilon GLM_GTC_epsilon +/// @ingroup gtc +/// +/// @brief Comparison functions for a user defined epsilon values. +/// +/// need to be included to use these functionalities. + +#pragma once + +// Dependencies +#include "../detail/setup.hpp" +#include "../detail/precision.hpp" + +#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED) +# pragma message("GLM: GLM_GTC_epsilon extension included") +#endif + +namespace glm +{ + /// @addtogroup gtc_epsilon + /// @{ + + /// Returns the component-wise comparison of |x - y| < epsilon. + /// True if this expression is satisfied. + /// + /// @see gtc_epsilon + template class vecType> + GLM_FUNC_DECL vecType epsilonEqual( + vecType const & x, + vecType const & y, + T const & epsilon); + + /// Returns the component-wise comparison of |x - y| < epsilon. + /// True if this expression is satisfied. + /// + /// @see gtc_epsilon + template + GLM_FUNC_DECL bool epsilonEqual( + genType const & x, + genType const & y, + genType const & epsilon); + + /// Returns the component-wise comparison of |x - y| < epsilon. + /// True if this expression is not satisfied. + /// + /// @see gtc_epsilon + template + GLM_FUNC_DECL typename genType::boolType epsilonNotEqual( + genType const & x, + genType const & y, + typename genType::value_type const & epsilon); + + /// Returns the component-wise comparison of |x - y| >= epsilon. + /// True if this expression is not satisfied. + /// + /// @see gtc_epsilon + template + GLM_FUNC_DECL bool epsilonNotEqual( + genType const & x, + genType const & y, + genType const & epsilon); + + /// @} +}//namespace glm + +#include "epsilon.inl" diff --git a/external/include/glm/gtc/epsilon.inl b/external/include/glm/gtc/epsilon.inl new file mode 100644 index 0000000..b5577d9 --- /dev/null +++ b/external/include/glm/gtc/epsilon.inl @@ -0,0 +1,125 @@ +/// @ref gtc_epsilon +/// @file glm/gtc/epsilon.inl + +// Dependency: +#include "quaternion.hpp" +#include "../vector_relational.hpp" +#include "../common.hpp" +#include "../vec2.hpp" +#include "../vec3.hpp" +#include "../vec4.hpp" + +namespace glm +{ + template <> + GLM_FUNC_QUALIFIER bool epsilonEqual + ( + float const & x, + float const & y, + float const & epsilon + ) + { + return abs(x - y) < epsilon; + } + + template <> + GLM_FUNC_QUALIFIER bool epsilonEqual + ( + double const & x, + double const & y, + double const & epsilon + ) + { + return abs(x - y) < epsilon; + } + + template <> + GLM_FUNC_QUALIFIER bool epsilonNotEqual + ( + float const & x, + float const & y, + float const & epsilon + ) + { + return abs(x - y) >= epsilon; + } + + template <> + GLM_FUNC_QUALIFIER bool epsilonNotEqual + ( + double const & x, + double const & y, + double const & epsilon + ) + { + return abs(x - y) >= epsilon; + } + + template class vecType> + GLM_FUNC_QUALIFIER vecType epsilonEqual + ( + vecType const & x, + vecType const & y, + T const & epsilon + ) + { + return lessThan(abs(x - y), vecType(epsilon)); + } + + template class vecType> + GLM_FUNC_QUALIFIER vecType epsilonEqual + ( + vecType const & x, + vecType const & y, + vecType const & epsilon + ) + { + return lessThan(abs(x - y), vecType(epsilon)); + } + + template class vecType> + GLM_FUNC_QUALIFIER vecType epsilonNotEqual + ( + vecType const & x, + vecType const & y, + T const & epsilon + ) + { + return greaterThanEqual(abs(x - y), vecType(epsilon)); + } + + template class vecType> + GLM_FUNC_QUALIFIER vecType epsilonNotEqual + ( + vecType const & x, + vecType const & y, + vecType const & epsilon + ) + { + return greaterThanEqual(abs(x - y), vecType(epsilon)); + } + + template + GLM_FUNC_QUALIFIER tvec4 epsilonEqual + ( + tquat const & x, + tquat const & y, + T const & epsilon + ) + { + tvec4 v(x.x - y.x, x.y - y.y, x.z - y.z, x.w - y.w); + return lessThan(abs(v), tvec4(epsilon)); + } + + template + GLM_FUNC_QUALIFIER tvec4 epsilonNotEqual + ( + tquat const & x, + tquat const & y, + T const & epsilon + ) + { + tvec4 v(x.x - y.x, x.y - y.y, x.z - y.z, x.w - y.w); + return greaterThanEqual(abs(v), tvec4(epsilon)); + } +}//namespace glm diff --git a/external/include/glm/gtc/functions.hpp b/external/include/glm/gtc/functions.hpp new file mode 100644 index 0000000..ab1590b --- /dev/null +++ b/external/include/glm/gtc/functions.hpp @@ -0,0 +1,53 @@ +/// @ref gtc_functions +/// @file glm/gtc/functions.hpp +/// +/// @see core (dependence) +/// @see gtc_half_float (dependence) +/// @see gtc_quaternion (dependence) +/// +/// @defgroup gtc_functions GLM_GTC_functions +/// @ingroup gtc +/// +/// @brief List of useful common functions. +/// +/// need to be included to use these functionalities. + +#pragma once + +// Dependencies +#include "../detail/setup.hpp" +#include "../detail/precision.hpp" +#include "../detail/type_vec2.hpp" + +#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED) +# pragma message("GLM: GLM_GTC_functions extension included") +#endif + +namespace glm +{ + /// @addtogroup gtc_functions + /// @{ + + /// 1D gauss function + /// + /// @see gtc_epsilon + template + GLM_FUNC_DECL T gauss( + T x, + T ExpectedValue, + T StandardDeviation); + + /// 2D gauss function + /// + /// @see gtc_epsilon + template + GLM_FUNC_DECL T gauss( + tvec2 const& Coord, + tvec2 const& ExpectedValue, + tvec2 const& StandardDeviation); + + /// @} +}//namespace glm + +#include "functions.inl" + diff --git a/external/include/glm/gtc/functions.inl b/external/include/glm/gtc/functions.inl new file mode 100644 index 0000000..1dbc496 --- /dev/null +++ b/external/include/glm/gtc/functions.inl @@ -0,0 +1,31 @@ +/// @ref gtc_functions +/// @file glm/gtc/functions.inl + +#include "../detail/func_exponential.hpp" + +namespace glm +{ + template + GLM_FUNC_QUALIFIER T gauss + ( + T x, + T ExpectedValue, + T StandardDeviation + ) + { + return exp(-((x - ExpectedValue) * (x - ExpectedValue)) / (static_cast(2) * StandardDeviation * StandardDeviation)) / (StandardDeviation * sqrt(static_cast(6.28318530717958647692528676655900576))); + } + + template + GLM_FUNC_QUALIFIER T gauss + ( + tvec2 const& Coord, + tvec2 const& ExpectedValue, + tvec2 const& StandardDeviation + ) + { + tvec2 const Squared = ((Coord - ExpectedValue) * (Coord - ExpectedValue)) / (static_cast(2) * StandardDeviation * StandardDeviation); + return exp(-(Squared.x + Squared.y)); + } +}//namespace glm + diff --git a/external/include/glm/gtc/integer.hpp b/external/include/glm/gtc/integer.hpp new file mode 100644 index 0000000..69ffb1d --- /dev/null +++ b/external/include/glm/gtc/integer.hpp @@ -0,0 +1,102 @@ +/// @ref gtc_integer +/// @file glm/gtc/integer.hpp +/// +/// @see core (dependence) +/// @see gtc_integer (dependence) +/// +/// @defgroup gtc_integer GLM_GTC_integer +/// @ingroup gtc +/// +/// @brief Allow to perform bit operations on integer values +/// +/// need to be included to use these functionalities. + +#pragma once + +// Dependencies +#include "../detail/setup.hpp" +#include "../detail/precision.hpp" +#include "../detail/func_common.hpp" +#include "../detail/func_integer.hpp" +#include "../detail/func_exponential.hpp" +#include + +#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED) +# pragma message("GLM: GLM_GTC_integer extension included") +#endif + +namespace glm +{ + /// @addtogroup gtc_integer + /// @{ + + /// Returns the log2 of x for integer values. Can be reliably using to compute mipmap count from the texture size. + /// @see gtc_integer + template + GLM_FUNC_DECL genIUType log2(genIUType x); + + /// Modulus. Returns x % y + /// for each component in x using the floating point value y. + /// + /// @tparam genIUType Integer-point scalar or vector types. + /// + /// @see gtc_integer + /// @see GLSL mod man page + /// @see GLSL 4.20.8 specification, section 8.3 Common Functions + template + GLM_FUNC_DECL genIUType mod(genIUType x, genIUType y); + + /// Modulus. Returns x % y + /// for each component in x using the floating point value y. + /// + /// @tparam T Integer scalar types. + /// @tparam vecType vector types. + /// + /// @see gtc_integer + /// @see GLSL mod man page + /// @see GLSL 4.20.8 specification, section 8.3 Common Functions + template class vecType> + GLM_FUNC_DECL vecType mod(vecType const & x, T y); + + /// Modulus. Returns x % y + /// for each component in x using the floating point value y. + /// + /// @tparam T Integer scalar types. + /// @tparam vecType vector types. + /// + /// @see gtc_integer + /// @see GLSL mod man page + /// @see GLSL 4.20.8 specification, section 8.3 Common Functions + template class vecType> + GLM_FUNC_DECL vecType mod(vecType const & x, vecType const & y); + + /// Returns a value equal to the nearest integer to x. + /// The fraction 0.5 will round in a direction chosen by the + /// implementation, presumably the direction that is fastest. + /// + /// @param x The values of the argument must be greater or equal to zero. + /// @tparam T floating point scalar types. + /// @tparam vecType vector types. + /// + /// @see GLSL round man page + /// @see gtc_integer + template class vecType> + GLM_FUNC_DECL vecType iround(vecType const & x); + + /// Returns a value equal to the nearest integer to x. + /// The fraction 0.5 will round in a direction chosen by the + /// implementation, presumably the direction that is fastest. + /// + /// @param x The values of the argument must be greater or equal to zero. + /// @tparam T floating point scalar types. + /// @tparam vecType vector types. + /// + /// @see GLSL round man page + /// @see gtc_integer + template class vecType> + GLM_FUNC_DECL vecType uround(vecType const & x); + + /// @} +} //namespace glm + +#include "integer.inl" diff --git a/external/include/glm/gtc/integer.inl b/external/include/glm/gtc/integer.inl new file mode 100644 index 0000000..7ce2918 --- /dev/null +++ b/external/include/glm/gtc/integer.inl @@ -0,0 +1,71 @@ +/// @ref gtc_integer +/// @file glm/gtc/integer.inl + +namespace glm{ +namespace detail +{ + template class vecType, bool Aligned> + struct compute_log2 + { + GLM_FUNC_QUALIFIER static vecType call(vecType const & vec) + { + //Equivalent to return findMSB(vec); but save one function call in ASM with VC + //return findMSB(vec); + return vecType(detail::compute_findMSB_vec::call(vec)); + } + }; + +# if GLM_HAS_BITSCAN_WINDOWS + template + struct compute_log2 + { + GLM_FUNC_QUALIFIER static tvec4 call(tvec4 const & vec) + { + tvec4 Result(glm::uninitialize); + + _BitScanReverse(reinterpret_cast(&Result.x), vec.x); + _BitScanReverse(reinterpret_cast(&Result.y), vec.y); + _BitScanReverse(reinterpret_cast(&Result.z), vec.z); + _BitScanReverse(reinterpret_cast(&Result.w), vec.w); + + return Result; + } + }; +# endif//GLM_HAS_BITSCAN_WINDOWS +}//namespace detail + template + GLM_FUNC_QUALIFIER int iround(genType x) + { + GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'iround' only accept floating-point inputs"); + assert(static_cast(0.0) <= x); + + return static_cast(x + static_cast(0.5)); + } + + template class vecType> + GLM_FUNC_QUALIFIER vecType iround(vecType const& x) + { + GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'iround' only accept floating-point inputs"); + assert(all(lessThanEqual(vecType(0), x))); + + return vecType(x + static_cast(0.5)); + } + + template + GLM_FUNC_QUALIFIER uint uround(genType x) + { + GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'uround' only accept floating-point inputs"); + assert(static_cast(0.0) <= x); + + return static_cast(x + static_cast(0.5)); + } + + template class vecType> + GLM_FUNC_QUALIFIER vecType uround(vecType const& x) + { + GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'uround' only accept floating-point inputs"); + assert(all(lessThanEqual(vecType(0), x))); + + return vecType(x + static_cast(0.5)); + } +}//namespace glm diff --git a/external/include/glm/gtc/matrix_access.hpp b/external/include/glm/gtc/matrix_access.hpp new file mode 100644 index 0000000..e4156ef --- /dev/null +++ b/external/include/glm/gtc/matrix_access.hpp @@ -0,0 +1,59 @@ +/// @ref gtc_matrix_access +/// @file glm/gtc/matrix_access.hpp +/// +/// @see core (dependence) +/// +/// @defgroup gtc_matrix_access GLM_GTC_matrix_access +/// @ingroup gtc +/// +/// Defines functions to access rows or columns of a matrix easily. +/// need to be included to use these functionalities. + +#pragma once + +// Dependency: +#include "../detail/setup.hpp" + +#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED) +# pragma message("GLM: GLM_GTC_matrix_access extension included") +#endif + +namespace glm +{ + /// @addtogroup gtc_matrix_access + /// @{ + + /// Get a specific row of a matrix. + /// @see gtc_matrix_access + template + GLM_FUNC_DECL typename genType::row_type row( + genType const & m, + length_t index); + + /// Set a specific row to a matrix. + /// @see gtc_matrix_access + template + GLM_FUNC_DECL genType row( + genType const & m, + length_t index, + typename genType::row_type const & x); + + /// Get a specific column of a matrix. + /// @see gtc_matrix_access + template + GLM_FUNC_DECL typename genType::col_type column( + genType const & m, + length_t index); + + /// Set a specific column to a matrix. + /// @see gtc_matrix_access + template + GLM_FUNC_DECL genType column( + genType const & m, + length_t index, + typename genType::col_type const & x); + + /// @} +}//namespace glm + +#include "matrix_access.inl" diff --git a/external/include/glm/gtc/matrix_access.inl b/external/include/glm/gtc/matrix_access.inl new file mode 100644 index 0000000..831b940 --- /dev/null +++ b/external/include/glm/gtc/matrix_access.inl @@ -0,0 +1,63 @@ +/// @ref gtc_matrix_access +/// @file glm/gtc/matrix_access.inl + +namespace glm +{ + template + GLM_FUNC_QUALIFIER genType row + ( + genType const & m, + length_t index, + typename genType::row_type const & x + ) + { + assert(index >= 0 && index < m[0].length()); + + genType Result = m; + for(length_t i = 0; i < m.length(); ++i) + Result[i][index] = x[i]; + return Result; + } + + template + GLM_FUNC_QUALIFIER typename genType::row_type row + ( + genType const & m, + length_t index + ) + { + assert(index >= 0 && index < m[0].length()); + + typename genType::row_type Result; + for(length_t i = 0; i < m.length(); ++i) + Result[i] = m[i][index]; + return Result; + } + + template + GLM_FUNC_QUALIFIER genType column + ( + genType const & m, + length_t index, + typename genType::col_type const & x + ) + { + assert(index >= 0 && index < m.length()); + + genType Result = m; + Result[index] = x; + return Result; + } + + template + GLM_FUNC_QUALIFIER typename genType::col_type column + ( + genType const & m, + length_t index + ) + { + assert(index >= 0 && index < m.length()); + + return m[index]; + } +}//namespace glm diff --git a/external/include/glm/gtc/matrix_integer.hpp b/external/include/glm/gtc/matrix_integer.hpp new file mode 100644 index 0000000..fdc816d --- /dev/null +++ b/external/include/glm/gtc/matrix_integer.hpp @@ -0,0 +1,486 @@ +/// @ref gtc_matrix_integer +/// @file glm/gtc/matrix_integer.hpp +/// +/// @see core (dependence) +/// +/// @defgroup gtc_matrix_integer GLM_GTC_matrix_integer +/// @ingroup gtc +/// +/// Defines a number of matrices with integer types. +/// need to be included to use these functionalities. + +#pragma once + +// Dependency: +#include "../mat2x2.hpp" +#include "../mat2x3.hpp" +#include "../mat2x4.hpp" +#include "../mat3x2.hpp" +#include "../mat3x3.hpp" +#include "../mat3x4.hpp" +#include "../mat4x2.hpp" +#include "../mat4x3.hpp" +#include "../mat4x4.hpp" + +#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED) +# pragma message("GLM: GLM_GTC_matrix_integer extension included") +#endif + +namespace glm +{ + /// @addtogroup gtc_matrix_integer + /// @{ + + /// High-precision signed integer 2x2 matrix. + /// @see gtc_matrix_integer + typedef tmat2x2 highp_imat2; + + /// High-precision signed integer 3x3 matrix. + /// @see gtc_matrix_integer + typedef tmat3x3 highp_imat3; + + /// High-precision signed integer 4x4 matrix. + /// @see gtc_matrix_integer + typedef tmat4x4 highp_imat4; + + /// High-precision signed integer 2x2 matrix. + /// @see gtc_matrix_integer + typedef tmat2x2 highp_imat2x2; + + /// High-precision signed integer 2x3 matrix. + /// @see gtc_matrix_integer + typedef tmat2x3 highp_imat2x3; + + /// High-precision signed integer 2x4 matrix. + /// @see gtc_matrix_integer + typedef tmat2x4 highp_imat2x4; + + /// High-precision signed integer 3x2 matrix. + /// @see gtc_matrix_integer + typedef tmat3x2 highp_imat3x2; + + /// High-precision signed integer 3x3 matrix. + /// @see gtc_matrix_integer + typedef tmat3x3 highp_imat3x3; + + /// High-precision signed integer 3x4 matrix. + /// @see gtc_matrix_integer + typedef tmat3x4 highp_imat3x4; + + /// High-precision signed integer 4x2 matrix. + /// @see gtc_matrix_integer + typedef tmat4x2 highp_imat4x2; + + /// High-precision signed integer 4x3 matrix. + /// @see gtc_matrix_integer + typedef tmat4x3 highp_imat4x3; + + /// High-precision signed integer 4x4 matrix. + /// @see gtc_matrix_integer + typedef tmat4x4 highp_imat4x4; + + + /// Medium-precision signed integer 2x2 matrix. + /// @see gtc_matrix_integer + typedef tmat2x2 mediump_imat2; + + /// Medium-precision signed integer 3x3 matrix. + /// @see gtc_matrix_integer + typedef tmat3x3 mediump_imat3; + + /// Medium-precision signed integer 4x4 matrix. + /// @see gtc_matrix_integer + typedef tmat4x4 mediump_imat4; + + + /// Medium-precision signed integer 2x2 matrix. + /// @see gtc_matrix_integer + typedef tmat2x2 mediump_imat2x2; + + /// Medium-precision signed integer 2x3 matrix. + /// @see gtc_matrix_integer + typedef tmat2x3 mediump_imat2x3; + + /// Medium-precision signed integer 2x4 matrix. + /// @see gtc_matrix_integer + typedef tmat2x4 mediump_imat2x4; + + /// Medium-precision signed integer 3x2 matrix. + /// @see gtc_matrix_integer + typedef tmat3x2 mediump_imat3x2; + + /// Medium-precision signed integer 3x3 matrix. + /// @see gtc_matrix_integer + typedef tmat3x3 mediump_imat3x3; + + /// Medium-precision signed integer 3x4 matrix. + /// @see gtc_matrix_integer + typedef tmat3x4 mediump_imat3x4; + + /// Medium-precision signed integer 4x2 matrix. + /// @see gtc_matrix_integer + typedef tmat4x2 mediump_imat4x2; + + /// Medium-precision signed integer 4x3 matrix. + /// @see gtc_matrix_integer + typedef tmat4x3 mediump_imat4x3; + + /// Medium-precision signed integer 4x4 matrix. + /// @see gtc_matrix_integer + typedef tmat4x4 mediump_imat4x4; + + + /// Low-precision signed integer 2x2 matrix. + /// @see gtc_matrix_integer + typedef tmat2x2 lowp_imat2; + + /// Low-precision signed integer 3x3 matrix. + /// @see gtc_matrix_integer + typedef tmat3x3 lowp_imat3; + + /// Low-precision signed integer 4x4 matrix. + /// @see gtc_matrix_integer + typedef tmat4x4 lowp_imat4; + + + /// Low-precision signed integer 2x2 matrix. + /// @see gtc_matrix_integer + typedef tmat2x2 lowp_imat2x2; + + /// Low-precision signed integer 2x3 matrix. + /// @see gtc_matrix_integer + typedef tmat2x3 lowp_imat2x3; + + /// Low-precision signed integer 2x4 matrix. + /// @see gtc_matrix_integer + typedef tmat2x4 lowp_imat2x4; + + /// Low-precision signed integer 3x2 matrix. + /// @see gtc_matrix_integer + typedef tmat3x2 lowp_imat3x2; + + /// Low-precision signed integer 3x3 matrix. + /// @see gtc_matrix_integer + typedef tmat3x3 lowp_imat3x3; + + /// Low-precision signed integer 3x4 matrix. + /// @see gtc_matrix_integer + typedef tmat3x4 lowp_imat3x4; + + /// Low-precision signed integer 4x2 matrix. + /// @see gtc_matrix_integer + typedef tmat4x2 lowp_imat4x2; + + /// Low-precision signed integer 4x3 matrix. + /// @see gtc_matrix_integer + typedef tmat4x3 lowp_imat4x3; + + /// Low-precision signed integer 4x4 matrix. + /// @see gtc_matrix_integer + typedef tmat4x4 lowp_imat4x4; + + + /// High-precision unsigned integer 2x2 matrix. + /// @see gtc_matrix_integer + typedef tmat2x2 highp_umat2; + + /// High-precision unsigned integer 3x3 matrix. + /// @see gtc_matrix_integer + typedef tmat3x3 highp_umat3; + + /// High-precision unsigned integer 4x4 matrix. + /// @see gtc_matrix_integer + typedef tmat4x4 highp_umat4; + + /// High-precision unsigned integer 2x2 matrix. + /// @see gtc_matrix_integer + typedef tmat2x2 highp_umat2x2; + + /// High-precision unsigned integer 2x3 matrix. + /// @see gtc_matrix_integer + typedef tmat2x3 highp_umat2x3; + + /// High-precision unsigned integer 2x4 matrix. + /// @see gtc_matrix_integer + typedef tmat2x4 highp_umat2x4; + + /// High-precision unsigned integer 3x2 matrix. + /// @see gtc_matrix_integer + typedef tmat3x2 highp_umat3x2; + + /// High-precision unsigned integer 3x3 matrix. + /// @see gtc_matrix_integer + typedef tmat3x3 highp_umat3x3; + + /// High-precision unsigned integer 3x4 matrix. + /// @see gtc_matrix_integer + typedef tmat3x4 highp_umat3x4; + + /// High-precision unsigned integer 4x2 matrix. + /// @see gtc_matrix_integer + typedef tmat4x2 highp_umat4x2; + + /// High-precision unsigned integer 4x3 matrix. + /// @see gtc_matrix_integer + typedef tmat4x3 highp_umat4x3; + + /// High-precision unsigned integer 4x4 matrix. + /// @see gtc_matrix_integer + typedef tmat4x4 highp_umat4x4; + + + /// Medium-precision unsigned integer 2x2 matrix. + /// @see gtc_matrix_integer + typedef tmat2x2 mediump_umat2; + + /// Medium-precision unsigned integer 3x3 matrix. + /// @see gtc_matrix_integer + typedef tmat3x3 mediump_umat3; + + /// Medium-precision unsigned integer 4x4 matrix. + /// @see gtc_matrix_integer + typedef tmat4x4 mediump_umat4; + + + /// Medium-precision unsigned integer 2x2 matrix. + /// @see gtc_matrix_integer + typedef tmat2x2 mediump_umat2x2; + + /// Medium-precision unsigned integer 2x3 matrix. + /// @see gtc_matrix_integer + typedef tmat2x3 mediump_umat2x3; + + /// Medium-precision unsigned integer 2x4 matrix. + /// @see gtc_matrix_integer + typedef tmat2x4 mediump_umat2x4; + + /// Medium-precision unsigned integer 3x2 matrix. + /// @see gtc_matrix_integer + typedef tmat3x2 mediump_umat3x2; + + /// Medium-precision unsigned integer 3x3 matrix. + /// @see gtc_matrix_integer + typedef tmat3x3 mediump_umat3x3; + + /// Medium-precision unsigned integer 3x4 matrix. + /// @see gtc_matrix_integer + typedef tmat3x4 mediump_umat3x4; + + /// Medium-precision unsigned integer 4x2 matrix. + /// @see gtc_matrix_integer + typedef tmat4x2 mediump_umat4x2; + + /// Medium-precision unsigned integer 4x3 matrix. + /// @see gtc_matrix_integer + typedef tmat4x3 mediump_umat4x3; + + /// Medium-precision unsigned integer 4x4 matrix. + /// @see gtc_matrix_integer + typedef tmat4x4 mediump_umat4x4; + + + /// Low-precision unsigned integer 2x2 matrix. + /// @see gtc_matrix_integer + typedef tmat2x2 lowp_umat2; + + /// Low-precision unsigned integer 3x3 matrix. + /// @see gtc_matrix_integer + typedef tmat3x3 lowp_umat3; + + /// Low-precision unsigned integer 4x4 matrix. + /// @see gtc_matrix_integer + typedef tmat4x4 lowp_umat4; + + + /// Low-precision unsigned integer 2x2 matrix. + /// @see gtc_matrix_integer + typedef tmat2x2 lowp_umat2x2; + + /// Low-precision unsigned integer 2x3 matrix. + /// @see gtc_matrix_integer + typedef tmat2x3 lowp_umat2x3; + + /// Low-precision unsigned integer 2x4 matrix. + /// @see gtc_matrix_integer + typedef tmat2x4 lowp_umat2x4; + + /// Low-precision unsigned integer 3x2 matrix. + /// @see gtc_matrix_integer + typedef tmat3x2 lowp_umat3x2; + + /// Low-precision unsigned integer 3x3 matrix. + /// @see gtc_matrix_integer + typedef tmat3x3 lowp_umat3x3; + + /// Low-precision unsigned integer 3x4 matrix. + /// @see gtc_matrix_integer + typedef tmat3x4 lowp_umat3x4; + + /// Low-precision unsigned integer 4x2 matrix. + /// @see gtc_matrix_integer + typedef tmat4x2 lowp_umat4x2; + + /// Low-precision unsigned integer 4x3 matrix. + /// @see gtc_matrix_integer + typedef tmat4x3 lowp_umat4x3; + + /// Low-precision unsigned integer 4x4 matrix. + /// @see gtc_matrix_integer + typedef tmat4x4 lowp_umat4x4; + +#if(defined(GLM_PRECISION_HIGHP_INT)) + typedef highp_imat2 imat2; + typedef highp_imat3 imat3; + typedef highp_imat4 imat4; + typedef highp_imat2x2 imat2x2; + typedef highp_imat2x3 imat2x3; + typedef highp_imat2x4 imat2x4; + typedef highp_imat3x2 imat3x2; + typedef highp_imat3x3 imat3x3; + typedef highp_imat3x4 imat3x4; + typedef highp_imat4x2 imat4x2; + typedef highp_imat4x3 imat4x3; + typedef highp_imat4x4 imat4x4; +#elif(defined(GLM_PRECISION_LOWP_INT)) + typedef lowp_imat2 imat2; + typedef lowp_imat3 imat3; + typedef lowp_imat4 imat4; + typedef lowp_imat2x2 imat2x2; + typedef lowp_imat2x3 imat2x3; + typedef lowp_imat2x4 imat2x4; + typedef lowp_imat3x2 imat3x2; + typedef lowp_imat3x3 imat3x3; + typedef lowp_imat3x4 imat3x4; + typedef lowp_imat4x2 imat4x2; + typedef lowp_imat4x3 imat4x3; + typedef lowp_imat4x4 imat4x4; +#else //if(defined(GLM_PRECISION_MEDIUMP_INT)) + + /// Signed integer 2x2 matrix. + /// @see gtc_matrix_integer + typedef mediump_imat2 imat2; + + /// Signed integer 3x3 matrix. + /// @see gtc_matrix_integer + typedef mediump_imat3 imat3; + + /// Signed integer 4x4 matrix. + /// @see gtc_matrix_integer + typedef mediump_imat4 imat4; + + /// Signed integer 2x2 matrix. + /// @see gtc_matrix_integer + typedef mediump_imat2x2 imat2x2; + + /// Signed integer 2x3 matrix. + /// @see gtc_matrix_integer + typedef mediump_imat2x3 imat2x3; + + /// Signed integer 2x4 matrix. + /// @see gtc_matrix_integer + typedef mediump_imat2x4 imat2x4; + + /// Signed integer 3x2 matrix. + /// @see gtc_matrix_integer + typedef mediump_imat3x2 imat3x2; + + /// Signed integer 3x3 matrix. + /// @see gtc_matrix_integer + typedef mediump_imat3x3 imat3x3; + + /// Signed integer 3x4 matrix. + /// @see gtc_matrix_integer + typedef mediump_imat3x4 imat3x4; + + /// Signed integer 4x2 matrix. + /// @see gtc_matrix_integer + typedef mediump_imat4x2 imat4x2; + + /// Signed integer 4x3 matrix. + /// @see gtc_matrix_integer + typedef mediump_imat4x3 imat4x3; + + /// Signed integer 4x4 matrix. + /// @see gtc_matrix_integer + typedef mediump_imat4x4 imat4x4; +#endif//GLM_PRECISION + +#if(defined(GLM_PRECISION_HIGHP_UINT)) + typedef highp_umat2 umat2; + typedef highp_umat3 umat3; + typedef highp_umat4 umat4; + typedef highp_umat2x2 umat2x2; + typedef highp_umat2x3 umat2x3; + typedef highp_umat2x4 umat2x4; + typedef highp_umat3x2 umat3x2; + typedef highp_umat3x3 umat3x3; + typedef highp_umat3x4 umat3x4; + typedef highp_umat4x2 umat4x2; + typedef highp_umat4x3 umat4x3; + typedef highp_umat4x4 umat4x4; +#elif(defined(GLM_PRECISION_LOWP_UINT)) + typedef lowp_umat2 umat2; + typedef lowp_umat3 umat3; + typedef lowp_umat4 umat4; + typedef lowp_umat2x2 umat2x2; + typedef lowp_umat2x3 umat2x3; + typedef lowp_umat2x4 umat2x4; + typedef lowp_umat3x2 umat3x2; + typedef lowp_umat3x3 umat3x3; + typedef lowp_umat3x4 umat3x4; + typedef lowp_umat4x2 umat4x2; + typedef lowp_umat4x3 umat4x3; + typedef lowp_umat4x4 umat4x4; +#else //if(defined(GLM_PRECISION_MEDIUMP_UINT)) + + /// Unsigned integer 2x2 matrix. + /// @see gtc_matrix_integer + typedef mediump_umat2 umat2; + + /// Unsigned integer 3x3 matrix. + /// @see gtc_matrix_integer + typedef mediump_umat3 umat3; + + /// Unsigned integer 4x4 matrix. + /// @see gtc_matrix_integer + typedef mediump_umat4 umat4; + + /// Unsigned integer 2x2 matrix. + /// @see gtc_matrix_integer + typedef mediump_umat2x2 umat2x2; + + /// Unsigned integer 2x3 matrix. + /// @see gtc_matrix_integer + typedef mediump_umat2x3 umat2x3; + + /// Unsigned integer 2x4 matrix. + /// @see gtc_matrix_integer + typedef mediump_umat2x4 umat2x4; + + /// Unsigned integer 3x2 matrix. + /// @see gtc_matrix_integer + typedef mediump_umat3x2 umat3x2; + + /// Unsigned integer 3x3 matrix. + /// @see gtc_matrix_integer + typedef mediump_umat3x3 umat3x3; + + /// Unsigned integer 3x4 matrix. + /// @see gtc_matrix_integer + typedef mediump_umat3x4 umat3x4; + + /// Unsigned integer 4x2 matrix. + /// @see gtc_matrix_integer + typedef mediump_umat4x2 umat4x2; + + /// Unsigned integer 4x3 matrix. + /// @see gtc_matrix_integer + typedef mediump_umat4x3 umat4x3; + + /// Unsigned integer 4x4 matrix. + /// @see gtc_matrix_integer + typedef mediump_umat4x4 umat4x4; +#endif//GLM_PRECISION + + /// @} +}//namespace glm diff --git a/external/include/glm/gtc/matrix_inverse.hpp b/external/include/glm/gtc/matrix_inverse.hpp new file mode 100644 index 0000000..589381d --- /dev/null +++ b/external/include/glm/gtc/matrix_inverse.hpp @@ -0,0 +1,49 @@ +/// @ref gtc_matrix_inverse +/// @file glm/gtc/matrix_inverse.hpp +/// +/// @see core (dependence) +/// +/// @defgroup gtc_matrix_inverse GLM_GTC_matrix_inverse +/// @ingroup gtc +/// +/// Defines additional matrix inverting functions. +/// need to be included to use these functionalities. + +#pragma once + +// Dependencies +#include "../detail/setup.hpp" +#include "../matrix.hpp" +#include "../mat2x2.hpp" +#include "../mat3x3.hpp" +#include "../mat4x4.hpp" + +#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED) +# pragma message("GLM: GLM_GTC_matrix_inverse extension included") +#endif + +namespace glm +{ + /// @addtogroup gtc_matrix_inverse + /// @{ + + /// Fast matrix inverse for affine matrix. + /// + /// @param m Input matrix to invert. + /// @tparam genType Squared floating-point matrix: half, float or double. Inverse of matrix based of half-precision floating point value is highly innacurate. + /// @see gtc_matrix_inverse + template + GLM_FUNC_DECL genType affineInverse(genType const & m); + + /// Compute the inverse transpose of a matrix. + /// + /// @param m Input matrix to invert transpose. + /// @tparam genType Squared floating-point matrix: half, float or double. Inverse of matrix based of half-precision floating point value is highly innacurate. + /// @see gtc_matrix_inverse + template + GLM_FUNC_DECL genType inverseTranspose(genType const & m); + + /// @} +}//namespace glm + +#include "matrix_inverse.inl" diff --git a/external/include/glm/gtc/matrix_inverse.inl b/external/include/glm/gtc/matrix_inverse.inl new file mode 100644 index 0000000..36c9bf7 --- /dev/null +++ b/external/include/glm/gtc/matrix_inverse.inl @@ -0,0 +1,120 @@ +/// @ref gtc_matrix_inverse +/// @file glm/gtc/matrix_inverse.inl + +namespace glm +{ + template + GLM_FUNC_QUALIFIER tmat3x3 affineInverse(tmat3x3 const & m) + { + tmat2x2 const Inv(inverse(tmat2x2(m))); + + return tmat3x3( + tvec3(Inv[0], static_cast(0)), + tvec3(Inv[1], static_cast(0)), + tvec3(-Inv * tvec2(m[2]), static_cast(1))); + } + + template + GLM_FUNC_QUALIFIER tmat4x4 affineInverse(tmat4x4 const & m) + { + tmat3x3 const Inv(inverse(tmat3x3(m))); + + return tmat4x4( + tvec4(Inv[0], static_cast(0)), + tvec4(Inv[1], static_cast(0)), + tvec4(Inv[2], static_cast(0)), + tvec4(-Inv * tvec3(m[3]), static_cast(1))); + } + + template + GLM_FUNC_QUALIFIER tmat2x2 inverseTranspose(tmat2x2 const & m) + { + T Determinant = m[0][0] * m[1][1] - m[1][0] * m[0][1]; + + tmat2x2 Inverse( + + m[1][1] / Determinant, + - m[0][1] / Determinant, + - m[1][0] / Determinant, + + m[0][0] / Determinant); + + return Inverse; + } + + template + GLM_FUNC_QUALIFIER tmat3x3 inverseTranspose(tmat3x3 const & m) + { + T Determinant = + + m[0][0] * (m[1][1] * m[2][2] - m[1][2] * m[2][1]) + - m[0][1] * (m[1][0] * m[2][2] - m[1][2] * m[2][0]) + + m[0][2] * (m[1][0] * m[2][1] - m[1][1] * m[2][0]); + + tmat3x3 Inverse(uninitialize); + Inverse[0][0] = + (m[1][1] * m[2][2] - m[2][1] * m[1][2]); + Inverse[0][1] = - (m[1][0] * m[2][2] - m[2][0] * m[1][2]); + Inverse[0][2] = + (m[1][0] * m[2][1] - m[2][0] * m[1][1]); + Inverse[1][0] = - (m[0][1] * m[2][2] - m[2][1] * m[0][2]); + Inverse[1][1] = + (m[0][0] * m[2][2] - m[2][0] * m[0][2]); + Inverse[1][2] = - (m[0][0] * m[2][1] - m[2][0] * m[0][1]); + Inverse[2][0] = + (m[0][1] * m[1][2] - m[1][1] * m[0][2]); + Inverse[2][1] = - (m[0][0] * m[1][2] - m[1][0] * m[0][2]); + Inverse[2][2] = + (m[0][0] * m[1][1] - m[1][0] * m[0][1]); + Inverse /= Determinant; + + return Inverse; + } + + template + GLM_FUNC_QUALIFIER tmat4x4 inverseTranspose(tmat4x4 const & m) + { + T SubFactor00 = m[2][2] * m[3][3] - m[3][2] * m[2][3]; + T SubFactor01 = m[2][1] * m[3][3] - m[3][1] * m[2][3]; + T SubFactor02 = m[2][1] * m[3][2] - m[3][1] * m[2][2]; + T SubFactor03 = m[2][0] * m[3][3] - m[3][0] * m[2][3]; + T SubFactor04 = m[2][0] * m[3][2] - m[3][0] * m[2][2]; + T SubFactor05 = m[2][0] * m[3][1] - m[3][0] * m[2][1]; + T SubFactor06 = m[1][2] * m[3][3] - m[3][2] * m[1][3]; + T SubFactor07 = m[1][1] * m[3][3] - m[3][1] * m[1][3]; + T SubFactor08 = m[1][1] * m[3][2] - m[3][1] * m[1][2]; + T SubFactor09 = m[1][0] * m[3][3] - m[3][0] * m[1][3]; + T SubFactor10 = m[1][0] * m[3][2] - m[3][0] * m[1][2]; + T SubFactor11 = m[1][1] * m[3][3] - m[3][1] * m[1][3]; + T SubFactor12 = m[1][0] * m[3][1] - m[3][0] * m[1][1]; + T SubFactor13 = m[1][2] * m[2][3] - m[2][2] * m[1][3]; + T SubFactor14 = m[1][1] * m[2][3] - m[2][1] * m[1][3]; + T SubFactor15 = m[1][1] * m[2][2] - m[2][1] * m[1][2]; + T SubFactor16 = m[1][0] * m[2][3] - m[2][0] * m[1][3]; + T SubFactor17 = m[1][0] * m[2][2] - m[2][0] * m[1][2]; + T SubFactor18 = m[1][0] * m[2][1] - m[2][0] * m[1][1]; + + tmat4x4 Inverse(uninitialize); + Inverse[0][0] = + (m[1][1] * SubFactor00 - m[1][2] * SubFactor01 + m[1][3] * SubFactor02); + Inverse[0][1] = - (m[1][0] * SubFactor00 - m[1][2] * SubFactor03 + m[1][3] * SubFactor04); + Inverse[0][2] = + (m[1][0] * SubFactor01 - m[1][1] * SubFactor03 + m[1][3] * SubFactor05); + Inverse[0][3] = - (m[1][0] * SubFactor02 - m[1][1] * SubFactor04 + m[1][2] * SubFactor05); + + Inverse[1][0] = - (m[0][1] * SubFactor00 - m[0][2] * SubFactor01 + m[0][3] * SubFactor02); + Inverse[1][1] = + (m[0][0] * SubFactor00 - m[0][2] * SubFactor03 + m[0][3] * SubFactor04); + Inverse[1][2] = - (m[0][0] * SubFactor01 - m[0][1] * SubFactor03 + m[0][3] * SubFactor05); + Inverse[1][3] = + (m[0][0] * SubFactor02 - m[0][1] * SubFactor04 + m[0][2] * SubFactor05); + + Inverse[2][0] = + (m[0][1] * SubFactor06 - m[0][2] * SubFactor07 + m[0][3] * SubFactor08); + Inverse[2][1] = - (m[0][0] * SubFactor06 - m[0][2] * SubFactor09 + m[0][3] * SubFactor10); + Inverse[2][2] = + (m[0][0] * SubFactor11 - m[0][1] * SubFactor09 + m[0][3] * SubFactor12); + Inverse[2][3] = - (m[0][0] * SubFactor08 - m[0][1] * SubFactor10 + m[0][2] * SubFactor12); + + Inverse[3][0] = - (m[0][1] * SubFactor13 - m[0][2] * SubFactor14 + m[0][3] * SubFactor15); + Inverse[3][1] = + (m[0][0] * SubFactor13 - m[0][2] * SubFactor16 + m[0][3] * SubFactor17); + Inverse[3][2] = - (m[0][0] * SubFactor14 - m[0][1] * SubFactor16 + m[0][3] * SubFactor18); + Inverse[3][3] = + (m[0][0] * SubFactor15 - m[0][1] * SubFactor17 + m[0][2] * SubFactor18); + + T Determinant = + + m[0][0] * Inverse[0][0] + + m[0][1] * Inverse[0][1] + + m[0][2] * Inverse[0][2] + + m[0][3] * Inverse[0][3]; + + Inverse /= Determinant; + + return Inverse; + } +}//namespace glm diff --git a/external/include/glm/gtc/matrix_transform.hpp b/external/include/glm/gtc/matrix_transform.hpp new file mode 100644 index 0000000..c97b89a --- /dev/null +++ b/external/include/glm/gtc/matrix_transform.hpp @@ -0,0 +1,465 @@ +/// @ref gtc_matrix_transform +/// @file glm/gtc/matrix_transform.hpp +/// +/// @see core (dependence) +/// @see gtx_transform +/// @see gtx_transform2 +/// +/// @defgroup gtc_matrix_transform GLM_GTC_matrix_transform +/// @ingroup gtc +/// +/// @brief Defines functions that generate common transformation matrices. +/// +/// The matrices generated by this extension use standard OpenGL fixed-function +/// conventions. For example, the lookAt function generates a transform from world +/// space into the specific eye space that the projective matrix functions +/// (perspective, ortho, etc) are designed to expect. The OpenGL compatibility +/// specifications defines the particular layout of this eye space. +/// +/// need to be included to use these functionalities. + +#pragma once + +// Dependencies +#include "../mat4x4.hpp" +#include "../vec2.hpp" +#include "../vec3.hpp" +#include "../vec4.hpp" +#include "../gtc/constants.hpp" + +#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED) +# pragma message("GLM: GLM_GTC_matrix_transform extension included") +#endif + +namespace glm +{ + /// @addtogroup gtc_matrix_transform + /// @{ + + /// Builds a translation 4 * 4 matrix created from a vector of 3 components. + /// + /// @param m Input matrix multiplied by this translation matrix. + /// @param v Coordinates of a translation vector. + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommanded), float or double. + /// @code + /// #include + /// #include + /// ... + /// glm::mat4 m = glm::translate(glm::mat4(1.0f), glm::vec3(1.0f)); + /// // m[0][0] == 1.0f, m[0][1] == 0.0f, m[0][2] == 0.0f, m[0][3] == 0.0f + /// // m[1][0] == 0.0f, m[1][1] == 1.0f, m[1][2] == 0.0f, m[1][3] == 0.0f + /// // m[2][0] == 0.0f, m[2][1] == 0.0f, m[2][2] == 1.0f, m[2][3] == 0.0f + /// // m[3][0] == 1.0f, m[3][1] == 1.0f, m[3][2] == 1.0f, m[3][3] == 1.0f + /// @endcode + /// @see gtc_matrix_transform + /// @see - translate(tmat4x4 const & m, T x, T y, T z) + /// @see - translate(tvec3 const & v) + template + GLM_FUNC_DECL tmat4x4 translate( + tmat4x4 const & m, + tvec3 const & v); + + /// Builds a rotation 4 * 4 matrix created from an axis vector and an angle. + /// + /// @param m Input matrix multiplied by this rotation matrix. + /// @param angle Rotation angle expressed in radians. + /// @param axis Rotation axis, recommended to be normalized. + /// @tparam T Value type used to build the matrix. Supported: half, float or double. + /// @see gtc_matrix_transform + /// @see - rotate(tmat4x4 const & m, T angle, T x, T y, T z) + /// @see - rotate(T angle, tvec3 const & v) + template + GLM_FUNC_DECL tmat4x4 rotate( + tmat4x4 const & m, + T angle, + tvec3 const & axis); + + /// Builds a scale 4 * 4 matrix created from 3 scalars. + /// + /// @param m Input matrix multiplied by this scale matrix. + /// @param v Ratio of scaling for each axis. + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommanded), float or double. + /// @see gtc_matrix_transform + /// @see - scale(tmat4x4 const & m, T x, T y, T z) + /// @see - scale(tvec3 const & v) + template + GLM_FUNC_DECL tmat4x4 scale( + tmat4x4 const & m, + tvec3 const & v); + + /// Creates a matrix for an orthographic parallel viewing volume, using the default handedness. + /// + /// @param left + /// @param right + /// @param bottom + /// @param top + /// @param zNear + /// @param zFar + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommanded), float or double. + /// @see gtc_matrix_transform + /// @see - glm::ortho(T const & left, T const & right, T const & bottom, T const & top) + template + GLM_FUNC_DECL tmat4x4 ortho( + T left, + T right, + T bottom, + T top, + T zNear, + T zFar); + + /// Creates a matrix for an orthographic parallel viewing volume, using left-handedness. + /// + /// @param left + /// @param right + /// @param bottom + /// @param top + /// @param zNear + /// @param zFar + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommanded), float or double. + /// @see gtc_matrix_transform + /// @see - glm::ortho(T const & left, T const & right, T const & bottom, T const & top) + template + GLM_FUNC_DECL tmat4x4 orthoLH( + T left, + T right, + T bottom, + T top, + T zNear, + T zFar); + + /// Creates a matrix for an orthographic parallel viewing volume, using right-handedness. + /// + /// @param left + /// @param right + /// @param bottom + /// @param top + /// @param zNear + /// @param zFar + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommanded), float or double. + /// @see gtc_matrix_transform + /// @see - glm::ortho(T const & left, T const & right, T const & bottom, T const & top) + template + GLM_FUNC_DECL tmat4x4 orthoRH( + T left, + T right, + T bottom, + T top, + T zNear, + T zFar); + + /// Creates a matrix for projecting two-dimensional coordinates onto the screen. + /// + /// @param left + /// @param right + /// @param bottom + /// @param top + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommanded), float or double. + /// @see gtc_matrix_transform + /// @see - glm::ortho(T const & left, T const & right, T const & bottom, T const & top, T const & zNear, T const & zFar) + template + GLM_FUNC_DECL tmat4x4 ortho( + T left, + T right, + T bottom, + T top); + + /// Creates a frustum matrix with default handedness. + /// + /// @param left + /// @param right + /// @param bottom + /// @param top + /// @param near + /// @param far + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommanded), float or double. + /// @see gtc_matrix_transform + template + GLM_FUNC_DECL tmat4x4 frustum( + T left, + T right, + T bottom, + T top, + T near, + T far); + + /// Creates a left handed frustum matrix. + /// + /// @param left + /// @param right + /// @param bottom + /// @param top + /// @param near + /// @param far + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommanded), float or double. + /// @see gtc_matrix_transform + template + GLM_FUNC_DECL tmat4x4 frustumLH( + T left, + T right, + T bottom, + T top, + T near, + T far); + + /// Creates a right handed frustum matrix. + /// + /// @param left + /// @param right + /// @param bottom + /// @param top + /// @param near + /// @param far + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommanded), float or double. + /// @see gtc_matrix_transform + template + GLM_FUNC_DECL tmat4x4 frustumRH( + T left, + T right, + T bottom, + T top, + T near, + T far); + + /// Creates a matrix for a symetric perspective-view frustum based on the default handedness. + /// + /// @param fovy Specifies the field of view angle in the y direction. Expressed in radians. + /// @param aspect Specifies the aspect ratio that determines the field of view in the x direction. The aspect ratio is the ratio of x (width) to y (height). + /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). + /// @param far Specifies the distance from the viewer to the far clipping plane (always positive). + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommanded), float or double. + /// @see gtc_matrix_transform + template + GLM_FUNC_DECL tmat4x4 perspective( + T fovy, + T aspect, + T near, + T far); + + /// Creates a matrix for a right handed, symetric perspective-view frustum. + /// + /// @param fovy Specifies the field of view angle, in degrees, in the y direction. Expressed in radians. + /// @param aspect Specifies the aspect ratio that determines the field of view in the x direction. The aspect ratio is the ratio of x (width) to y (height). + /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). + /// @param far Specifies the distance from the viewer to the far clipping plane (always positive). + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommanded), float or double. + /// @see gtc_matrix_transform + template + GLM_FUNC_DECL tmat4x4 perspectiveRH( + T fovy, + T aspect, + T near, + T far); + + /// Creates a matrix for a left handed, symetric perspective-view frustum. + /// + /// @param fovy Specifies the field of view angle, in degrees, in the y direction. Expressed in radians. + /// @param aspect Specifies the aspect ratio that determines the field of view in the x direction. The aspect ratio is the ratio of x (width) to y (height). + /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). + /// @param far Specifies the distance from the viewer to the far clipping plane (always positive). + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommanded), float or double. + /// @see gtc_matrix_transform + template + GLM_FUNC_DECL tmat4x4 perspectiveLH( + T fovy, + T aspect, + T near, + T far); + + /// Builds a perspective projection matrix based on a field of view and the default handedness. + /// + /// @param fov Expressed in radians. + /// @param width + /// @param height + /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). + /// @param far Specifies the distance from the viewer to the far clipping plane (always positive). + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommanded), float or double. + /// @see gtc_matrix_transform + template + GLM_FUNC_DECL tmat4x4 perspectiveFov( + T fov, + T width, + T height, + T near, + T far); + + /// Builds a right handed perspective projection matrix based on a field of view. + /// + /// @param fov Expressed in radians. + /// @param width + /// @param height + /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). + /// @param far Specifies the distance from the viewer to the far clipping plane (always positive). + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommanded), float or double. + /// @see gtc_matrix_transform + template + GLM_FUNC_DECL tmat4x4 perspectiveFovRH( + T fov, + T width, + T height, + T near, + T far); + + /// Builds a left handed perspective projection matrix based on a field of view. + /// + /// @param fov Expressed in radians. + /// @param width + /// @param height + /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). + /// @param far Specifies the distance from the viewer to the far clipping plane (always positive). + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommanded), float or double. + /// @see gtc_matrix_transform + template + GLM_FUNC_DECL tmat4x4 perspectiveFovLH( + T fov, + T width, + T height, + T near, + T far); + + /// Creates a matrix for a symmetric perspective-view frustum with far plane at infinite with default handedness. + /// + /// @param fovy Specifies the field of view angle, in degrees, in the y direction. Expressed in radians. + /// @param aspect Specifies the aspect ratio that determines the field of view in the x direction. The aspect ratio is the ratio of x (width) to y (height). + /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommanded), float or double. + /// @see gtc_matrix_transform + template + GLM_FUNC_DECL tmat4x4 infinitePerspective( + T fovy, T aspect, T near); + + /// Creates a matrix for a left handed, symmetric perspective-view frustum with far plane at infinite. + /// + /// @param fovy Specifies the field of view angle, in degrees, in the y direction. Expressed in radians. + /// @param aspect Specifies the aspect ratio that determines the field of view in the x direction. The aspect ratio is the ratio of x (width) to y (height). + /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommanded), float or double. + /// @see gtc_matrix_transform + template + GLM_FUNC_DECL tmat4x4 infinitePerspectiveLH( + T fovy, T aspect, T near); + + /// Creates a matrix for a right handed, symmetric perspective-view frustum with far plane at infinite. + /// + /// @param fovy Specifies the field of view angle, in degrees, in the y direction. Expressed in radians. + /// @param aspect Specifies the aspect ratio that determines the field of view in the x direction. The aspect ratio is the ratio of x (width) to y (height). + /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommanded), float or double. + /// @see gtc_matrix_transform + template + GLM_FUNC_DECL tmat4x4 infinitePerspectiveRH( + T fovy, T aspect, T near); + + /// Creates a matrix for a symmetric perspective-view frustum with far plane at infinite for graphics hardware that doesn't support depth clamping. + /// + /// @param fovy Specifies the field of view angle, in degrees, in the y direction. Expressed in radians. + /// @param aspect Specifies the aspect ratio that determines the field of view in the x direction. The aspect ratio is the ratio of x (width) to y (height). + /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommanded), float or double. + /// @see gtc_matrix_transform + template + GLM_FUNC_DECL tmat4x4 tweakedInfinitePerspective( + T fovy, T aspect, T near); + + /// Creates a matrix for a symmetric perspective-view frustum with far plane at infinite for graphics hardware that doesn't support depth clamping. + /// + /// @param fovy Specifies the field of view angle, in degrees, in the y direction. Expressed in radians. + /// @param aspect Specifies the aspect ratio that determines the field of view in the x direction. The aspect ratio is the ratio of x (width) to y (height). + /// @param near Specifies the distance from the viewer to the near clipping plane (always positive). + /// @param ep + /// @tparam T Value type used to build the matrix. Currently supported: half (not recommanded), float or double. + /// @see gtc_matrix_transform + template + GLM_FUNC_DECL tmat4x4 tweakedInfinitePerspective( + T fovy, T aspect, T near, T ep); + + /// Map the specified object coordinates (obj.x, obj.y, obj.z) into window coordinates. + /// + /// @param obj Specify the object coordinates. + /// @param model Specifies the current modelview matrix + /// @param proj Specifies the current projection matrix + /// @param viewport Specifies the current viewport + /// @return Return the computed window coordinates. + /// @tparam T Native type used for the computation. Currently supported: half (not recommanded), float or double. + /// @tparam U Currently supported: Floating-point types and integer types. + /// @see gtc_matrix_transform + template + GLM_FUNC_DECL tvec3 project( + tvec3 const & obj, + tmat4x4 const & model, + tmat4x4 const & proj, + tvec4 const & viewport); + + /// Map the specified window coordinates (win.x, win.y, win.z) into object coordinates. + /// + /// @param win Specify the window coordinates to be mapped. + /// @param model Specifies the modelview matrix + /// @param proj Specifies the projection matrix + /// @param viewport Specifies the viewport + /// @return Returns the computed object coordinates. + /// @tparam T Native type used for the computation. Currently supported: half (not recommanded), float or double. + /// @tparam U Currently supported: Floating-point types and integer types. + /// @see gtc_matrix_transform + template + GLM_FUNC_DECL tvec3 unProject( + tvec3 const & win, + tmat4x4 const & model, + tmat4x4 const & proj, + tvec4 const & viewport); + + /// Define a picking region + /// + /// @param center + /// @param delta + /// @param viewport + /// @tparam T Native type used for the computation. Currently supported: half (not recommanded), float or double. + /// @tparam U Currently supported: Floating-point types and integer types. + /// @see gtc_matrix_transform + template + GLM_FUNC_DECL tmat4x4 pickMatrix( + tvec2 const & center, + tvec2 const & delta, + tvec4 const & viewport); + + /// Build a look at view matrix based on the default handedness. + /// + /// @param eye Position of the camera + /// @param center Position where the camera is looking at + /// @param up Normalized up vector, how the camera is oriented. Typically (0, 0, 1) + /// @see gtc_matrix_transform + /// @see - frustum(T const & left, T const & right, T const & bottom, T const & top, T const & nearVal, T const & farVal) frustum(T const & left, T const & right, T const & bottom, T const & top, T const & nearVal, T const & farVal) + template + GLM_FUNC_DECL tmat4x4 lookAt( + tvec3 const & eye, + tvec3 const & center, + tvec3 const & up); + + /// Build a right handed look at view matrix. + /// + /// @param eye Position of the camera + /// @param center Position where the camera is looking at + /// @param up Normalized up vector, how the camera is oriented. Typically (0, 0, 1) + /// @see gtc_matrix_transform + /// @see - frustum(T const & left, T const & right, T const & bottom, T const & top, T const & nearVal, T const & farVal) frustum(T const & left, T const & right, T const & bottom, T const & top, T const & nearVal, T const & farVal) + template + GLM_FUNC_DECL tmat4x4 lookAtRH( + tvec3 const & eye, + tvec3 const & center, + tvec3 const & up); + + /// Build a left handed look at view matrix. + /// + /// @param eye Position of the camera + /// @param center Position where the camera is looking at + /// @param up Normalized up vector, how the camera is oriented. Typically (0, 0, 1) + /// @see gtc_matrix_transform + /// @see - frustum(T const & left, T const & right, T const & bottom, T const & top, T const & nearVal, T const & farVal) frustum(T const & left, T const & right, T const & bottom, T const & top, T const & nearVal, T const & farVal) + template + GLM_FUNC_DECL tmat4x4 lookAtLH( + tvec3 const & eye, + tvec3 const & center, + tvec3 const & up); + + /// @} +}//namespace glm + +#include "matrix_transform.inl" diff --git a/external/include/glm/gtc/matrix_transform.inl b/external/include/glm/gtc/matrix_transform.inl new file mode 100644 index 0000000..b9ff418 --- /dev/null +++ b/external/include/glm/gtc/matrix_transform.inl @@ -0,0 +1,575 @@ +/// @ref gtc_matrix_transform +/// @file glm/gtc/matrix_transform.inl + +#include "../geometric.hpp" +#include "../trigonometric.hpp" +#include "../matrix.hpp" + +namespace glm +{ + template + GLM_FUNC_QUALIFIER tmat4x4 translate(tmat4x4 const & m, tvec3 const & v) + { + tmat4x4 Result(m); + Result[3] = m[0] * v[0] + m[1] * v[1] + m[2] * v[2] + m[3]; + return Result; + } + + template + GLM_FUNC_QUALIFIER tmat4x4 rotate(tmat4x4 const & m, T angle, tvec3 const & v) + { + T const a = angle; + T const c = cos(a); + T const s = sin(a); + + tvec3 axis(normalize(v)); + tvec3 temp((T(1) - c) * axis); + + tmat4x4 Rotate(uninitialize); + Rotate[0][0] = c + temp[0] * axis[0]; + Rotate[0][1] = temp[0] * axis[1] + s * axis[2]; + Rotate[0][2] = temp[0] * axis[2] - s * axis[1]; + + Rotate[1][0] = temp[1] * axis[0] - s * axis[2]; + Rotate[1][1] = c + temp[1] * axis[1]; + Rotate[1][2] = temp[1] * axis[2] + s * axis[0]; + + Rotate[2][0] = temp[2] * axis[0] + s * axis[1]; + Rotate[2][1] = temp[2] * axis[1] - s * axis[0]; + Rotate[2][2] = c + temp[2] * axis[2]; + + tmat4x4 Result(uninitialize); + Result[0] = m[0] * Rotate[0][0] + m[1] * Rotate[0][1] + m[2] * Rotate[0][2]; + Result[1] = m[0] * Rotate[1][0] + m[1] * Rotate[1][1] + m[2] * Rotate[1][2]; + Result[2] = m[0] * Rotate[2][0] + m[1] * Rotate[2][1] + m[2] * Rotate[2][2]; + Result[3] = m[3]; + return Result; + } + + template + GLM_FUNC_QUALIFIER tmat4x4 rotate_slow(tmat4x4 const & m, T angle, tvec3 const & v) + { + T const a = angle; + T const c = cos(a); + T const s = sin(a); + tmat4x4 Result; + + tvec3 axis = normalize(v); + + Result[0][0] = c + (static_cast(1) - c) * axis.x * axis.x; + Result[0][1] = (static_cast(1) - c) * axis.x * axis.y + s * axis.z; + Result[0][2] = (static_cast(1) - c) * axis.x * axis.z - s * axis.y; + Result[0][3] = static_cast(0); + + Result[1][0] = (static_cast(1) - c) * axis.y * axis.x - s * axis.z; + Result[1][1] = c + (static_cast(1) - c) * axis.y * axis.y; + Result[1][2] = (static_cast(1) - c) * axis.y * axis.z + s * axis.x; + Result[1][3] = static_cast(0); + + Result[2][0] = (static_cast(1) - c) * axis.z * axis.x + s * axis.y; + Result[2][1] = (static_cast(1) - c) * axis.z * axis.y - s * axis.x; + Result[2][2] = c + (static_cast(1) - c) * axis.z * axis.z; + Result[2][3] = static_cast(0); + + Result[3] = tvec4(0, 0, 0, 1); + return m * Result; + } + + template + GLM_FUNC_QUALIFIER tmat4x4 scale(tmat4x4 const & m, tvec3 const & v) + { + tmat4x4 Result(uninitialize); + Result[0] = m[0] * v[0]; + Result[1] = m[1] * v[1]; + Result[2] = m[2] * v[2]; + Result[3] = m[3]; + return Result; + } + + template + GLM_FUNC_QUALIFIER tmat4x4 scale_slow(tmat4x4 const & m, tvec3 const & v) + { + tmat4x4 Result(T(1)); + Result[0][0] = v.x; + Result[1][1] = v.y; + Result[2][2] = v.z; + return m * Result; + } + + template + GLM_FUNC_QUALIFIER tmat4x4 ortho + ( + T left, T right, + T bottom, T top, + T zNear, T zFar + ) + { +# if GLM_COORDINATE_SYSTEM == GLM_LEFT_HANDED + return orthoLH(left, right, bottom, top, zNear, zFar); +# else + return orthoRH(left, right, bottom, top, zNear, zFar); +# endif + } + + template + GLM_FUNC_QUALIFIER tmat4x4 orthoLH + ( + T left, T right, + T bottom, T top, + T zNear, T zFar + ) + { + tmat4x4 Result(1); + Result[0][0] = static_cast(2) / (right - left); + Result[1][1] = static_cast(2) / (top - bottom); + Result[3][0] = - (right + left) / (right - left); + Result[3][1] = - (top + bottom) / (top - bottom); + +# if GLM_DEPTH_CLIP_SPACE == GLM_DEPTH_ZERO_TO_ONE + Result[2][2] = static_cast(1) / (zFar - zNear); + Result[3][2] = - zNear / (zFar - zNear); +# else + Result[2][2] = static_cast(2) / (zFar - zNear); + Result[3][2] = - (zFar + zNear) / (zFar - zNear); +# endif + + return Result; + } + + template + GLM_FUNC_QUALIFIER tmat4x4 orthoRH + ( + T left, T right, + T bottom, T top, + T zNear, T zFar + ) + { + tmat4x4 Result(1); + Result[0][0] = static_cast(2) / (right - left); + Result[1][1] = static_cast(2) / (top - bottom); + Result[3][0] = - (right + left) / (right - left); + Result[3][1] = - (top + bottom) / (top - bottom); + +# if GLM_DEPTH_CLIP_SPACE == GLM_DEPTH_ZERO_TO_ONE + Result[2][2] = - static_cast(1) / (zFar - zNear); + Result[3][2] = - zNear / (zFar - zNear); +# else + Result[2][2] = - static_cast(2) / (zFar - zNear); + Result[3][2] = - (zFar + zNear) / (zFar - zNear); +# endif + + return Result; + } + + template + GLM_FUNC_QUALIFIER tmat4x4 ortho + ( + T left, T right, + T bottom, T top + ) + { + tmat4x4 Result(static_cast(1)); + Result[0][0] = static_cast(2) / (right - left); + Result[1][1] = static_cast(2) / (top - bottom); + Result[2][2] = - static_cast(1); + Result[3][0] = - (right + left) / (right - left); + Result[3][1] = - (top + bottom) / (top - bottom); + return Result; + } + + template + GLM_FUNC_QUALIFIER tmat4x4 frustum + ( + T left, T right, + T bottom, T top, + T nearVal, T farVal + ) + { +# if GLM_COORDINATE_SYSTEM == GLM_LEFT_HANDED + return frustumLH(left, right, bottom, top, nearVal, farVal); +# else + return frustumRH(left, right, bottom, top, nearVal, farVal); +# endif + } + + template + GLM_FUNC_QUALIFIER tmat4x4 frustumLH + ( + T left, T right, + T bottom, T top, + T nearVal, T farVal + ) + { + tmat4x4 Result(0); + Result[0][0] = (static_cast(2) * nearVal) / (right - left); + Result[1][1] = (static_cast(2) * nearVal) / (top - bottom); + Result[2][0] = (right + left) / (right - left); + Result[2][1] = (top + bottom) / (top - bottom); + Result[2][3] = static_cast(1); + +# if GLM_DEPTH_CLIP_SPACE == GLM_DEPTH_ZERO_TO_ONE + Result[2][2] = farVal / (farVal - nearVal); + Result[3][2] = -(farVal * nearVal) / (farVal - nearVal); +# else + Result[2][2] = (farVal + nearVal) / (farVal - nearVal); + Result[3][2] = - (static_cast(2) * farVal * nearVal) / (farVal - nearVal); +# endif + + return Result; + } + + template + GLM_FUNC_QUALIFIER tmat4x4 frustumRH + ( + T left, T right, + T bottom, T top, + T nearVal, T farVal + ) + { + tmat4x4 Result(0); + Result[0][0] = (static_cast(2) * nearVal) / (right - left); + Result[1][1] = (static_cast(2) * nearVal) / (top - bottom); + Result[2][0] = (right + left) / (right - left); + Result[2][1] = (top + bottom) / (top - bottom); + Result[2][3] = static_cast(-1); + +# if GLM_DEPTH_CLIP_SPACE == GLM_DEPTH_ZERO_TO_ONE + Result[2][2] = farVal / (nearVal - farVal); + Result[3][2] = -(farVal * nearVal) / (farVal - nearVal); +# else + Result[2][2] = - (farVal + nearVal) / (farVal - nearVal); + Result[3][2] = - (static_cast(2) * farVal * nearVal) / (farVal - nearVal); +# endif + + return Result; + } + + template + GLM_FUNC_QUALIFIER tmat4x4 perspective(T fovy, T aspect, T zNear, T zFar) + { +# if GLM_COORDINATE_SYSTEM == GLM_LEFT_HANDED + return perspectiveLH(fovy, aspect, zNear, zFar); +# else + return perspectiveRH(fovy, aspect, zNear, zFar); +# endif + } + + template + GLM_FUNC_QUALIFIER tmat4x4 perspectiveRH(T fovy, T aspect, T zNear, T zFar) + { + assert(abs(aspect - std::numeric_limits::epsilon()) > static_cast(0)); + + T const tanHalfFovy = tan(fovy / static_cast(2)); + + tmat4x4 Result(static_cast(0)); + Result[0][0] = static_cast(1) / (aspect * tanHalfFovy); + Result[1][1] = static_cast(1) / (tanHalfFovy); + Result[2][3] = - static_cast(1); + +# if GLM_DEPTH_CLIP_SPACE == GLM_DEPTH_ZERO_TO_ONE + Result[2][2] = zFar / (zNear - zFar); + Result[3][2] = -(zFar * zNear) / (zFar - zNear); +# else + Result[2][2] = - (zFar + zNear) / (zFar - zNear); + Result[3][2] = - (static_cast(2) * zFar * zNear) / (zFar - zNear); +# endif + + return Result; + } + + template + GLM_FUNC_QUALIFIER tmat4x4 perspectiveLH(T fovy, T aspect, T zNear, T zFar) + { + assert(abs(aspect - std::numeric_limits::epsilon()) > static_cast(0)); + + T const tanHalfFovy = tan(fovy / static_cast(2)); + + tmat4x4 Result(static_cast(0)); + Result[0][0] = static_cast(1) / (aspect * tanHalfFovy); + Result[1][1] = static_cast(1) / (tanHalfFovy); + Result[2][3] = static_cast(1); + +# if GLM_DEPTH_CLIP_SPACE == GLM_DEPTH_ZERO_TO_ONE + Result[2][2] = zFar / (zFar - zNear); + Result[3][2] = -(zFar * zNear) / (zFar - zNear); +# else + Result[2][2] = (zFar + zNear) / (zFar - zNear); + Result[3][2] = - (static_cast(2) * zFar * zNear) / (zFar - zNear); +# endif + + return Result; + } + + template + GLM_FUNC_QUALIFIER tmat4x4 perspectiveFov(T fov, T width, T height, T zNear, T zFar) + { +# if GLM_COORDINATE_SYSTEM == GLM_LEFT_HANDED + return perspectiveFovLH(fov, width, height, zNear, zFar); +# else + return perspectiveFovRH(fov, width, height, zNear, zFar); +# endif + } + + template + GLM_FUNC_QUALIFIER tmat4x4 perspectiveFovRH(T fov, T width, T height, T zNear, T zFar) + { + assert(width > static_cast(0)); + assert(height > static_cast(0)); + assert(fov > static_cast(0)); + + T const rad = fov; + T const h = glm::cos(static_cast(0.5) * rad) / glm::sin(static_cast(0.5) * rad); + T const w = h * height / width; ///todo max(width , Height) / min(width , Height)? + + tmat4x4 Result(static_cast(0)); + Result[0][0] = w; + Result[1][1] = h; + Result[2][3] = - static_cast(1); + +# if GLM_DEPTH_CLIP_SPACE == GLM_DEPTH_ZERO_TO_ONE + Result[2][2] = zFar / (zNear - zFar); + Result[3][2] = -(zFar * zNear) / (zFar - zNear); +# else + Result[2][2] = - (zFar + zNear) / (zFar - zNear); + Result[3][2] = - (static_cast(2) * zFar * zNear) / (zFar - zNear); +# endif + + return Result; + } + + template + GLM_FUNC_QUALIFIER tmat4x4 perspectiveFovLH(T fov, T width, T height, T zNear, T zFar) + { + assert(width > static_cast(0)); + assert(height > static_cast(0)); + assert(fov > static_cast(0)); + + T const rad = fov; + T const h = glm::cos(static_cast(0.5) * rad) / glm::sin(static_cast(0.5) * rad); + T const w = h * height / width; ///todo max(width , Height) / min(width , Height)? + + tmat4x4 Result(static_cast(0)); + Result[0][0] = w; + Result[1][1] = h; + Result[2][3] = static_cast(1); + +# if GLM_DEPTH_CLIP_SPACE == GLM_DEPTH_ZERO_TO_ONE + Result[2][2] = zFar / (zFar - zNear); + Result[3][2] = -(zFar * zNear) / (zFar - zNear); +# else + Result[2][2] = (zFar + zNear) / (zFar - zNear); + Result[3][2] = - (static_cast(2) * zFar * zNear) / (zFar - zNear); +# endif + + return Result; + } + + template + GLM_FUNC_QUALIFIER tmat4x4 infinitePerspective(T fovy, T aspect, T zNear) + { +# if GLM_COORDINATE_SYSTEM == GLM_LEFT_HANDED + return infinitePerspectiveLH(fovy, aspect, zNear); +# else + return infinitePerspectiveRH(fovy, aspect, zNear); +# endif + } + + template + GLM_FUNC_QUALIFIER tmat4x4 infinitePerspectiveRH(T fovy, T aspect, T zNear) + { + T const range = tan(fovy / static_cast(2)) * zNear; + T const left = -range * aspect; + T const right = range * aspect; + T const bottom = -range; + T const top = range; + + tmat4x4 Result(static_cast(0)); + Result[0][0] = (static_cast(2) * zNear) / (right - left); + Result[1][1] = (static_cast(2) * zNear) / (top - bottom); + Result[2][2] = - static_cast(1); + Result[2][3] = - static_cast(1); + Result[3][2] = - static_cast(2) * zNear; + return Result; + } + + template + GLM_FUNC_QUALIFIER tmat4x4 infinitePerspectiveLH(T fovy, T aspect, T zNear) + { + T const range = tan(fovy / static_cast(2)) * zNear; + T const left = -range * aspect; + T const right = range * aspect; + T const bottom = -range; + T const top = range; + + tmat4x4 Result(T(0)); + Result[0][0] = (static_cast(2) * zNear) / (right - left); + Result[1][1] = (static_cast(2) * zNear) / (top - bottom); + Result[2][2] = static_cast(1); + Result[2][3] = static_cast(1); + Result[3][2] = - static_cast(2) * zNear; + return Result; + } + + // Infinite projection matrix: http://www.terathon.com/gdc07_lengyel.pdf + template + GLM_FUNC_QUALIFIER tmat4x4 tweakedInfinitePerspective(T fovy, T aspect, T zNear, T ep) + { + T const range = tan(fovy / static_cast(2)) * zNear; + T const left = -range * aspect; + T const right = range * aspect; + T const bottom = -range; + T const top = range; + + tmat4x4 Result(static_cast(0)); + Result[0][0] = (static_cast(2) * zNear) / (right - left); + Result[1][1] = (static_cast(2) * zNear) / (top - bottom); + Result[2][2] = ep - static_cast(1); + Result[2][3] = static_cast(-1); + Result[3][2] = (ep - static_cast(2)) * zNear; + return Result; + } + + template + GLM_FUNC_QUALIFIER tmat4x4 tweakedInfinitePerspective(T fovy, T aspect, T zNear) + { + return tweakedInfinitePerspective(fovy, aspect, zNear, epsilon()); + } + + template + GLM_FUNC_QUALIFIER tvec3 project + ( + tvec3 const & obj, + tmat4x4 const & model, + tmat4x4 const & proj, + tvec4 const & viewport + ) + { + tvec4 tmp = tvec4(obj, static_cast(1)); + tmp = model * tmp; + tmp = proj * tmp; + + tmp /= tmp.w; +# if GLM_DEPTH_CLIP_SPACE == GLM_DEPTH_ZERO_TO_ONE + tmp.x = tmp.x * static_cast(0.5) + static_cast(0.5); + tmp.y = tmp.y * static_cast(0.5) + static_cast(0.5); +# else + tmp = tmp * static_cast(0.5) + static_cast(0.5); +# endif + tmp[0] = tmp[0] * T(viewport[2]) + T(viewport[0]); + tmp[1] = tmp[1] * T(viewport[3]) + T(viewport[1]); + + return tvec3(tmp); + } + + template + GLM_FUNC_QUALIFIER tvec3 unProject + ( + tvec3 const & win, + tmat4x4 const & model, + tmat4x4 const & proj, + tvec4 const & viewport + ) + { + tmat4x4 Inverse = inverse(proj * model); + + tvec4 tmp = tvec4(win, T(1)); + tmp.x = (tmp.x - T(viewport[0])) / T(viewport[2]); + tmp.y = (tmp.y - T(viewport[1])) / T(viewport[3]); +# if GLM_DEPTH_CLIP_SPACE == GLM_DEPTH_ZERO_TO_ONE + tmp.x = tmp.x * static_cast(2) - static_cast(1); + tmp.y = tmp.y * static_cast(2) - static_cast(1); +# else + tmp = tmp * static_cast(2) - static_cast(1); +# endif + + tvec4 obj = Inverse * tmp; + obj /= obj.w; + + return tvec3(obj); + } + + template + GLM_FUNC_QUALIFIER tmat4x4 pickMatrix(tvec2 const & center, tvec2 const & delta, tvec4 const & viewport) + { + assert(delta.x > static_cast(0) && delta.y > static_cast(0)); + tmat4x4 Result(static_cast(1)); + + if(!(delta.x > static_cast(0) && delta.y > static_cast(0))) + return Result; // Error + + tvec3 Temp( + (static_cast(viewport[2]) - static_cast(2) * (center.x - static_cast(viewport[0]))) / delta.x, + (static_cast(viewport[3]) - static_cast(2) * (center.y - static_cast(viewport[1]))) / delta.y, + static_cast(0)); + + // Translate and scale the picked region to the entire window + Result = translate(Result, Temp); + return scale(Result, tvec3(static_cast(viewport[2]) / delta.x, static_cast(viewport[3]) / delta.y, static_cast(1))); + } + + template + GLM_FUNC_QUALIFIER tmat4x4 lookAt(tvec3 const & eye, tvec3 const & center, tvec3 const & up) + { +# if GLM_COORDINATE_SYSTEM == GLM_LEFT_HANDED + return lookAtLH(eye, center, up); +# else + return lookAtRH(eye, center, up); +# endif + } + + template + GLM_FUNC_QUALIFIER tmat4x4 lookAtRH + ( + tvec3 const & eye, + tvec3 const & center, + tvec3 const & up + ) + { + tvec3 const f(normalize(center - eye)); + tvec3 const s(normalize(cross(f, up))); + tvec3 const u(cross(s, f)); + + tmat4x4 Result(1); + Result[0][0] = s.x; + Result[1][0] = s.y; + Result[2][0] = s.z; + Result[0][1] = u.x; + Result[1][1] = u.y; + Result[2][1] = u.z; + Result[0][2] =-f.x; + Result[1][2] =-f.y; + Result[2][2] =-f.z; + Result[3][0] =-dot(s, eye); + Result[3][1] =-dot(u, eye); + Result[3][2] = dot(f, eye); + return Result; + } + + template + GLM_FUNC_QUALIFIER tmat4x4 lookAtLH + ( + tvec3 const & eye, + tvec3 const & center, + tvec3 const & up + ) + { + tvec3 const f(normalize(center - eye)); + tvec3 const s(normalize(cross(up, f))); + tvec3 const u(cross(f, s)); + + tmat4x4 Result(1); + Result[0][0] = s.x; + Result[1][0] = s.y; + Result[2][0] = s.z; + Result[0][1] = u.x; + Result[1][1] = u.y; + Result[2][1] = u.z; + Result[0][2] = f.x; + Result[1][2] = f.y; + Result[2][2] = f.z; + Result[3][0] = -dot(s, eye); + Result[3][1] = -dot(u, eye); + Result[3][2] = -dot(f, eye); + return Result; + } +}//namespace glm diff --git a/external/include/glm/gtc/noise.hpp b/external/include/glm/gtc/noise.hpp new file mode 100644 index 0000000..aec4f18 --- /dev/null +++ b/external/include/glm/gtc/noise.hpp @@ -0,0 +1,60 @@ +/// @ref gtc_noise +/// @file glm/gtc/noise.hpp +/// +/// @see core (dependence) +/// +/// @defgroup gtc_noise GLM_GTC_noise +/// @ingroup gtc +/// +/// Defines 2D, 3D and 4D procedural noise functions +/// Based on the work of Stefan Gustavson and Ashima Arts on "webgl-noise": +/// https://github.com/ashima/webgl-noise +/// Following Stefan Gustavson's paper "Simplex noise demystified": +/// http://www.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf +/// need to be included to use these functionalities. + +#pragma once + +// Dependencies +#include "../detail/setup.hpp" +#include "../detail/precision.hpp" +#include "../detail/_noise.hpp" +#include "../geometric.hpp" +#include "../common.hpp" +#include "../vector_relational.hpp" +#include "../vec2.hpp" +#include "../vec3.hpp" +#include "../vec4.hpp" + +#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED) +# pragma message("GLM: GLM_GTC_noise extension included") +#endif + +namespace glm +{ + /// @addtogroup gtc_noise + /// @{ + + /// Classic perlin noise. + /// @see gtc_noise + template class vecType> + GLM_FUNC_DECL T perlin( + vecType const & p); + + /// Periodic perlin noise. + /// @see gtc_noise + template class vecType> + GLM_FUNC_DECL T perlin( + vecType const & p, + vecType const & rep); + + /// Simplex noise. + /// @see gtc_noise + template class vecType> + GLM_FUNC_DECL T simplex( + vecType const & p); + + /// @} +}//namespace glm + +#include "noise.inl" diff --git a/external/include/glm/gtc/noise.inl b/external/include/glm/gtc/noise.inl new file mode 100644 index 0000000..4f2731c --- /dev/null +++ b/external/include/glm/gtc/noise.inl @@ -0,0 +1,808 @@ +/// @ref gtc_noise +/// @file glm/gtc/noise.inl +/// +// Based on the work of Stefan Gustavson and Ashima Arts on "webgl-noise": +// https://github.com/ashima/webgl-noise +// Following Stefan Gustavson's paper "Simplex noise demystified": +// http://www.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf + +namespace glm{ +namespace gtc +{ + template + GLM_FUNC_QUALIFIER tvec4 grad4(T const & j, tvec4 const & ip) + { + tvec3 pXYZ = floor(fract(tvec3(j) * tvec3(ip)) * T(7)) * ip[2] - T(1); + T pW = static_cast(1.5) - dot(abs(pXYZ), tvec3(1)); + tvec4 s = tvec4(lessThan(tvec4(pXYZ, pW), tvec4(0.0))); + pXYZ = pXYZ + (tvec3(s) * T(2) - T(1)) * s.w; + return tvec4(pXYZ, pW); + } +}//namespace gtc + + // Classic Perlin noise + template + GLM_FUNC_QUALIFIER T perlin(tvec2 const & Position) + { + tvec4 Pi = glm::floor(tvec4(Position.x, Position.y, Position.x, Position.y)) + tvec4(0.0, 0.0, 1.0, 1.0); + tvec4 Pf = glm::fract(tvec4(Position.x, Position.y, Position.x, Position.y)) - tvec4(0.0, 0.0, 1.0, 1.0); + Pi = mod(Pi, tvec4(289)); // To avoid truncation effects in permutation + tvec4 ix(Pi.x, Pi.z, Pi.x, Pi.z); + tvec4 iy(Pi.y, Pi.y, Pi.w, Pi.w); + tvec4 fx(Pf.x, Pf.z, Pf.x, Pf.z); + tvec4 fy(Pf.y, Pf.y, Pf.w, Pf.w); + + tvec4 i = detail::permute(detail::permute(ix) + iy); + + tvec4 gx = static_cast(2) * glm::fract(i / T(41)) - T(1); + tvec4 gy = glm::abs(gx) - T(0.5); + tvec4 tx = glm::floor(gx + T(0.5)); + gx = gx - tx; + + tvec2 g00(gx.x, gy.x); + tvec2 g10(gx.y, gy.y); + tvec2 g01(gx.z, gy.z); + tvec2 g11(gx.w, gy.w); + + tvec4 norm = detail::taylorInvSqrt(tvec4(dot(g00, g00), dot(g01, g01), dot(g10, g10), dot(g11, g11))); + g00 *= norm.x; + g01 *= norm.y; + g10 *= norm.z; + g11 *= norm.w; + + T n00 = dot(g00, tvec2(fx.x, fy.x)); + T n10 = dot(g10, tvec2(fx.y, fy.y)); + T n01 = dot(g01, tvec2(fx.z, fy.z)); + T n11 = dot(g11, tvec2(fx.w, fy.w)); + + tvec2 fade_xy = detail::fade(tvec2(Pf.x, Pf.y)); + tvec2 n_x = mix(tvec2(n00, n01), tvec2(n10, n11), fade_xy.x); + T n_xy = mix(n_x.x, n_x.y, fade_xy.y); + return T(2.3) * n_xy; + } + + // Classic Perlin noise + template + GLM_FUNC_QUALIFIER T perlin(tvec3 const & Position) + { + tvec3 Pi0 = floor(Position); // Integer part for indexing + tvec3 Pi1 = Pi0 + T(1); // Integer part + 1 + Pi0 = detail::mod289(Pi0); + Pi1 = detail::mod289(Pi1); + tvec3 Pf0 = fract(Position); // Fractional part for interpolation + tvec3 Pf1 = Pf0 - T(1); // Fractional part - 1.0 + tvec4 ix(Pi0.x, Pi1.x, Pi0.x, Pi1.x); + tvec4 iy = tvec4(tvec2(Pi0.y), tvec2(Pi1.y)); + tvec4 iz0(Pi0.z); + tvec4 iz1(Pi1.z); + + tvec4 ixy = detail::permute(detail::permute(ix) + iy); + tvec4 ixy0 = detail::permute(ixy + iz0); + tvec4 ixy1 = detail::permute(ixy + iz1); + + tvec4 gx0 = ixy0 * T(1.0 / 7.0); + tvec4 gy0 = fract(floor(gx0) * T(1.0 / 7.0)) - T(0.5); + gx0 = fract(gx0); + tvec4 gz0 = tvec4(0.5) - abs(gx0) - abs(gy0); + tvec4 sz0 = step(gz0, tvec4(0.0)); + gx0 -= sz0 * (step(T(0), gx0) - T(0.5)); + gy0 -= sz0 * (step(T(0), gy0) - T(0.5)); + + tvec4 gx1 = ixy1 * T(1.0 / 7.0); + tvec4 gy1 = fract(floor(gx1) * T(1.0 / 7.0)) - T(0.5); + gx1 = fract(gx1); + tvec4 gz1 = tvec4(0.5) - abs(gx1) - abs(gy1); + tvec4 sz1 = step(gz1, tvec4(0.0)); + gx1 -= sz1 * (step(T(0), gx1) - T(0.5)); + gy1 -= sz1 * (step(T(0), gy1) - T(0.5)); + + tvec3 g000(gx0.x, gy0.x, gz0.x); + tvec3 g100(gx0.y, gy0.y, gz0.y); + tvec3 g010(gx0.z, gy0.z, gz0.z); + tvec3 g110(gx0.w, gy0.w, gz0.w); + tvec3 g001(gx1.x, gy1.x, gz1.x); + tvec3 g101(gx1.y, gy1.y, gz1.y); + tvec3 g011(gx1.z, gy1.z, gz1.z); + tvec3 g111(gx1.w, gy1.w, gz1.w); + + tvec4 norm0 = detail::taylorInvSqrt(tvec4(dot(g000, g000), dot(g010, g010), dot(g100, g100), dot(g110, g110))); + g000 *= norm0.x; + g010 *= norm0.y; + g100 *= norm0.z; + g110 *= norm0.w; + tvec4 norm1 = detail::taylorInvSqrt(tvec4(dot(g001, g001), dot(g011, g011), dot(g101, g101), dot(g111, g111))); + g001 *= norm1.x; + g011 *= norm1.y; + g101 *= norm1.z; + g111 *= norm1.w; + + T n000 = dot(g000, Pf0); + T n100 = dot(g100, tvec3(Pf1.x, Pf0.y, Pf0.z)); + T n010 = dot(g010, tvec3(Pf0.x, Pf1.y, Pf0.z)); + T n110 = dot(g110, tvec3(Pf1.x, Pf1.y, Pf0.z)); + T n001 = dot(g001, tvec3(Pf0.x, Pf0.y, Pf1.z)); + T n101 = dot(g101, tvec3(Pf1.x, Pf0.y, Pf1.z)); + T n011 = dot(g011, tvec3(Pf0.x, Pf1.y, Pf1.z)); + T n111 = dot(g111, Pf1); + + tvec3 fade_xyz = detail::fade(Pf0); + tvec4 n_z = mix(tvec4(n000, n100, n010, n110), tvec4(n001, n101, n011, n111), fade_xyz.z); + tvec2 n_yz = mix(tvec2(n_z.x, n_z.y), tvec2(n_z.z, n_z.w), fade_xyz.y); + T n_xyz = mix(n_yz.x, n_yz.y, fade_xyz.x); + return T(2.2) * n_xyz; + } + /* + // Classic Perlin noise + template + GLM_FUNC_QUALIFIER T perlin(tvec3 const & P) + { + tvec3 Pi0 = floor(P); // Integer part for indexing + tvec3 Pi1 = Pi0 + T(1); // Integer part + 1 + Pi0 = mod(Pi0, T(289)); + Pi1 = mod(Pi1, T(289)); + tvec3 Pf0 = fract(P); // Fractional part for interpolation + tvec3 Pf1 = Pf0 - T(1); // Fractional part - 1.0 + tvec4 ix(Pi0.x, Pi1.x, Pi0.x, Pi1.x); + tvec4 iy(Pi0.y, Pi0.y, Pi1.y, Pi1.y); + tvec4 iz0(Pi0.z); + tvec4 iz1(Pi1.z); + + tvec4 ixy = permute(permute(ix) + iy); + tvec4 ixy0 = permute(ixy + iz0); + tvec4 ixy1 = permute(ixy + iz1); + + tvec4 gx0 = ixy0 / T(7); + tvec4 gy0 = fract(floor(gx0) / T(7)) - T(0.5); + gx0 = fract(gx0); + tvec4 gz0 = tvec4(0.5) - abs(gx0) - abs(gy0); + tvec4 sz0 = step(gz0, tvec4(0.0)); + gx0 -= sz0 * (step(0.0, gx0) - T(0.5)); + gy0 -= sz0 * (step(0.0, gy0) - T(0.5)); + + tvec4 gx1 = ixy1 / T(7); + tvec4 gy1 = fract(floor(gx1) / T(7)) - T(0.5); + gx1 = fract(gx1); + tvec4 gz1 = tvec4(0.5) - abs(gx1) - abs(gy1); + tvec4 sz1 = step(gz1, tvec4(0.0)); + gx1 -= sz1 * (step(T(0), gx1) - T(0.5)); + gy1 -= sz1 * (step(T(0), gy1) - T(0.5)); + + tvec3 g000(gx0.x, gy0.x, gz0.x); + tvec3 g100(gx0.y, gy0.y, gz0.y); + tvec3 g010(gx0.z, gy0.z, gz0.z); + tvec3 g110(gx0.w, gy0.w, gz0.w); + tvec3 g001(gx1.x, gy1.x, gz1.x); + tvec3 g101(gx1.y, gy1.y, gz1.y); + tvec3 g011(gx1.z, gy1.z, gz1.z); + tvec3 g111(gx1.w, gy1.w, gz1.w); + + tvec4 norm0 = taylorInvSqrt(tvec4(dot(g000, g000), dot(g010, g010), dot(g100, g100), dot(g110, g110))); + g000 *= norm0.x; + g010 *= norm0.y; + g100 *= norm0.z; + g110 *= norm0.w; + tvec4 norm1 = taylorInvSqrt(tvec4(dot(g001, g001), dot(g011, g011), dot(g101, g101), dot(g111, g111))); + g001 *= norm1.x; + g011 *= norm1.y; + g101 *= norm1.z; + g111 *= norm1.w; + + T n000 = dot(g000, Pf0); + T n100 = dot(g100, tvec3(Pf1.x, Pf0.y, Pf0.z)); + T n010 = dot(g010, tvec3(Pf0.x, Pf1.y, Pf0.z)); + T n110 = dot(g110, tvec3(Pf1.x, Pf1.y, Pf0.z)); + T n001 = dot(g001, tvec3(Pf0.x, Pf0.y, Pf1.z)); + T n101 = dot(g101, tvec3(Pf1.x, Pf0.y, Pf1.z)); + T n011 = dot(g011, tvec3(Pf0.x, Pf1.y, Pf1.z)); + T n111 = dot(g111, Pf1); + + tvec3 fade_xyz = fade(Pf0); + tvec4 n_z = mix(tvec4(n000, n100, n010, n110), tvec4(n001, n101, n011, n111), fade_xyz.z); + tvec2 n_yz = mix( + tvec2(n_z.x, n_z.y), + tvec2(n_z.z, n_z.w), fade_xyz.y); + T n_xyz = mix(n_yz.x, n_yz.y, fade_xyz.x); + return T(2.2) * n_xyz; + } + */ + // Classic Perlin noise + template + GLM_FUNC_QUALIFIER T perlin(tvec4 const & Position) + { + tvec4 Pi0 = floor(Position); // Integer part for indexing + tvec4 Pi1 = Pi0 + T(1); // Integer part + 1 + Pi0 = mod(Pi0, tvec4(289)); + Pi1 = mod(Pi1, tvec4(289)); + tvec4 Pf0 = fract(Position); // Fractional part for interpolation + tvec4 Pf1 = Pf0 - T(1); // Fractional part - 1.0 + tvec4 ix(Pi0.x, Pi1.x, Pi0.x, Pi1.x); + tvec4 iy(Pi0.y, Pi0.y, Pi1.y, Pi1.y); + tvec4 iz0(Pi0.z); + tvec4 iz1(Pi1.z); + tvec4 iw0(Pi0.w); + tvec4 iw1(Pi1.w); + + tvec4 ixy = detail::permute(detail::permute(ix) + iy); + tvec4 ixy0 = detail::permute(ixy + iz0); + tvec4 ixy1 = detail::permute(ixy + iz1); + tvec4 ixy00 = detail::permute(ixy0 + iw0); + tvec4 ixy01 = detail::permute(ixy0 + iw1); + tvec4 ixy10 = detail::permute(ixy1 + iw0); + tvec4 ixy11 = detail::permute(ixy1 + iw1); + + tvec4 gx00 = ixy00 / T(7); + tvec4 gy00 = floor(gx00) / T(7); + tvec4 gz00 = floor(gy00) / T(6); + gx00 = fract(gx00) - T(0.5); + gy00 = fract(gy00) - T(0.5); + gz00 = fract(gz00) - T(0.5); + tvec4 gw00 = tvec4(0.75) - abs(gx00) - abs(gy00) - abs(gz00); + tvec4 sw00 = step(gw00, tvec4(0.0)); + gx00 -= sw00 * (step(T(0), gx00) - T(0.5)); + gy00 -= sw00 * (step(T(0), gy00) - T(0.5)); + + tvec4 gx01 = ixy01 / T(7); + tvec4 gy01 = floor(gx01) / T(7); + tvec4 gz01 = floor(gy01) / T(6); + gx01 = fract(gx01) - T(0.5); + gy01 = fract(gy01) - T(0.5); + gz01 = fract(gz01) - T(0.5); + tvec4 gw01 = tvec4(0.75) - abs(gx01) - abs(gy01) - abs(gz01); + tvec4 sw01 = step(gw01, tvec4(0.0)); + gx01 -= sw01 * (step(T(0), gx01) - T(0.5)); + gy01 -= sw01 * (step(T(0), gy01) - T(0.5)); + + tvec4 gx10 = ixy10 / T(7); + tvec4 gy10 = floor(gx10) / T(7); + tvec4 gz10 = floor(gy10) / T(6); + gx10 = fract(gx10) - T(0.5); + gy10 = fract(gy10) - T(0.5); + gz10 = fract(gz10) - T(0.5); + tvec4 gw10 = tvec4(0.75) - abs(gx10) - abs(gy10) - abs(gz10); + tvec4 sw10 = step(gw10, tvec4(0)); + gx10 -= sw10 * (step(T(0), gx10) - T(0.5)); + gy10 -= sw10 * (step(T(0), gy10) - T(0.5)); + + tvec4 gx11 = ixy11 / T(7); + tvec4 gy11 = floor(gx11) / T(7); + tvec4 gz11 = floor(gy11) / T(6); + gx11 = fract(gx11) - T(0.5); + gy11 = fract(gy11) - T(0.5); + gz11 = fract(gz11) - T(0.5); + tvec4 gw11 = tvec4(0.75) - abs(gx11) - abs(gy11) - abs(gz11); + tvec4 sw11 = step(gw11, tvec4(0.0)); + gx11 -= sw11 * (step(T(0), gx11) - T(0.5)); + gy11 -= sw11 * (step(T(0), gy11) - T(0.5)); + + tvec4 g0000(gx00.x, gy00.x, gz00.x, gw00.x); + tvec4 g1000(gx00.y, gy00.y, gz00.y, gw00.y); + tvec4 g0100(gx00.z, gy00.z, gz00.z, gw00.z); + tvec4 g1100(gx00.w, gy00.w, gz00.w, gw00.w); + tvec4 g0010(gx10.x, gy10.x, gz10.x, gw10.x); + tvec4 g1010(gx10.y, gy10.y, gz10.y, gw10.y); + tvec4 g0110(gx10.z, gy10.z, gz10.z, gw10.z); + tvec4 g1110(gx10.w, gy10.w, gz10.w, gw10.w); + tvec4 g0001(gx01.x, gy01.x, gz01.x, gw01.x); + tvec4 g1001(gx01.y, gy01.y, gz01.y, gw01.y); + tvec4 g0101(gx01.z, gy01.z, gz01.z, gw01.z); + tvec4 g1101(gx01.w, gy01.w, gz01.w, gw01.w); + tvec4 g0011(gx11.x, gy11.x, gz11.x, gw11.x); + tvec4 g1011(gx11.y, gy11.y, gz11.y, gw11.y); + tvec4 g0111(gx11.z, gy11.z, gz11.z, gw11.z); + tvec4 g1111(gx11.w, gy11.w, gz11.w, gw11.w); + + tvec4 norm00 = detail::taylorInvSqrt(tvec4(dot(g0000, g0000), dot(g0100, g0100), dot(g1000, g1000), dot(g1100, g1100))); + g0000 *= norm00.x; + g0100 *= norm00.y; + g1000 *= norm00.z; + g1100 *= norm00.w; + + tvec4 norm01 = detail::taylorInvSqrt(tvec4(dot(g0001, g0001), dot(g0101, g0101), dot(g1001, g1001), dot(g1101, g1101))); + g0001 *= norm01.x; + g0101 *= norm01.y; + g1001 *= norm01.z; + g1101 *= norm01.w; + + tvec4 norm10 = detail::taylorInvSqrt(tvec4(dot(g0010, g0010), dot(g0110, g0110), dot(g1010, g1010), dot(g1110, g1110))); + g0010 *= norm10.x; + g0110 *= norm10.y; + g1010 *= norm10.z; + g1110 *= norm10.w; + + tvec4 norm11 = detail::taylorInvSqrt(tvec4(dot(g0011, g0011), dot(g0111, g0111), dot(g1011, g1011), dot(g1111, g1111))); + g0011 *= norm11.x; + g0111 *= norm11.y; + g1011 *= norm11.z; + g1111 *= norm11.w; + + T n0000 = dot(g0000, Pf0); + T n1000 = dot(g1000, tvec4(Pf1.x, Pf0.y, Pf0.z, Pf0.w)); + T n0100 = dot(g0100, tvec4(Pf0.x, Pf1.y, Pf0.z, Pf0.w)); + T n1100 = dot(g1100, tvec4(Pf1.x, Pf1.y, Pf0.z, Pf0.w)); + T n0010 = dot(g0010, tvec4(Pf0.x, Pf0.y, Pf1.z, Pf0.w)); + T n1010 = dot(g1010, tvec4(Pf1.x, Pf0.y, Pf1.z, Pf0.w)); + T n0110 = dot(g0110, tvec4(Pf0.x, Pf1.y, Pf1.z, Pf0.w)); + T n1110 = dot(g1110, tvec4(Pf1.x, Pf1.y, Pf1.z, Pf0.w)); + T n0001 = dot(g0001, tvec4(Pf0.x, Pf0.y, Pf0.z, Pf1.w)); + T n1001 = dot(g1001, tvec4(Pf1.x, Pf0.y, Pf0.z, Pf1.w)); + T n0101 = dot(g0101, tvec4(Pf0.x, Pf1.y, Pf0.z, Pf1.w)); + T n1101 = dot(g1101, tvec4(Pf1.x, Pf1.y, Pf0.z, Pf1.w)); + T n0011 = dot(g0011, tvec4(Pf0.x, Pf0.y, Pf1.z, Pf1.w)); + T n1011 = dot(g1011, tvec4(Pf1.x, Pf0.y, Pf1.z, Pf1.w)); + T n0111 = dot(g0111, tvec4(Pf0.x, Pf1.y, Pf1.z, Pf1.w)); + T n1111 = dot(g1111, Pf1); + + tvec4 fade_xyzw = detail::fade(Pf0); + tvec4 n_0w = mix(tvec4(n0000, n1000, n0100, n1100), tvec4(n0001, n1001, n0101, n1101), fade_xyzw.w); + tvec4 n_1w = mix(tvec4(n0010, n1010, n0110, n1110), tvec4(n0011, n1011, n0111, n1111), fade_xyzw.w); + tvec4 n_zw = mix(n_0w, n_1w, fade_xyzw.z); + tvec2 n_yzw = mix(tvec2(n_zw.x, n_zw.y), tvec2(n_zw.z, n_zw.w), fade_xyzw.y); + T n_xyzw = mix(n_yzw.x, n_yzw.y, fade_xyzw.x); + return T(2.2) * n_xyzw; + } + + // Classic Perlin noise, periodic variant + template + GLM_FUNC_QUALIFIER T perlin(tvec2 const & Position, tvec2 const & rep) + { + tvec4 Pi = floor(tvec4(Position.x, Position.y, Position.x, Position.y)) + tvec4(0.0, 0.0, 1.0, 1.0); + tvec4 Pf = fract(tvec4(Position.x, Position.y, Position.x, Position.y)) - tvec4(0.0, 0.0, 1.0, 1.0); + Pi = mod(Pi, tvec4(rep.x, rep.y, rep.x, rep.y)); // To create noise with explicit period + Pi = mod(Pi, tvec4(289)); // To avoid truncation effects in permutation + tvec4 ix(Pi.x, Pi.z, Pi.x, Pi.z); + tvec4 iy(Pi.y, Pi.y, Pi.w, Pi.w); + tvec4 fx(Pf.x, Pf.z, Pf.x, Pf.z); + tvec4 fy(Pf.y, Pf.y, Pf.w, Pf.w); + + tvec4 i = detail::permute(detail::permute(ix) + iy); + + tvec4 gx = static_cast(2) * fract(i / T(41)) - T(1); + tvec4 gy = abs(gx) - T(0.5); + tvec4 tx = floor(gx + T(0.5)); + gx = gx - tx; + + tvec2 g00(gx.x, gy.x); + tvec2 g10(gx.y, gy.y); + tvec2 g01(gx.z, gy.z); + tvec2 g11(gx.w, gy.w); + + tvec4 norm = detail::taylorInvSqrt(tvec4(dot(g00, g00), dot(g01, g01), dot(g10, g10), dot(g11, g11))); + g00 *= norm.x; + g01 *= norm.y; + g10 *= norm.z; + g11 *= norm.w; + + T n00 = dot(g00, tvec2(fx.x, fy.x)); + T n10 = dot(g10, tvec2(fx.y, fy.y)); + T n01 = dot(g01, tvec2(fx.z, fy.z)); + T n11 = dot(g11, tvec2(fx.w, fy.w)); + + tvec2 fade_xy = detail::fade(tvec2(Pf.x, Pf.y)); + tvec2 n_x = mix(tvec2(n00, n01), tvec2(n10, n11), fade_xy.x); + T n_xy = mix(n_x.x, n_x.y, fade_xy.y); + return T(2.3) * n_xy; + } + + // Classic Perlin noise, periodic variant + template + GLM_FUNC_QUALIFIER T perlin(tvec3 const & Position, tvec3 const & rep) + { + tvec3 Pi0 = mod(floor(Position), rep); // Integer part, modulo period + tvec3 Pi1 = mod(Pi0 + tvec3(T(1)), rep); // Integer part + 1, mod period + Pi0 = mod(Pi0, tvec3(289)); + Pi1 = mod(Pi1, tvec3(289)); + tvec3 Pf0 = fract(Position); // Fractional part for interpolation + tvec3 Pf1 = Pf0 - tvec3(T(1)); // Fractional part - 1.0 + tvec4 ix = tvec4(Pi0.x, Pi1.x, Pi0.x, Pi1.x); + tvec4 iy = tvec4(Pi0.y, Pi0.y, Pi1.y, Pi1.y); + tvec4 iz0(Pi0.z); + tvec4 iz1(Pi1.z); + + tvec4 ixy = detail::permute(detail::permute(ix) + iy); + tvec4 ixy0 = detail::permute(ixy + iz0); + tvec4 ixy1 = detail::permute(ixy + iz1); + + tvec4 gx0 = ixy0 / T(7); + tvec4 gy0 = fract(floor(gx0) / T(7)) - T(0.5); + gx0 = fract(gx0); + tvec4 gz0 = tvec4(0.5) - abs(gx0) - abs(gy0); + tvec4 sz0 = step(gz0, tvec4(0)); + gx0 -= sz0 * (step(T(0), gx0) - T(0.5)); + gy0 -= sz0 * (step(T(0), gy0) - T(0.5)); + + tvec4 gx1 = ixy1 / T(7); + tvec4 gy1 = fract(floor(gx1) / T(7)) - T(0.5); + gx1 = fract(gx1); + tvec4 gz1 = tvec4(0.5) - abs(gx1) - abs(gy1); + tvec4 sz1 = step(gz1, tvec4(T(0))); + gx1 -= sz1 * (step(T(0), gx1) - T(0.5)); + gy1 -= sz1 * (step(T(0), gy1) - T(0.5)); + + tvec3 g000 = tvec3(gx0.x, gy0.x, gz0.x); + tvec3 g100 = tvec3(gx0.y, gy0.y, gz0.y); + tvec3 g010 = tvec3(gx0.z, gy0.z, gz0.z); + tvec3 g110 = tvec3(gx0.w, gy0.w, gz0.w); + tvec3 g001 = tvec3(gx1.x, gy1.x, gz1.x); + tvec3 g101 = tvec3(gx1.y, gy1.y, gz1.y); + tvec3 g011 = tvec3(gx1.z, gy1.z, gz1.z); + tvec3 g111 = tvec3(gx1.w, gy1.w, gz1.w); + + tvec4 norm0 = detail::taylorInvSqrt(tvec4(dot(g000, g000), dot(g010, g010), dot(g100, g100), dot(g110, g110))); + g000 *= norm0.x; + g010 *= norm0.y; + g100 *= norm0.z; + g110 *= norm0.w; + tvec4 norm1 = detail::taylorInvSqrt(tvec4(dot(g001, g001), dot(g011, g011), dot(g101, g101), dot(g111, g111))); + g001 *= norm1.x; + g011 *= norm1.y; + g101 *= norm1.z; + g111 *= norm1.w; + + T n000 = dot(g000, Pf0); + T n100 = dot(g100, tvec3(Pf1.x, Pf0.y, Pf0.z)); + T n010 = dot(g010, tvec3(Pf0.x, Pf1.y, Pf0.z)); + T n110 = dot(g110, tvec3(Pf1.x, Pf1.y, Pf0.z)); + T n001 = dot(g001, tvec3(Pf0.x, Pf0.y, Pf1.z)); + T n101 = dot(g101, tvec3(Pf1.x, Pf0.y, Pf1.z)); + T n011 = dot(g011, tvec3(Pf0.x, Pf1.y, Pf1.z)); + T n111 = dot(g111, Pf1); + + tvec3 fade_xyz = detail::fade(Pf0); + tvec4 n_z = mix(tvec4(n000, n100, n010, n110), tvec4(n001, n101, n011, n111), fade_xyz.z); + tvec2 n_yz = mix(tvec2(n_z.x, n_z.y), tvec2(n_z.z, n_z.w), fade_xyz.y); + T n_xyz = mix(n_yz.x, n_yz.y, fade_xyz.x); + return T(2.2) * n_xyz; + } + + // Classic Perlin noise, periodic version + template + GLM_FUNC_QUALIFIER T perlin(tvec4 const & Position, tvec4 const & rep) + { + tvec4 Pi0 = mod(floor(Position), rep); // Integer part modulo rep + tvec4 Pi1 = mod(Pi0 + T(1), rep); // Integer part + 1 mod rep + tvec4 Pf0 = fract(Position); // Fractional part for interpolation + tvec4 Pf1 = Pf0 - T(1); // Fractional part - 1.0 + tvec4 ix = tvec4(Pi0.x, Pi1.x, Pi0.x, Pi1.x); + tvec4 iy = tvec4(Pi0.y, Pi0.y, Pi1.y, Pi1.y); + tvec4 iz0(Pi0.z); + tvec4 iz1(Pi1.z); + tvec4 iw0(Pi0.w); + tvec4 iw1(Pi1.w); + + tvec4 ixy = detail::permute(detail::permute(ix) + iy); + tvec4 ixy0 = detail::permute(ixy + iz0); + tvec4 ixy1 = detail::permute(ixy + iz1); + tvec4 ixy00 = detail::permute(ixy0 + iw0); + tvec4 ixy01 = detail::permute(ixy0 + iw1); + tvec4 ixy10 = detail::permute(ixy1 + iw0); + tvec4 ixy11 = detail::permute(ixy1 + iw1); + + tvec4 gx00 = ixy00 / T(7); + tvec4 gy00 = floor(gx00) / T(7); + tvec4 gz00 = floor(gy00) / T(6); + gx00 = fract(gx00) - T(0.5); + gy00 = fract(gy00) - T(0.5); + gz00 = fract(gz00) - T(0.5); + tvec4 gw00 = tvec4(0.75) - abs(gx00) - abs(gy00) - abs(gz00); + tvec4 sw00 = step(gw00, tvec4(0)); + gx00 -= sw00 * (step(T(0), gx00) - T(0.5)); + gy00 -= sw00 * (step(T(0), gy00) - T(0.5)); + + tvec4 gx01 = ixy01 / T(7); + tvec4 gy01 = floor(gx01) / T(7); + tvec4 gz01 = floor(gy01) / T(6); + gx01 = fract(gx01) - T(0.5); + gy01 = fract(gy01) - T(0.5); + gz01 = fract(gz01) - T(0.5); + tvec4 gw01 = tvec4(0.75) - abs(gx01) - abs(gy01) - abs(gz01); + tvec4 sw01 = step(gw01, tvec4(0.0)); + gx01 -= sw01 * (step(T(0), gx01) - T(0.5)); + gy01 -= sw01 * (step(T(0), gy01) - T(0.5)); + + tvec4 gx10 = ixy10 / T(7); + tvec4 gy10 = floor(gx10) / T(7); + tvec4 gz10 = floor(gy10) / T(6); + gx10 = fract(gx10) - T(0.5); + gy10 = fract(gy10) - T(0.5); + gz10 = fract(gz10) - T(0.5); + tvec4 gw10 = tvec4(0.75) - abs(gx10) - abs(gy10) - abs(gz10); + tvec4 sw10 = step(gw10, tvec4(0.0)); + gx10 -= sw10 * (step(T(0), gx10) - T(0.5)); + gy10 -= sw10 * (step(T(0), gy10) - T(0.5)); + + tvec4 gx11 = ixy11 / T(7); + tvec4 gy11 = floor(gx11) / T(7); + tvec4 gz11 = floor(gy11) / T(6); + gx11 = fract(gx11) - T(0.5); + gy11 = fract(gy11) - T(0.5); + gz11 = fract(gz11) - T(0.5); + tvec4 gw11 = tvec4(0.75) - abs(gx11) - abs(gy11) - abs(gz11); + tvec4 sw11 = step(gw11, tvec4(T(0))); + gx11 -= sw11 * (step(T(0), gx11) - T(0.5)); + gy11 -= sw11 * (step(T(0), gy11) - T(0.5)); + + tvec4 g0000(gx00.x, gy00.x, gz00.x, gw00.x); + tvec4 g1000(gx00.y, gy00.y, gz00.y, gw00.y); + tvec4 g0100(gx00.z, gy00.z, gz00.z, gw00.z); + tvec4 g1100(gx00.w, gy00.w, gz00.w, gw00.w); + tvec4 g0010(gx10.x, gy10.x, gz10.x, gw10.x); + tvec4 g1010(gx10.y, gy10.y, gz10.y, gw10.y); + tvec4 g0110(gx10.z, gy10.z, gz10.z, gw10.z); + tvec4 g1110(gx10.w, gy10.w, gz10.w, gw10.w); + tvec4 g0001(gx01.x, gy01.x, gz01.x, gw01.x); + tvec4 g1001(gx01.y, gy01.y, gz01.y, gw01.y); + tvec4 g0101(gx01.z, gy01.z, gz01.z, gw01.z); + tvec4 g1101(gx01.w, gy01.w, gz01.w, gw01.w); + tvec4 g0011(gx11.x, gy11.x, gz11.x, gw11.x); + tvec4 g1011(gx11.y, gy11.y, gz11.y, gw11.y); + tvec4 g0111(gx11.z, gy11.z, gz11.z, gw11.z); + tvec4 g1111(gx11.w, gy11.w, gz11.w, gw11.w); + + tvec4 norm00 = detail::taylorInvSqrt(tvec4(dot(g0000, g0000), dot(g0100, g0100), dot(g1000, g1000), dot(g1100, g1100))); + g0000 *= norm00.x; + g0100 *= norm00.y; + g1000 *= norm00.z; + g1100 *= norm00.w; + + tvec4 norm01 = detail::taylorInvSqrt(tvec4(dot(g0001, g0001), dot(g0101, g0101), dot(g1001, g1001), dot(g1101, g1101))); + g0001 *= norm01.x; + g0101 *= norm01.y; + g1001 *= norm01.z; + g1101 *= norm01.w; + + tvec4 norm10 = detail::taylorInvSqrt(tvec4(dot(g0010, g0010), dot(g0110, g0110), dot(g1010, g1010), dot(g1110, g1110))); + g0010 *= norm10.x; + g0110 *= norm10.y; + g1010 *= norm10.z; + g1110 *= norm10.w; + + tvec4 norm11 = detail::taylorInvSqrt(tvec4(dot(g0011, g0011), dot(g0111, g0111), dot(g1011, g1011), dot(g1111, g1111))); + g0011 *= norm11.x; + g0111 *= norm11.y; + g1011 *= norm11.z; + g1111 *= norm11.w; + + T n0000 = dot(g0000, Pf0); + T n1000 = dot(g1000, tvec4(Pf1.x, Pf0.y, Pf0.z, Pf0.w)); + T n0100 = dot(g0100, tvec4(Pf0.x, Pf1.y, Pf0.z, Pf0.w)); + T n1100 = dot(g1100, tvec4(Pf1.x, Pf1.y, Pf0.z, Pf0.w)); + T n0010 = dot(g0010, tvec4(Pf0.x, Pf0.y, Pf1.z, Pf0.w)); + T n1010 = dot(g1010, tvec4(Pf1.x, Pf0.y, Pf1.z, Pf0.w)); + T n0110 = dot(g0110, tvec4(Pf0.x, Pf1.y, Pf1.z, Pf0.w)); + T n1110 = dot(g1110, tvec4(Pf1.x, Pf1.y, Pf1.z, Pf0.w)); + T n0001 = dot(g0001, tvec4(Pf0.x, Pf0.y, Pf0.z, Pf1.w)); + T n1001 = dot(g1001, tvec4(Pf1.x, Pf0.y, Pf0.z, Pf1.w)); + T n0101 = dot(g0101, tvec4(Pf0.x, Pf1.y, Pf0.z, Pf1.w)); + T n1101 = dot(g1101, tvec4(Pf1.x, Pf1.y, Pf0.z, Pf1.w)); + T n0011 = dot(g0011, tvec4(Pf0.x, Pf0.y, Pf1.z, Pf1.w)); + T n1011 = dot(g1011, tvec4(Pf1.x, Pf0.y, Pf1.z, Pf1.w)); + T n0111 = dot(g0111, tvec4(Pf0.x, Pf1.y, Pf1.z, Pf1.w)); + T n1111 = dot(g1111, Pf1); + + tvec4 fade_xyzw = detail::fade(Pf0); + tvec4 n_0w = mix(tvec4(n0000, n1000, n0100, n1100), tvec4(n0001, n1001, n0101, n1101), fade_xyzw.w); + tvec4 n_1w = mix(tvec4(n0010, n1010, n0110, n1110), tvec4(n0011, n1011, n0111, n1111), fade_xyzw.w); + tvec4 n_zw = mix(n_0w, n_1w, fade_xyzw.z); + tvec2 n_yzw = mix(tvec2(n_zw.x, n_zw.y), tvec2(n_zw.z, n_zw.w), fade_xyzw.y); + T n_xyzw = mix(n_yzw.x, n_yzw.y, fade_xyzw.x); + return T(2.2) * n_xyzw; + } + + template + GLM_FUNC_QUALIFIER T simplex(glm::tvec2 const & v) + { + tvec4 const C = tvec4( + T( 0.211324865405187), // (3.0 - sqrt(3.0)) / 6.0 + T( 0.366025403784439), // 0.5 * (sqrt(3.0) - 1.0) + T(-0.577350269189626), // -1.0 + 2.0 * C.x + T( 0.024390243902439)); // 1.0 / 41.0 + + // First corner + tvec2 i = floor(v + dot(v, tvec2(C[1]))); + tvec2 x0 = v - i + dot(i, tvec2(C[0])); + + // Other corners + //i1.x = step( x0.y, x0.x ); // x0.x > x0.y ? 1.0 : 0.0 + //i1.y = 1.0 - i1.x; + tvec2 i1 = (x0.x > x0.y) ? tvec2(1, 0) : tvec2(0, 1); + // x0 = x0 - 0.0 + 0.0 * C.xx ; + // x1 = x0 - i1 + 1.0 * C.xx ; + // x2 = x0 - 1.0 + 2.0 * C.xx ; + tvec4 x12 = tvec4(x0.x, x0.y, x0.x, x0.y) + tvec4(C.x, C.x, C.z, C.z); + x12 = tvec4(tvec2(x12) - i1, x12.z, x12.w); + + // Permutations + i = mod(i, tvec2(289)); // Avoid truncation effects in permutation + tvec3 p = detail::permute( + detail::permute(i.y + tvec3(T(0), i1.y, T(1))) + + i.x + tvec3(T(0), i1.x, T(1))); + + tvec3 m = max(tvec3(0.5) - tvec3( + dot(x0, x0), + dot(tvec2(x12.x, x12.y), tvec2(x12.x, x12.y)), + dot(tvec2(x12.z, x12.w), tvec2(x12.z, x12.w))), tvec3(0)); + m = m * m ; + m = m * m ; + + // Gradients: 41 points uniformly over a line, mapped onto a diamond. + // The ring size 17*17 = 289 is close to a multiple of 41 (41*7 = 287) + + tvec3 x = static_cast(2) * fract(p * C.w) - T(1); + tvec3 h = abs(x) - T(0.5); + tvec3 ox = floor(x + T(0.5)); + tvec3 a0 = x - ox; + + // Normalise gradients implicitly by scaling m + // Inlined for speed: m *= taylorInvSqrt( a0*a0 + h*h ); + m *= static_cast(1.79284291400159) - T(0.85373472095314) * (a0 * a0 + h * h); + + // Compute final noise value at P + tvec3 g; + g.x = a0.x * x0.x + h.x * x0.y; + //g.yz = a0.yz * x12.xz + h.yz * x12.yw; + g.y = a0.y * x12.x + h.y * x12.y; + g.z = a0.z * x12.z + h.z * x12.w; + return T(130) * dot(m, g); + } + + template + GLM_FUNC_QUALIFIER T simplex(tvec3 const & v) + { + tvec2 const C(1.0 / 6.0, 1.0 / 3.0); + tvec4 const D(0.0, 0.5, 1.0, 2.0); + + // First corner + tvec3 i(floor(v + dot(v, tvec3(C.y)))); + tvec3 x0(v - i + dot(i, tvec3(C.x))); + + // Other corners + tvec3 g(step(tvec3(x0.y, x0.z, x0.x), x0)); + tvec3 l(T(1) - g); + tvec3 i1(min(g, tvec3(l.z, l.x, l.y))); + tvec3 i2(max(g, tvec3(l.z, l.x, l.y))); + + // x0 = x0 - 0.0 + 0.0 * C.xxx; + // x1 = x0 - i1 + 1.0 * C.xxx; + // x2 = x0 - i2 + 2.0 * C.xxx; + // x3 = x0 - 1.0 + 3.0 * C.xxx; + tvec3 x1(x0 - i1 + C.x); + tvec3 x2(x0 - i2 + C.y); // 2.0*C.x = 1/3 = C.y + tvec3 x3(x0 - D.y); // -1.0+3.0*C.x = -0.5 = -D.y + + // Permutations + i = detail::mod289(i); + tvec4 p(detail::permute(detail::permute(detail::permute( + i.z + tvec4(T(0), i1.z, i2.z, T(1))) + + i.y + tvec4(T(0), i1.y, i2.y, T(1))) + + i.x + tvec4(T(0), i1.x, i2.x, T(1)))); + + // Gradients: 7x7 points over a square, mapped onto an octahedron. + // The ring size 17*17 = 289 is close to a multiple of 49 (49*6 = 294) + T n_ = static_cast(0.142857142857); // 1.0/7.0 + tvec3 ns(n_ * tvec3(D.w, D.y, D.z) - tvec3(D.x, D.z, D.x)); + + tvec4 j(p - T(49) * floor(p * ns.z * ns.z)); // mod(p,7*7) + + tvec4 x_(floor(j * ns.z)); + tvec4 y_(floor(j - T(7) * x_)); // mod(j,N) + + tvec4 x(x_ * ns.x + ns.y); + tvec4 y(y_ * ns.x + ns.y); + tvec4 h(T(1) - abs(x) - abs(y)); + + tvec4 b0(x.x, x.y, y.x, y.y); + tvec4 b1(x.z, x.w, y.z, y.w); + + // vec4 s0 = vec4(lessThan(b0,0.0))*2.0 - 1.0; + // vec4 s1 = vec4(lessThan(b1,0.0))*2.0 - 1.0; + tvec4 s0(floor(b0) * T(2) + T(1)); + tvec4 s1(floor(b1) * T(2) + T(1)); + tvec4 sh(-step(h, tvec4(0.0))); + + tvec4 a0 = tvec4(b0.x, b0.z, b0.y, b0.w) + tvec4(s0.x, s0.z, s0.y, s0.w) * tvec4(sh.x, sh.x, sh.y, sh.y); + tvec4 a1 = tvec4(b1.x, b1.z, b1.y, b1.w) + tvec4(s1.x, s1.z, s1.y, s1.w) * tvec4(sh.z, sh.z, sh.w, sh.w); + + tvec3 p0(a0.x, a0.y, h.x); + tvec3 p1(a0.z, a0.w, h.y); + tvec3 p2(a1.x, a1.y, h.z); + tvec3 p3(a1.z, a1.w, h.w); + + // Normalise gradients + tvec4 norm = detail::taylorInvSqrt(tvec4(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3))); + p0 *= norm.x; + p1 *= norm.y; + p2 *= norm.z; + p3 *= norm.w; + + // Mix final noise value + tvec4 m = max(T(0.6) - tvec4(dot(x0, x0), dot(x1, x1), dot(x2, x2), dot(x3, x3)), tvec4(0)); + m = m * m; + return T(42) * dot(m * m, tvec4(dot(p0, x0), dot(p1, x1), dot(p2, x2), dot(p3, x3))); + } + + template + GLM_FUNC_QUALIFIER T simplex(tvec4 const & v) + { + tvec4 const C( + 0.138196601125011, // (5 - sqrt(5))/20 G4 + 0.276393202250021, // 2 * G4 + 0.414589803375032, // 3 * G4 + -0.447213595499958); // -1 + 4 * G4 + + // (sqrt(5) - 1)/4 = F4, used once below + T const F4 = static_cast(0.309016994374947451); + + // First corner + tvec4 i = floor(v + dot(v, vec4(F4))); + tvec4 x0 = v - i + dot(i, vec4(C.x)); + + // Other corners + + // Rank sorting originally contributed by Bill Licea-Kane, AMD (formerly ATI) + tvec4 i0; + tvec3 isX = step(tvec3(x0.y, x0.z, x0.w), tvec3(x0.x)); + tvec3 isYZ = step(tvec3(x0.z, x0.w, x0.w), tvec3(x0.y, x0.y, x0.z)); + // i0.x = dot(isX, vec3(1.0)); + //i0.x = isX.x + isX.y + isX.z; + //i0.yzw = static_cast(1) - isX; + i0 = tvec4(isX.x + isX.y + isX.z, T(1) - isX); + // i0.y += dot(isYZ.xy, vec2(1.0)); + i0.y += isYZ.x + isYZ.y; + //i0.zw += 1.0 - tvec2(isYZ.x, isYZ.y); + i0.z += static_cast(1) - isYZ.x; + i0.w += static_cast(1) - isYZ.y; + i0.z += isYZ.z; + i0.w += static_cast(1) - isYZ.z; + + // i0 now contains the unique values 0,1,2,3 in each channel + tvec4 i3 = clamp(i0, T(0), T(1)); + tvec4 i2 = clamp(i0 - T(1), T(0), T(1)); + tvec4 i1 = clamp(i0 - T(2), T(0), T(1)); + + // x0 = x0 - 0.0 + 0.0 * C.xxxx + // x1 = x0 - i1 + 0.0 * C.xxxx + // x2 = x0 - i2 + 0.0 * C.xxxx + // x3 = x0 - i3 + 0.0 * C.xxxx + // x4 = x0 - 1.0 + 4.0 * C.xxxx + tvec4 x1 = x0 - i1 + C.x; + tvec4 x2 = x0 - i2 + C.y; + tvec4 x3 = x0 - i3 + C.z; + tvec4 x4 = x0 + C.w; + + // Permutations + i = mod(i, tvec4(289)); + T j0 = detail::permute(detail::permute(detail::permute(detail::permute(i.w) + i.z) + i.y) + i.x); + tvec4 j1 = detail::permute(detail::permute(detail::permute(detail::permute( + i.w + tvec4(i1.w, i2.w, i3.w, T(1))) + + i.z + tvec4(i1.z, i2.z, i3.z, T(1))) + + i.y + tvec4(i1.y, i2.y, i3.y, T(1))) + + i.x + tvec4(i1.x, i2.x, i3.x, T(1))); + + // Gradients: 7x7x6 points over a cube, mapped onto a 4-cross polytope + // 7*7*6 = 294, which is close to the ring size 17*17 = 289. + tvec4 ip = tvec4(T(1) / T(294), T(1) / T(49), T(1) / T(7), T(0)); + + tvec4 p0 = gtc::grad4(j0, ip); + tvec4 p1 = gtc::grad4(j1.x, ip); + tvec4 p2 = gtc::grad4(j1.y, ip); + tvec4 p3 = gtc::grad4(j1.z, ip); + tvec4 p4 = gtc::grad4(j1.w, ip); + + // Normalise gradients + tvec4 norm = detail::taylorInvSqrt(tvec4(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3))); + p0 *= norm.x; + p1 *= norm.y; + p2 *= norm.z; + p3 *= norm.w; + p4 *= detail::taylorInvSqrt(dot(p4, p4)); + + // Mix contributions from the five corners + tvec3 m0 = max(T(0.6) - tvec3(dot(x0, x0), dot(x1, x1), dot(x2, x2)), tvec3(0)); + tvec2 m1 = max(T(0.6) - tvec2(dot(x3, x3), dot(x4, x4) ), tvec2(0)); + m0 = m0 * m0; + m1 = m1 * m1; + return T(49) * + (dot(m0 * m0, tvec3(dot(p0, x0), dot(p1, x1), dot(p2, x2))) + + dot(m1 * m1, tvec2(dot(p3, x3), dot(p4, x4)))); + } +}//namespace glm diff --git a/external/include/glm/gtc/packing.hpp b/external/include/glm/gtc/packing.hpp new file mode 100644 index 0000000..1389d95 --- /dev/null +++ b/external/include/glm/gtc/packing.hpp @@ -0,0 +1,579 @@ +/// @ref gtc_packing +/// @file glm/gtc/packing.hpp +/// +/// @see core (dependence) +/// +/// @defgroup gtc_packing GLM_GTC_packing +/// @ingroup gtc +/// +/// @brief This extension provides a set of function to convert vertors to packed +/// formats. +/// +/// need to be included to use these features. + +#pragma once + +// Dependency: +#include "type_precision.hpp" + +#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED) +# pragma message("GLM: GLM_GTC_packing extension included") +#endif + +namespace glm +{ + /// @addtogroup gtc_packing + /// @{ + + /// First, converts the normalized floating-point value v into a 8-bit integer value. + /// Then, the results are packed into the returned 8-bit unsigned integer. + /// + /// The conversion for component c of v to fixed point is done as follows: + /// packUnorm1x8: round(clamp(c, 0, +1) * 255.0) + /// + /// @see gtc_packing + /// @see uint16 packUnorm2x8(vec2 const & v) + /// @see uint32 packUnorm4x8(vec4 const & v) + /// @see GLSL packUnorm4x8 man page + /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions + GLM_FUNC_DECL uint8 packUnorm1x8(float v); + + /// Convert a single 8-bit integer to a normalized floating-point value. + /// + /// The conversion for unpacked fixed-point value f to floating point is done as follows: + /// unpackUnorm4x8: f / 255.0 + /// + /// @see gtc_packing + /// @see vec2 unpackUnorm2x8(uint16 p) + /// @see vec4 unpackUnorm4x8(uint32 p) + /// @see GLSL unpackUnorm4x8 man page + /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions + GLM_FUNC_DECL float unpackUnorm1x8(uint8 p); + + /// First, converts each component of the normalized floating-point value v into 8-bit integer values. + /// Then, the results are packed into the returned 16-bit unsigned integer. + /// + /// The conversion for component c of v to fixed point is done as follows: + /// packUnorm2x8: round(clamp(c, 0, +1) * 255.0) + /// + /// The first component of the vector will be written to the least significant bits of the output; + /// the last component will be written to the most significant bits. + /// + /// @see gtc_packing + /// @see uint8 packUnorm1x8(float const & v) + /// @see uint32 packUnorm4x8(vec4 const & v) + /// @see GLSL packUnorm4x8 man page + /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions + GLM_FUNC_DECL uint16 packUnorm2x8(vec2 const & v); + + /// First, unpacks a single 16-bit unsigned integer p into a pair of 8-bit unsigned integers. + /// Then, each component is converted to a normalized floating-point value to generate the returned two-component vector. + /// + /// The conversion for unpacked fixed-point value f to floating point is done as follows: + /// unpackUnorm4x8: f / 255.0 + /// + /// The first component of the returned vector will be extracted from the least significant bits of the input; + /// the last component will be extracted from the most significant bits. + /// + /// @see gtc_packing + /// @see float unpackUnorm1x8(uint8 v) + /// @see vec4 unpackUnorm4x8(uint32 p) + /// @see GLSL unpackUnorm4x8 man page + /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions + GLM_FUNC_DECL vec2 unpackUnorm2x8(uint16 p); + + /// First, converts the normalized floating-point value v into 8-bit integer value. + /// Then, the results are packed into the returned 8-bit unsigned integer. + /// + /// The conversion to fixed point is done as follows: + /// packSnorm1x8: round(clamp(s, -1, +1) * 127.0) + /// + /// @see gtc_packing + /// @see uint16 packSnorm2x8(vec2 const & v) + /// @see uint32 packSnorm4x8(vec4 const & v) + /// @see GLSL packSnorm4x8 man page + /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions + GLM_FUNC_DECL uint8 packSnorm1x8(float s); + + /// First, unpacks a single 8-bit unsigned integer p into a single 8-bit signed integers. + /// Then, the value is converted to a normalized floating-point value to generate the returned scalar. + /// + /// The conversion for unpacked fixed-point value f to floating point is done as follows: + /// unpackSnorm1x8: clamp(f / 127.0, -1, +1) + /// + /// @see gtc_packing + /// @see vec2 unpackSnorm2x8(uint16 p) + /// @see vec4 unpackSnorm4x8(uint32 p) + /// @see GLSL unpackSnorm4x8 man page + /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions + GLM_FUNC_DECL float unpackSnorm1x8(uint8 p); + + /// First, converts each component of the normalized floating-point value v into 8-bit integer values. + /// Then, the results are packed into the returned 16-bit unsigned integer. + /// + /// The conversion for component c of v to fixed point is done as follows: + /// packSnorm2x8: round(clamp(c, -1, +1) * 127.0) + /// + /// The first component of the vector will be written to the least significant bits of the output; + /// the last component will be written to the most significant bits. + /// + /// @see gtc_packing + /// @see uint8 packSnorm1x8(float const & v) + /// @see uint32 packSnorm4x8(vec4 const & v) + /// @see GLSL packSnorm4x8 man page + /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions + GLM_FUNC_DECL uint16 packSnorm2x8(vec2 const & v); + + /// First, unpacks a single 16-bit unsigned integer p into a pair of 8-bit signed integers. + /// Then, each component is converted to a normalized floating-point value to generate the returned two-component vector. + /// + /// The conversion for unpacked fixed-point value f to floating point is done as follows: + /// unpackSnorm2x8: clamp(f / 127.0, -1, +1) + /// + /// The first component of the returned vector will be extracted from the least significant bits of the input; + /// the last component will be extracted from the most significant bits. + /// + /// @see gtc_packing + /// @see float unpackSnorm1x8(uint8 p) + /// @see vec4 unpackSnorm4x8(uint32 p) + /// @see GLSL unpackSnorm4x8 man page + /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions + GLM_FUNC_DECL vec2 unpackSnorm2x8(uint16 p); + + /// First, converts the normalized floating-point value v into a 16-bit integer value. + /// Then, the results are packed into the returned 16-bit unsigned integer. + /// + /// The conversion for component c of v to fixed point is done as follows: + /// packUnorm1x16: round(clamp(c, 0, +1) * 65535.0) + /// + /// @see gtc_packing + /// @see uint16 packSnorm1x16(float const & v) + /// @see uint64 packSnorm4x16(vec4 const & v) + /// @see GLSL packUnorm4x8 man page + /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions + GLM_FUNC_DECL uint16 packUnorm1x16(float v); + + /// First, unpacks a single 16-bit unsigned integer p into a of 16-bit unsigned integers. + /// Then, the value is converted to a normalized floating-point value to generate the returned scalar. + /// + /// The conversion for unpacked fixed-point value f to floating point is done as follows: + /// unpackUnorm1x16: f / 65535.0 + /// + /// @see gtc_packing + /// @see vec2 unpackUnorm2x16(uint32 p) + /// @see vec4 unpackUnorm4x16(uint64 p) + /// @see GLSL unpackUnorm2x16 man page + /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions + GLM_FUNC_DECL float unpackUnorm1x16(uint16 p); + + /// First, converts each component of the normalized floating-point value v into 16-bit integer values. + /// Then, the results are packed into the returned 64-bit unsigned integer. + /// + /// The conversion for component c of v to fixed point is done as follows: + /// packUnorm4x16: round(clamp(c, 0, +1) * 65535.0) + /// + /// The first component of the vector will be written to the least significant bits of the output; + /// the last component will be written to the most significant bits. + /// + /// @see gtc_packing + /// @see uint16 packUnorm1x16(float const & v) + /// @see uint32 packUnorm2x16(vec2 const & v) + /// @see GLSL packUnorm4x8 man page + /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions + GLM_FUNC_DECL uint64 packUnorm4x16(vec4 const & v); + + /// First, unpacks a single 64-bit unsigned integer p into four 16-bit unsigned integers. + /// Then, each component is converted to a normalized floating-point value to generate the returned four-component vector. + /// + /// The conversion for unpacked fixed-point value f to floating point is done as follows: + /// unpackUnormx4x16: f / 65535.0 + /// + /// The first component of the returned vector will be extracted from the least significant bits of the input; + /// the last component will be extracted from the most significant bits. + /// + /// @see gtc_packing + /// @see float unpackUnorm1x16(uint16 p) + /// @see vec2 unpackUnorm2x16(uint32 p) + /// @see GLSL unpackUnorm2x16 man page + /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions + GLM_FUNC_DECL vec4 unpackUnorm4x16(uint64 p); + + /// First, converts the normalized floating-point value v into 16-bit integer value. + /// Then, the results are packed into the returned 16-bit unsigned integer. + /// + /// The conversion to fixed point is done as follows: + /// packSnorm1x8: round(clamp(s, -1, +1) * 32767.0) + /// + /// @see gtc_packing + /// @see uint32 packSnorm2x16(vec2 const & v) + /// @see uint64 packSnorm4x16(vec4 const & v) + /// @see GLSL packSnorm4x8 man page + /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions + GLM_FUNC_DECL uint16 packSnorm1x16(float v); + + /// First, unpacks a single 16-bit unsigned integer p into a single 16-bit signed integers. + /// Then, each component is converted to a normalized floating-point value to generate the returned scalar. + /// + /// The conversion for unpacked fixed-point value f to floating point is done as follows: + /// unpackSnorm1x16: clamp(f / 32767.0, -1, +1) + /// + /// @see gtc_packing + /// @see vec2 unpackSnorm2x16(uint32 p) + /// @see vec4 unpackSnorm4x16(uint64 p) + /// @see GLSL unpackSnorm4x8 man page + /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions + GLM_FUNC_DECL float unpackSnorm1x16(uint16 p); + + /// First, converts each component of the normalized floating-point value v into 16-bit integer values. + /// Then, the results are packed into the returned 64-bit unsigned integer. + /// + /// The conversion for component c of v to fixed point is done as follows: + /// packSnorm2x8: round(clamp(c, -1, +1) * 32767.0) + /// + /// The first component of the vector will be written to the least significant bits of the output; + /// the last component will be written to the most significant bits. + /// + /// @see gtc_packing + /// @see uint16 packSnorm1x16(float const & v) + /// @see uint32 packSnorm2x16(vec2 const & v) + /// @see GLSL packSnorm4x8 man page + /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions + GLM_FUNC_DECL uint64 packSnorm4x16(vec4 const & v); + + /// First, unpacks a single 64-bit unsigned integer p into four 16-bit signed integers. + /// Then, each component is converted to a normalized floating-point value to generate the returned four-component vector. + /// + /// The conversion for unpacked fixed-point value f to floating point is done as follows: + /// unpackSnorm4x16: clamp(f / 32767.0, -1, +1) + /// + /// The first component of the returned vector will be extracted from the least significant bits of the input; + /// the last component will be extracted from the most significant bits. + /// + /// @see gtc_packing + /// @see float unpackSnorm1x16(uint16 p) + /// @see vec2 unpackSnorm2x16(uint32 p) + /// @see GLSL unpackSnorm4x8 man page + /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions + GLM_FUNC_DECL vec4 unpackSnorm4x16(uint64 p); + + /// Returns an unsigned integer obtained by converting the components of a floating-point scalar + /// to the 16-bit floating-point representation found in the OpenGL Specification, + /// and then packing this 16-bit value into a 16-bit unsigned integer. + /// + /// @see gtc_packing + /// @see uint32 packHalf2x16(vec2 const & v) + /// @see uint64 packHalf4x16(vec4 const & v) + /// @see GLSL packHalf2x16 man page + /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions + GLM_FUNC_DECL uint16 packHalf1x16(float v); + + /// Returns a floating-point scalar with components obtained by unpacking a 16-bit unsigned integer into a 16-bit value, + /// interpreted as a 16-bit floating-point number according to the OpenGL Specification, + /// and converting it to 32-bit floating-point values. + /// + /// @see gtc_packing + /// @see vec2 unpackHalf2x16(uint32 const & v) + /// @see vec4 unpackHalf4x16(uint64 const & v) + /// @see GLSL unpackHalf2x16 man page + /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions + GLM_FUNC_DECL float unpackHalf1x16(uint16 v); + + /// Returns an unsigned integer obtained by converting the components of a four-component floating-point vector + /// to the 16-bit floating-point representation found in the OpenGL Specification, + /// and then packing these four 16-bit values into a 64-bit unsigned integer. + /// The first vector component specifies the 16 least-significant bits of the result; + /// the forth component specifies the 16 most-significant bits. + /// + /// @see gtc_packing + /// @see uint16 packHalf1x16(float const & v) + /// @see uint32 packHalf2x16(vec2 const & v) + /// @see GLSL packHalf2x16 man page + /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions + GLM_FUNC_DECL uint64 packHalf4x16(vec4 const & v); + + /// Returns a four-component floating-point vector with components obtained by unpacking a 64-bit unsigned integer into four 16-bit values, + /// interpreting those values as 16-bit floating-point numbers according to the OpenGL Specification, + /// and converting them to 32-bit floating-point values. + /// The first component of the vector is obtained from the 16 least-significant bits of v; + /// the forth component is obtained from the 16 most-significant bits of v. + /// + /// @see gtc_packing + /// @see float unpackHalf1x16(uint16 const & v) + /// @see vec2 unpackHalf2x16(uint32 const & v) + /// @see GLSL unpackHalf2x16 man page + /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions + GLM_FUNC_DECL vec4 unpackHalf4x16(uint64 p); + + /// Returns an unsigned integer obtained by converting the components of a four-component signed integer vector + /// to the 10-10-10-2-bit signed integer representation found in the OpenGL Specification, + /// and then packing these four values into a 32-bit unsigned integer. + /// The first vector component specifies the 10 least-significant bits of the result; + /// the forth component specifies the 2 most-significant bits. + /// + /// @see gtc_packing + /// @see uint32 packI3x10_1x2(uvec4 const & v) + /// @see uint32 packSnorm3x10_1x2(vec4 const & v) + /// @see uint32 packUnorm3x10_1x2(vec4 const & v) + /// @see ivec4 unpackI3x10_1x2(uint32 const & p) + GLM_FUNC_DECL uint32 packI3x10_1x2(ivec4 const & v); + + /// Unpacks a single 32-bit unsigned integer p into three 10-bit and one 2-bit signed integers. + /// + /// The first component of the returned vector will be extracted from the least significant bits of the input; + /// the last component will be extracted from the most significant bits. + /// + /// @see gtc_packing + /// @see uint32 packU3x10_1x2(uvec4 const & v) + /// @see vec4 unpackSnorm3x10_1x2(uint32 const & p); + /// @see uvec4 unpackI3x10_1x2(uint32 const & p); + GLM_FUNC_DECL ivec4 unpackI3x10_1x2(uint32 p); + + /// Returns an unsigned integer obtained by converting the components of a four-component unsigned integer vector + /// to the 10-10-10-2-bit unsigned integer representation found in the OpenGL Specification, + /// and then packing these four values into a 32-bit unsigned integer. + /// The first vector component specifies the 10 least-significant bits of the result; + /// the forth component specifies the 2 most-significant bits. + /// + /// @see gtc_packing + /// @see uint32 packI3x10_1x2(ivec4 const & v) + /// @see uint32 packSnorm3x10_1x2(vec4 const & v) + /// @see uint32 packUnorm3x10_1x2(vec4 const & v) + /// @see ivec4 unpackU3x10_1x2(uint32 const & p) + GLM_FUNC_DECL uint32 packU3x10_1x2(uvec4 const & v); + + /// Unpacks a single 32-bit unsigned integer p into three 10-bit and one 2-bit unsigned integers. + /// + /// The first component of the returned vector will be extracted from the least significant bits of the input; + /// the last component will be extracted from the most significant bits. + /// + /// @see gtc_packing + /// @see uint32 packU3x10_1x2(uvec4 const & v) + /// @see vec4 unpackSnorm3x10_1x2(uint32 const & p); + /// @see uvec4 unpackI3x10_1x2(uint32 const & p); + GLM_FUNC_DECL uvec4 unpackU3x10_1x2(uint32 p); + + /// First, converts the first three components of the normalized floating-point value v into 10-bit signed integer values. + /// Then, converts the forth component of the normalized floating-point value v into 2-bit signed integer values. + /// Then, the results are packed into the returned 32-bit unsigned integer. + /// + /// The conversion for component c of v to fixed point is done as follows: + /// packSnorm3x10_1x2(xyz): round(clamp(c, -1, +1) * 511.0) + /// packSnorm3x10_1x2(w): round(clamp(c, -1, +1) * 1.0) + /// + /// The first vector component specifies the 10 least-significant bits of the result; + /// the forth component specifies the 2 most-significant bits. + /// + /// @see gtc_packing + /// @see vec4 unpackSnorm3x10_1x2(uint32 const & p) + /// @see uint32 packUnorm3x10_1x2(vec4 const & v) + /// @see uint32 packU3x10_1x2(uvec4 const & v) + /// @see uint32 packI3x10_1x2(ivec4 const & v) + GLM_FUNC_DECL uint32 packSnorm3x10_1x2(vec4 const & v); + + /// First, unpacks a single 32-bit unsigned integer p into four 16-bit signed integers. + /// Then, each component is converted to a normalized floating-point value to generate the returned four-component vector. + /// + /// The conversion for unpacked fixed-point value f to floating point is done as follows: + /// unpackSnorm3x10_1x2(xyz): clamp(f / 511.0, -1, +1) + /// unpackSnorm3x10_1x2(w): clamp(f / 511.0, -1, +1) + /// + /// The first component of the returned vector will be extracted from the least significant bits of the input; + /// the last component will be extracted from the most significant bits. + /// + /// @see gtc_packing + /// @see uint32 packSnorm3x10_1x2(vec4 const & v) + /// @see vec4 unpackUnorm3x10_1x2(uint32 const & p)) + /// @see uvec4 unpackI3x10_1x2(uint32 const & p) + /// @see uvec4 unpackU3x10_1x2(uint32 const & p) + GLM_FUNC_DECL vec4 unpackSnorm3x10_1x2(uint32 p); + + /// First, converts the first three components of the normalized floating-point value v into 10-bit unsigned integer values. + /// Then, converts the forth component of the normalized floating-point value v into 2-bit signed uninteger values. + /// Then, the results are packed into the returned 32-bit unsigned integer. + /// + /// The conversion for component c of v to fixed point is done as follows: + /// packUnorm3x10_1x2(xyz): round(clamp(c, 0, +1) * 1023.0) + /// packUnorm3x10_1x2(w): round(clamp(c, 0, +1) * 3.0) + /// + /// The first vector component specifies the 10 least-significant bits of the result; + /// the forth component specifies the 2 most-significant bits. + /// + /// @see gtc_packing + /// @see vec4 unpackUnorm3x10_1x2(uint32 const & p) + /// @see uint32 packUnorm3x10_1x2(vec4 const & v) + /// @see uint32 packU3x10_1x2(uvec4 const & v) + /// @see uint32 packI3x10_1x2(ivec4 const & v) + GLM_FUNC_DECL uint32 packUnorm3x10_1x2(vec4 const & v); + + /// First, unpacks a single 32-bit unsigned integer p into four 16-bit signed integers. + /// Then, each component is converted to a normalized floating-point value to generate the returned four-component vector. + /// + /// The conversion for unpacked fixed-point value f to floating point is done as follows: + /// unpackSnorm3x10_1x2(xyz): clamp(f / 1023.0, 0, +1) + /// unpackSnorm3x10_1x2(w): clamp(f / 3.0, 0, +1) + /// + /// The first component of the returned vector will be extracted from the least significant bits of the input; + /// the last component will be extracted from the most significant bits. + /// + /// @see gtc_packing + /// @see uint32 packSnorm3x10_1x2(vec4 const & v) + /// @see vec4 unpackInorm3x10_1x2(uint32 const & p)) + /// @see uvec4 unpackI3x10_1x2(uint32 const & p) + /// @see uvec4 unpackU3x10_1x2(uint32 const & p) + GLM_FUNC_DECL vec4 unpackUnorm3x10_1x2(uint32 p); + + /// First, converts the first two components of the normalized floating-point value v into 11-bit signless floating-point values. + /// Then, converts the third component of the normalized floating-point value v into a 10-bit signless floating-point value. + /// Then, the results are packed into the returned 32-bit unsigned integer. + /// + /// The first vector component specifies the 11 least-significant bits of the result; + /// the last component specifies the 10 most-significant bits. + /// + /// @see gtc_packing + /// @see vec3 unpackF2x11_1x10(uint32 const & p) + GLM_FUNC_DECL uint32 packF2x11_1x10(vec3 const & v); + + /// First, unpacks a single 32-bit unsigned integer p into two 11-bit signless floating-point values and one 10-bit signless floating-point value . + /// Then, each component is converted to a normalized floating-point value to generate the returned three-component vector. + /// + /// The first component of the returned vector will be extracted from the least significant bits of the input; + /// the last component will be extracted from the most significant bits. + /// + /// @see gtc_packing + /// @see uint32 packF2x11_1x10(vec3 const & v) + GLM_FUNC_DECL vec3 unpackF2x11_1x10(uint32 p); + + + /// First, converts the first two components of the normalized floating-point value v into 11-bit signless floating-point values. + /// Then, converts the third component of the normalized floating-point value v into a 10-bit signless floating-point value. + /// Then, the results are packed into the returned 32-bit unsigned integer. + /// + /// The first vector component specifies the 11 least-significant bits of the result; + /// the last component specifies the 10 most-significant bits. + /// + /// @see gtc_packing + /// @see vec3 unpackF3x9_E1x5(uint32 const & p) + GLM_FUNC_DECL uint32 packF3x9_E1x5(vec3 const & v); + + /// First, unpacks a single 32-bit unsigned integer p into two 11-bit signless floating-point values and one 10-bit signless floating-point value . + /// Then, each component is converted to a normalized floating-point value to generate the returned three-component vector. + /// + /// The first component of the returned vector will be extracted from the least significant bits of the input; + /// the last component will be extracted from the most significant bits. + /// + /// @see gtc_packing + /// @see uint32 packF3x9_E1x5(vec3 const & v) + GLM_FUNC_DECL vec3 unpackF3x9_E1x5(uint32 p); + + /// Returns an unsigned integer vector obtained by converting the components of a floating-point vector + /// to the 16-bit floating-point representation found in the OpenGL Specification. + /// The first vector component specifies the 16 least-significant bits of the result; + /// the forth component specifies the 16 most-significant bits. + /// + /// @see gtc_packing + /// @see vecType unpackHalf(vecType const & p) + /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions + template class vecType> + GLM_FUNC_DECL vecType packHalf(vecType const & v); + + /// Returns a floating-point vector with components obtained by reinterpreting an integer vector as 16-bit floating-point numbers and converting them to 32-bit floating-point values. + /// The first component of the vector is obtained from the 16 least-significant bits of v; + /// the forth component is obtained from the 16 most-significant bits of v. + /// + /// @see gtc_packing + /// @see vecType packHalf(vecType const & v) + /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions + template class vecType> + GLM_FUNC_DECL vecType unpackHalf(vecType const & p); + + /// Convert each component of the normalized floating-point vector into unsigned integer values. + /// + /// @see gtc_packing + /// @see vecType unpackUnorm(vecType const & p); + template class vecType> + GLM_FUNC_DECL vecType packUnorm(vecType const & v); + + /// Convert each unsigned integer components of a vector to normalized floating-point values. + /// + /// @see gtc_packing + /// @see vecType packUnorm(vecType const & v) + template class vecType> + GLM_FUNC_DECL vecType unpackUnorm(vecType const & v); + + /// Convert each component of the normalized floating-point vector into signed integer values. + /// + /// @see gtc_packing + /// @see vecType unpackSnorm(vecType const & p); + template class vecType> + GLM_FUNC_DECL vecType packSnorm(vecType const & v); + + /// Convert each signed integer components of a vector to normalized floating-point values. + /// + /// @see gtc_packing + /// @see vecType packSnorm(vecType const & v) + template class vecType> + GLM_FUNC_DECL vecType unpackSnorm(vecType const & v); + + /// Convert each component of the normalized floating-point vector into unsigned integer values. + /// + /// @see gtc_packing + /// @see vec2 unpackUnorm2x4(uint8 p) + GLM_FUNC_DECL uint8 packUnorm2x4(vec2 const & v); + + /// Convert each unsigned integer components of a vector to normalized floating-point values. + /// + /// @see gtc_packing + /// @see uint8 packUnorm2x4(vec2 const & v) + GLM_FUNC_DECL vec2 unpackUnorm2x4(uint8 p); + + /// Convert each component of the normalized floating-point vector into unsigned integer values. + /// + /// @see gtc_packing + /// @see vec4 unpackUnorm4x4(uint16 p) + GLM_FUNC_DECL uint16 packUnorm4x4(vec4 const & v); + + /// Convert each unsigned integer components of a vector to normalized floating-point values. + /// + /// @see gtc_packing + /// @see uint16 packUnorm4x4(vec4 const & v) + GLM_FUNC_DECL vec4 unpackUnorm4x4(uint16 p); + + /// Convert each component of the normalized floating-point vector into unsigned integer values. + /// + /// @see gtc_packing + /// @see vec3 unpackUnorm1x5_1x6_1x5(uint16 p) + GLM_FUNC_DECL uint16 packUnorm1x5_1x6_1x5(vec3 const & v); + + /// Convert each unsigned integer components of a vector to normalized floating-point values. + /// + /// @see gtc_packing + /// @see uint16 packUnorm1x5_1x6_1x5(vec3 const & v) + GLM_FUNC_DECL vec3 unpackUnorm1x5_1x6_1x5(uint16 p); + + /// Convert each component of the normalized floating-point vector into unsigned integer values. + /// + /// @see gtc_packing + /// @see vec4 unpackUnorm3x5_1x1(uint16 p) + GLM_FUNC_DECL uint16 packUnorm3x5_1x1(vec4 const & v); + + /// Convert each unsigned integer components of a vector to normalized floating-point values. + /// + /// @see gtc_packing + /// @see uint16 packUnorm3x5_1x1(vec4 const & v) + GLM_FUNC_DECL vec4 unpackUnorm3x5_1x1(uint16 p); + + /// Convert each component of the normalized floating-point vector into unsigned integer values. + /// + /// @see gtc_packing + /// @see vec3 unpackUnorm2x3_1x2(uint8 p) + GLM_FUNC_DECL uint8 packUnorm2x3_1x2(vec3 const & v); + + /// Convert each unsigned integer components of a vector to normalized floating-point values. + /// + /// @see gtc_packing + /// @see uint8 packUnorm2x3_1x2(vec3 const & v) + GLM_FUNC_DECL vec3 unpackUnorm2x3_1x2(uint8 p); + /// @} +}// namespace glm + +#include "packing.inl" diff --git a/external/include/glm/gtc/packing.inl b/external/include/glm/gtc/packing.inl new file mode 100644 index 0000000..618fb9e --- /dev/null +++ b/external/include/glm/gtc/packing.inl @@ -0,0 +1,781 @@ +/// @ref gtc_packing +/// @file glm/gtc/packing.inl + +#include "../common.hpp" +#include "../vec2.hpp" +#include "../vec3.hpp" +#include "../vec4.hpp" +#include "../detail/type_half.hpp" +#include +#include + +namespace glm{ +namespace detail +{ + GLM_FUNC_QUALIFIER glm::uint16 float2half(glm::uint32 f) + { + // 10 bits => EE EEEFFFFF + // 11 bits => EEE EEFFFFFF + // Half bits => SEEEEEFF FFFFFFFF + // Float bits => SEEEEEEE EFFFFFFF FFFFFFFF FFFFFFFF + + // 0x00007c00 => 00000000 00000000 01111100 00000000 + // 0x000003ff => 00000000 00000000 00000011 11111111 + // 0x38000000 => 00111000 00000000 00000000 00000000 + // 0x7f800000 => 01111111 10000000 00000000 00000000 + // 0x00008000 => 00000000 00000000 10000000 00000000 + return + ((f >> 16) & 0x8000) | // sign + ((((f & 0x7f800000) - 0x38000000) >> 13) & 0x7c00) | // exponential + ((f >> 13) & 0x03ff); // Mantissa + } + + GLM_FUNC_QUALIFIER glm::uint32 float2packed11(glm::uint32 f) + { + // 10 bits => EE EEEFFFFF + // 11 bits => EEE EEFFFFFF + // Half bits => SEEEEEFF FFFFFFFF + // Float bits => SEEEEEEE EFFFFFFF FFFFFFFF FFFFFFFF + + // 0x000007c0 => 00000000 00000000 00000111 11000000 + // 0x00007c00 => 00000000 00000000 01111100 00000000 + // 0x000003ff => 00000000 00000000 00000011 11111111 + // 0x38000000 => 00111000 00000000 00000000 00000000 + // 0x7f800000 => 01111111 10000000 00000000 00000000 + // 0x00008000 => 00000000 00000000 10000000 00000000 + return + ((((f & 0x7f800000) - 0x38000000) >> 17) & 0x07c0) | // exponential + ((f >> 17) & 0x003f); // Mantissa + } + + GLM_FUNC_QUALIFIER glm::uint32 packed11ToFloat(glm::uint32 p) + { + // 10 bits => EE EEEFFFFF + // 11 bits => EEE EEFFFFFF + // Half bits => SEEEEEFF FFFFFFFF + // Float bits => SEEEEEEE EFFFFFFF FFFFFFFF FFFFFFFF + + // 0x000007c0 => 00000000 00000000 00000111 11000000 + // 0x00007c00 => 00000000 00000000 01111100 00000000 + // 0x000003ff => 00000000 00000000 00000011 11111111 + // 0x38000000 => 00111000 00000000 00000000 00000000 + // 0x7f800000 => 01111111 10000000 00000000 00000000 + // 0x00008000 => 00000000 00000000 10000000 00000000 + return + ((((p & 0x07c0) << 17) + 0x38000000) & 0x7f800000) | // exponential + ((p & 0x003f) << 17); // Mantissa + } + + GLM_FUNC_QUALIFIER glm::uint32 float2packed10(glm::uint32 f) + { + // 10 bits => EE EEEFFFFF + // 11 bits => EEE EEFFFFFF + // Half bits => SEEEEEFF FFFFFFFF + // Float bits => SEEEEEEE EFFFFFFF FFFFFFFF FFFFFFFF + + // 0x0000001F => 00000000 00000000 00000000 00011111 + // 0x0000003F => 00000000 00000000 00000000 00111111 + // 0x000003E0 => 00000000 00000000 00000011 11100000 + // 0x000007C0 => 00000000 00000000 00000111 11000000 + // 0x00007C00 => 00000000 00000000 01111100 00000000 + // 0x000003FF => 00000000 00000000 00000011 11111111 + // 0x38000000 => 00111000 00000000 00000000 00000000 + // 0x7f800000 => 01111111 10000000 00000000 00000000 + // 0x00008000 => 00000000 00000000 10000000 00000000 + return + ((((f & 0x7f800000) - 0x38000000) >> 18) & 0x03E0) | // exponential + ((f >> 18) & 0x001f); // Mantissa + } + + GLM_FUNC_QUALIFIER glm::uint32 packed10ToFloat(glm::uint32 p) + { + // 10 bits => EE EEEFFFFF + // 11 bits => EEE EEFFFFFF + // Half bits => SEEEEEFF FFFFFFFF + // Float bits => SEEEEEEE EFFFFFFF FFFFFFFF FFFFFFFF + + // 0x0000001F => 00000000 00000000 00000000 00011111 + // 0x0000003F => 00000000 00000000 00000000 00111111 + // 0x000003E0 => 00000000 00000000 00000011 11100000 + // 0x000007C0 => 00000000 00000000 00000111 11000000 + // 0x00007C00 => 00000000 00000000 01111100 00000000 + // 0x000003FF => 00000000 00000000 00000011 11111111 + // 0x38000000 => 00111000 00000000 00000000 00000000 + // 0x7f800000 => 01111111 10000000 00000000 00000000 + // 0x00008000 => 00000000 00000000 10000000 00000000 + return + ((((p & 0x03E0) << 18) + 0x38000000) & 0x7f800000) | // exponential + ((p & 0x001f) << 18); // Mantissa + } + + GLM_FUNC_QUALIFIER glm::uint half2float(glm::uint h) + { + return ((h & 0x8000) << 16) | ((( h & 0x7c00) + 0x1C000) << 13) | ((h & 0x03FF) << 13); + } + + GLM_FUNC_QUALIFIER glm::uint floatTo11bit(float x) + { + if(x == 0.0f) + return 0u; + else if(glm::isnan(x)) + return ~0u; + else if(glm::isinf(x)) + return 0x1Fu << 6u; + + uint Pack = 0u; + memcpy(&Pack, &x, sizeof(Pack)); + return float2packed11(Pack); + } + + GLM_FUNC_QUALIFIER float packed11bitToFloat(glm::uint x) + { + if(x == 0) + return 0.0f; + else if(x == ((1 << 11) - 1)) + return ~0;//NaN + else if(x == (0x1f << 6)) + return ~0;//Inf + + uint Result = packed11ToFloat(x); + + float Temp = 0; + memcpy(&Temp, &Result, sizeof(Temp)); + return Temp; + } + + GLM_FUNC_QUALIFIER glm::uint floatTo10bit(float x) + { + if(x == 0.0f) + return 0u; + else if(glm::isnan(x)) + return ~0u; + else if(glm::isinf(x)) + return 0x1Fu << 5u; + + uint Pack = 0; + memcpy(&Pack, &x, sizeof(Pack)); + return float2packed10(Pack); + } + + GLM_FUNC_QUALIFIER float packed10bitToFloat(glm::uint x) + { + if(x == 0) + return 0.0f; + else if(x == ((1 << 10) - 1)) + return ~0;//NaN + else if(x == (0x1f << 5)) + return ~0;//Inf + + uint Result = packed10ToFloat(x); + + float Temp = 0; + memcpy(&Temp, &Result, sizeof(Temp)); + return Temp; + } + +// GLM_FUNC_QUALIFIER glm::uint f11_f11_f10(float x, float y, float z) +// { +// return ((floatTo11bit(x) & ((1 << 11) - 1)) << 0) | ((floatTo11bit(y) & ((1 << 11) - 1)) << 11) | ((floatTo10bit(z) & ((1 << 10) - 1)) << 22); +// } + + union u3u3u2 + { + struct + { + uint x : 3; + uint y : 3; + uint z : 2; + } data; + uint8 pack; + }; + + union u4u4 + { + struct + { + uint x : 4; + uint y : 4; + } data; + uint8 pack; + }; + + union u4u4u4u4 + { + struct + { + uint x : 4; + uint y : 4; + uint z : 4; + uint w : 4; + } data; + uint16 pack; + }; + + union u5u6u5 + { + struct + { + uint x : 5; + uint y : 6; + uint z : 5; + } data; + uint16 pack; + }; + + union u5u5u5u1 + { + struct + { + uint x : 5; + uint y : 5; + uint z : 5; + uint w : 1; + } data; + uint16 pack; + }; + + union u10u10u10u2 + { + struct + { + uint x : 10; + uint y : 10; + uint z : 10; + uint w : 2; + } data; + uint32 pack; + }; + + union i10i10i10i2 + { + struct + { + int x : 10; + int y : 10; + int z : 10; + int w : 2; + } data; + uint32 pack; + }; + + union u9u9u9e5 + { + struct + { + uint x : 9; + uint y : 9; + uint z : 9; + uint w : 5; + } data; + uint32 pack; + }; + + template class vecType> + struct compute_half + {}; + + template + struct compute_half + { + GLM_FUNC_QUALIFIER static tvec1 pack(tvec1 const & v) + { + int16 const Unpack(detail::toFloat16(v.x)); + u16vec1 Packed(uninitialize); + memcpy(&Packed, &Unpack, sizeof(Packed)); + return Packed; + } + + GLM_FUNC_QUALIFIER static tvec1 unpack(tvec1 const & v) + { + i16vec1 Unpack(uninitialize); + memcpy(&Unpack, &v, sizeof(Unpack)); + return tvec1(detail::toFloat32(v.x)); + } + }; + + template + struct compute_half + { + GLM_FUNC_QUALIFIER static tvec2 pack(tvec2 const & v) + { + tvec2 const Unpack(detail::toFloat16(v.x), detail::toFloat16(v.y)); + u16vec2 Packed(uninitialize); + memcpy(&Packed, &Unpack, sizeof(Packed)); + return Packed; + } + + GLM_FUNC_QUALIFIER static tvec2 unpack(tvec2 const & v) + { + i16vec2 Unpack(uninitialize); + memcpy(&Unpack, &v, sizeof(Unpack)); + return tvec2(detail::toFloat32(v.x), detail::toFloat32(v.y)); + } + }; + + template + struct compute_half + { + GLM_FUNC_QUALIFIER static tvec3 pack(tvec3 const & v) + { + tvec3 const Unpack(detail::toFloat16(v.x), detail::toFloat16(v.y), detail::toFloat16(v.z)); + u16vec3 Packed(uninitialize); + memcpy(&Packed, &Unpack, sizeof(Packed)); + return Packed; + } + + GLM_FUNC_QUALIFIER static tvec3 unpack(tvec3 const & v) + { + i16vec3 Unpack(uninitialize); + memcpy(&Unpack, &v, sizeof(Unpack)); + return tvec3(detail::toFloat32(v.x), detail::toFloat32(v.y), detail::toFloat32(v.z)); + } + }; + + template + struct compute_half + { + GLM_FUNC_QUALIFIER static tvec4 pack(tvec4 const & v) + { + tvec4 const Unpack(detail::toFloat16(v.x), detail::toFloat16(v.y), detail::toFloat16(v.z), detail::toFloat16(v.w)); + u16vec4 Packed(uninitialize); + memcpy(&Packed, &Unpack, sizeof(Packed)); + return Packed; + } + + GLM_FUNC_QUALIFIER static tvec4 unpack(tvec4 const & v) + { + i16vec4 Unpack(uninitialize); + memcpy(&Unpack, &v, sizeof(Unpack)); + return tvec4(detail::toFloat32(v.x), detail::toFloat32(v.y), detail::toFloat32(v.z), detail::toFloat32(v.w)); + } + }; +}//namespace detail + + GLM_FUNC_QUALIFIER uint8 packUnorm1x8(float v) + { + return static_cast(round(clamp(v, 0.0f, 1.0f) * 255.0f)); + } + + GLM_FUNC_QUALIFIER float unpackUnorm1x8(uint8 p) + { + float const Unpack(p); + return Unpack * static_cast(0.0039215686274509803921568627451); // 1 / 255 + } + + GLM_FUNC_QUALIFIER uint16 packUnorm2x8(vec2 const & v) + { + u8vec2 const Topack(round(clamp(v, 0.0f, 1.0f) * 255.0f)); + + uint16 Unpack = 0; + memcpy(&Unpack, &Topack, sizeof(Unpack)); + return Unpack; + } + + GLM_FUNC_QUALIFIER vec2 unpackUnorm2x8(uint16 p) + { + u8vec2 Unpack(uninitialize); + memcpy(&Unpack, &p, sizeof(Unpack)); + return vec2(Unpack) * float(0.0039215686274509803921568627451); // 1 / 255 + } + + GLM_FUNC_QUALIFIER uint8 packSnorm1x8(float v) + { + int8 const Topack(static_cast(round(clamp(v ,-1.0f, 1.0f) * 127.0f))); + uint8 Packed = 0; + memcpy(&Packed, &Topack, sizeof(Packed)); + return Packed; + } + + GLM_FUNC_QUALIFIER float unpackSnorm1x8(uint8 p) + { + int8 Unpack = 0; + memcpy(&Unpack, &p, sizeof(Unpack)); + return clamp( + static_cast(Unpack) * 0.00787401574803149606299212598425f, // 1.0f / 127.0f + -1.0f, 1.0f); + } + + GLM_FUNC_QUALIFIER uint16 packSnorm2x8(vec2 const & v) + { + i8vec2 const Topack(round(clamp(v, -1.0f, 1.0f) * 127.0f)); + uint16 Packed = 0; + memcpy(&Packed, &Topack, sizeof(Packed)); + return Packed; + } + + GLM_FUNC_QUALIFIER vec2 unpackSnorm2x8(uint16 p) + { + i8vec2 Unpack(uninitialize); + memcpy(&Unpack, &p, sizeof(Unpack)); + return clamp( + vec2(Unpack) * 0.00787401574803149606299212598425f, // 1.0f / 127.0f + -1.0f, 1.0f); + } + + GLM_FUNC_QUALIFIER uint16 packUnorm1x16(float s) + { + return static_cast(round(clamp(s, 0.0f, 1.0f) * 65535.0f)); + } + + GLM_FUNC_QUALIFIER float unpackUnorm1x16(uint16 p) + { + float const Unpack(p); + return Unpack * 1.5259021896696421759365224689097e-5f; // 1.0 / 65535.0 + } + + GLM_FUNC_QUALIFIER uint64 packUnorm4x16(vec4 const & v) + { + u16vec4 const Topack(round(clamp(v , 0.0f, 1.0f) * 65535.0f)); + uint64 Packed = 0; + memcpy(&Packed, &Topack, sizeof(Packed)); + return Packed; + } + + GLM_FUNC_QUALIFIER vec4 unpackUnorm4x16(uint64 p) + { + u16vec4 Unpack(uninitialize); + memcpy(&Unpack, &p, sizeof(Unpack)); + return vec4(Unpack) * 1.5259021896696421759365224689097e-5f; // 1.0 / 65535.0 + } + + GLM_FUNC_QUALIFIER uint16 packSnorm1x16(float v) + { + int16 const Topack = static_cast(round(clamp(v ,-1.0f, 1.0f) * 32767.0f)); + uint16 Packed = 0; + memcpy(&Packed, &Topack, sizeof(Packed)); + return Packed; + } + + GLM_FUNC_QUALIFIER float unpackSnorm1x16(uint16 p) + { + int16 Unpack = 0; + memcpy(&Unpack, &p, sizeof(Unpack)); + return clamp( + static_cast(Unpack) * 3.0518509475997192297128208258309e-5f, //1.0f / 32767.0f, + -1.0f, 1.0f); + } + + GLM_FUNC_QUALIFIER uint64 packSnorm4x16(vec4 const & v) + { + i16vec4 const Topack(round(clamp(v ,-1.0f, 1.0f) * 32767.0f)); + uint64 Packed = 0; + memcpy(&Packed, &Topack, sizeof(Packed)); + return Packed; + } + + GLM_FUNC_QUALIFIER vec4 unpackSnorm4x16(uint64 p) + { + i16vec4 Unpack(uninitialize); + memcpy(&Unpack, &p, sizeof(Unpack)); + return clamp( + vec4(Unpack) * 3.0518509475997192297128208258309e-5f, //1.0f / 32767.0f, + -1.0f, 1.0f); + } + + GLM_FUNC_QUALIFIER uint16 packHalf1x16(float v) + { + int16 const Topack(detail::toFloat16(v)); + uint16 Packed = 0; + memcpy(&Packed, &Topack, sizeof(Packed)); + return Packed; + } + + GLM_FUNC_QUALIFIER float unpackHalf1x16(uint16 v) + { + int16 Unpack = 0; + memcpy(&Unpack, &v, sizeof(Unpack)); + return detail::toFloat32(Unpack); + } + + GLM_FUNC_QUALIFIER uint64 packHalf4x16(glm::vec4 const & v) + { + i16vec4 const Unpack( + detail::toFloat16(v.x), + detail::toFloat16(v.y), + detail::toFloat16(v.z), + detail::toFloat16(v.w)); + uint64 Packed = 0; + memcpy(&Packed, &Unpack, sizeof(Packed)); + return Packed; + } + + GLM_FUNC_QUALIFIER glm::vec4 unpackHalf4x16(uint64 v) + { + i16vec4 Unpack(uninitialize); + memcpy(&Unpack, &v, sizeof(Unpack)); + return vec4( + detail::toFloat32(Unpack.x), + detail::toFloat32(Unpack.y), + detail::toFloat32(Unpack.z), + detail::toFloat32(Unpack.w)); + } + + GLM_FUNC_QUALIFIER uint32 packI3x10_1x2(ivec4 const & v) + { + detail::i10i10i10i2 Result; + Result.data.x = v.x; + Result.data.y = v.y; + Result.data.z = v.z; + Result.data.w = v.w; + return Result.pack; + } + + GLM_FUNC_QUALIFIER ivec4 unpackI3x10_1x2(uint32 v) + { + detail::i10i10i10i2 Unpack; + Unpack.pack = v; + return ivec4( + Unpack.data.x, + Unpack.data.y, + Unpack.data.z, + Unpack.data.w); + } + + GLM_FUNC_QUALIFIER uint32 packU3x10_1x2(uvec4 const & v) + { + detail::u10u10u10u2 Result; + Result.data.x = v.x; + Result.data.y = v.y; + Result.data.z = v.z; + Result.data.w = v.w; + return Result.pack; + } + + GLM_FUNC_QUALIFIER uvec4 unpackU3x10_1x2(uint32 v) + { + detail::u10u10u10u2 Unpack; + Unpack.pack = v; + return uvec4( + Unpack.data.x, + Unpack.data.y, + Unpack.data.z, + Unpack.data.w); + } + + GLM_FUNC_QUALIFIER uint32 packSnorm3x10_1x2(vec4 const & v) + { + detail::i10i10i10i2 Result; + Result.data.x = int(round(clamp(v.x,-1.0f, 1.0f) * 511.f)); + Result.data.y = int(round(clamp(v.y,-1.0f, 1.0f) * 511.f)); + Result.data.z = int(round(clamp(v.z,-1.0f, 1.0f) * 511.f)); + Result.data.w = int(round(clamp(v.w,-1.0f, 1.0f) * 1.f)); + return Result.pack; + } + + GLM_FUNC_QUALIFIER vec4 unpackSnorm3x10_1x2(uint32 v) + { + detail::i10i10i10i2 Unpack; + Unpack.pack = v; + vec4 Result; + Result.x = clamp(float(Unpack.data.x) / 511.f, -1.0f, 1.0f); + Result.y = clamp(float(Unpack.data.y) / 511.f, -1.0f, 1.0f); + Result.z = clamp(float(Unpack.data.z) / 511.f, -1.0f, 1.0f); + Result.w = clamp(float(Unpack.data.w) / 1.f, -1.0f, 1.0f); + return Result; + } + + GLM_FUNC_QUALIFIER uint32 packUnorm3x10_1x2(vec4 const & v) + { + uvec4 const Unpack(round(clamp(v, 0.0f, 1.0f) * vec4(1023.f, 1023.f, 1023.f, 3.f))); + + detail::u10u10u10u2 Result; + Result.data.x = Unpack.x; + Result.data.y = Unpack.y; + Result.data.z = Unpack.z; + Result.data.w = Unpack.w; + return Result.pack; + } + + GLM_FUNC_QUALIFIER vec4 unpackUnorm3x10_1x2(uint32 v) + { + vec4 const ScaleFactors(1.0f / 1023.f, 1.0f / 1023.f, 1.0f / 1023.f, 1.0f / 3.f); + + detail::u10u10u10u2 Unpack; + Unpack.pack = v; + return vec4(Unpack.data.x, Unpack.data.y, Unpack.data.z, Unpack.data.w) * ScaleFactors; + } + + GLM_FUNC_QUALIFIER uint32 packF2x11_1x10(vec3 const & v) + { + return + ((detail::floatTo11bit(v.x) & ((1 << 11) - 1)) << 0) | + ((detail::floatTo11bit(v.y) & ((1 << 11) - 1)) << 11) | + ((detail::floatTo10bit(v.z) & ((1 << 10) - 1)) << 22); + } + + GLM_FUNC_QUALIFIER vec3 unpackF2x11_1x10(uint32 v) + { + return vec3( + detail::packed11bitToFloat(v >> 0), + detail::packed11bitToFloat(v >> 11), + detail::packed10bitToFloat(v >> 22)); + } + + GLM_FUNC_QUALIFIER uint32 packF3x9_E1x5(vec3 const & v) + { + float const SharedExpMax = (pow(2.0f, 9.0f - 1.0f) / pow(2.0f, 9.0f)) * pow(2.0f, 31.f - 15.f); + vec3 const Color = clamp(v, 0.0f, SharedExpMax); + float const MaxColor = max(Color.x, max(Color.y, Color.z)); + + float const ExpSharedP = max(-15.f - 1.f, floor(log2(MaxColor))) + 1.0f + 15.f; + float const MaxShared = floor(MaxColor / pow(2.0f, (ExpSharedP - 16.f - 9.f)) + 0.5f); + float const ExpShared = MaxShared == pow(2.0f, 9.0f) ? ExpSharedP + 1.0f : ExpSharedP; + + uvec3 const ColorComp(floor(Color / pow(2.f, (ExpShared - 15.f - 9.f)) + 0.5f)); + + detail::u9u9u9e5 Unpack; + Unpack.data.x = ColorComp.x; + Unpack.data.y = ColorComp.y; + Unpack.data.z = ColorComp.z; + Unpack.data.w = uint(ExpShared); + return Unpack.pack; + } + + GLM_FUNC_QUALIFIER vec3 unpackF3x9_E1x5(uint32 v) + { + detail::u9u9u9e5 Unpack; + Unpack.pack = v; + + return vec3(Unpack.data.x, Unpack.data.y, Unpack.data.z) * pow(2.0f, Unpack.data.w - 15.f - 9.f); + } + + template class vecType> + GLM_FUNC_QUALIFIER vecType packHalf(vecType const & v) + { + return detail::compute_half::pack(v); + } + + template class vecType> + GLM_FUNC_QUALIFIER vecType unpackHalf(vecType const & v) + { + return detail::compute_half::unpack(v); + } + + template class vecType> + GLM_FUNC_QUALIFIER vecType packUnorm(vecType const & v) + { + GLM_STATIC_ASSERT(std::numeric_limits::is_integer, "uintType must be an integer type"); + GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "floatType must be a floating point type"); + + return vecType(round(clamp(v, static_cast(0), static_cast(1)) * static_cast(std::numeric_limits::max()))); + } + + template class vecType> + GLM_FUNC_QUALIFIER vecType unpackUnorm(vecType const & v) + { + GLM_STATIC_ASSERT(std::numeric_limits::is_integer, "uintType must be an integer type"); + GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "floatType must be a floating point type"); + + return vecType(v) * (static_cast(1) / static_cast(std::numeric_limits::max())); + } + + template class vecType> + GLM_FUNC_QUALIFIER vecType packSnorm(vecType const & v) + { + GLM_STATIC_ASSERT(std::numeric_limits::is_integer, "uintType must be an integer type"); + GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "floatType must be a floating point type"); + + return vecType(round(clamp(v , static_cast(-1), static_cast(1)) * static_cast(std::numeric_limits::max()))); + } + + template class vecType> + GLM_FUNC_QUALIFIER vecType unpackSnorm(vecType const & v) + { + GLM_STATIC_ASSERT(std::numeric_limits::is_integer, "uintType must be an integer type"); + GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "floatType must be a floating point type"); + + return clamp(vecType(v) * (static_cast(1) / static_cast(std::numeric_limits::max())), static_cast(-1), static_cast(1)); + } + + GLM_FUNC_QUALIFIER uint8 packUnorm2x4(vec2 const & v) + { + u32vec2 const Unpack(round(clamp(v, 0.0f, 1.0f) * 15.0f)); + detail::u4u4 Result; + Result.data.x = Unpack.x; + Result.data.y = Unpack.y; + return Result.pack; + } + + GLM_FUNC_QUALIFIER vec2 unpackUnorm2x4(uint8 v) + { + float const ScaleFactor(1.f / 15.f); + detail::u4u4 Unpack; + Unpack.pack = v; + return vec2(Unpack.data.x, Unpack.data.y) * ScaleFactor; + } + + GLM_FUNC_QUALIFIER uint16 packUnorm4x4(vec4 const & v) + { + u32vec4 const Unpack(round(clamp(v, 0.0f, 1.0f) * 15.0f)); + detail::u4u4u4u4 Result; + Result.data.x = Unpack.x; + Result.data.y = Unpack.y; + Result.data.z = Unpack.z; + Result.data.w = Unpack.w; + return Result.pack; + } + + GLM_FUNC_QUALIFIER vec4 unpackUnorm4x4(uint16 v) + { + float const ScaleFactor(1.f / 15.f); + detail::u4u4u4u4 Unpack; + Unpack.pack = v; + return vec4(Unpack.data.x, Unpack.data.y, Unpack.data.z, Unpack.data.w) * ScaleFactor; + } + + GLM_FUNC_QUALIFIER uint16 packUnorm1x5_1x6_1x5(vec3 const & v) + { + u32vec3 const Unpack(round(clamp(v, 0.0f, 1.0f) * vec3(31.f, 63.f, 31.f))); + detail::u5u6u5 Result; + Result.data.x = Unpack.x; + Result.data.y = Unpack.y; + Result.data.z = Unpack.z; + return Result.pack; + } + + GLM_FUNC_QUALIFIER vec3 unpackUnorm1x5_1x6_1x5(uint16 v) + { + vec3 const ScaleFactor(1.f / 31.f, 1.f / 63.f, 1.f / 31.f); + detail::u5u6u5 Unpack; + Unpack.pack = v; + return vec3(Unpack.data.x, Unpack.data.y, Unpack.data.z) * ScaleFactor; + } + + GLM_FUNC_QUALIFIER uint16 packUnorm3x5_1x1(vec4 const & v) + { + u32vec4 const Unpack(round(clamp(v, 0.0f, 1.0f) * vec4(31.f, 31.f, 31.f, 1.f))); + detail::u5u5u5u1 Result; + Result.data.x = Unpack.x; + Result.data.y = Unpack.y; + Result.data.z = Unpack.z; + Result.data.w = Unpack.w; + return Result.pack; + } + + GLM_FUNC_QUALIFIER vec4 unpackUnorm3x5_1x1(uint16 v) + { + vec4 const ScaleFactor(1.f / 31.f, 1.f / 31.f, 1.f / 31.f, 1.f); + detail::u5u5u5u1 Unpack; + Unpack.pack = v; + return vec4(Unpack.data.x, Unpack.data.y, Unpack.data.z, Unpack.data.w) * ScaleFactor; + } + + GLM_FUNC_QUALIFIER uint8 packUnorm2x3_1x2(vec3 const & v) + { + u32vec3 const Unpack(round(clamp(v, 0.0f, 1.0f) * vec3(7.f, 7.f, 3.f))); + detail::u3u3u2 Result; + Result.data.x = Unpack.x; + Result.data.y = Unpack.y; + Result.data.z = Unpack.z; + return Result.pack; + } + + GLM_FUNC_QUALIFIER vec3 unpackUnorm2x3_1x2(uint8 v) + { + vec3 const ScaleFactor(1.f / 7.f, 1.f / 7.f, 1.f / 3.f); + detail::u3u3u2 Unpack; + Unpack.pack = v; + return vec3(Unpack.data.x, Unpack.data.y, Unpack.data.z) * ScaleFactor; + } +}//namespace glm + diff --git a/external/include/glm/gtc/quaternion.hpp b/external/include/glm/gtc/quaternion.hpp new file mode 100644 index 0000000..8af1c8b --- /dev/null +++ b/external/include/glm/gtc/quaternion.hpp @@ -0,0 +1,397 @@ +/// @ref gtc_quaternion +/// @file glm/gtc/quaternion.hpp +/// +/// @see core (dependence) +/// @see gtc_half_float (dependence) +/// @see gtc_constants (dependence) +/// +/// @defgroup gtc_quaternion GLM_GTC_quaternion +/// @ingroup gtc +/// +/// @brief Defines a templated quaternion type and several quaternion operations. +/// +/// need to be included to use these functionalities. + +#pragma once + +// Dependency: +#include "../mat3x3.hpp" +#include "../mat4x4.hpp" +#include "../vec3.hpp" +#include "../vec4.hpp" +#include "../gtc/constants.hpp" + +#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED) +# pragma message("GLM: GLM_GTC_quaternion extension included") +#endif + +namespace glm +{ + /// @addtogroup gtc_quaternion + /// @{ + + template + struct tquat + { + // -- Implementation detail -- + + typedef tquat type; + typedef T value_type; + + // -- Data -- + +# if GLM_HAS_ALIGNED_TYPE +# if GLM_COMPILER & GLM_COMPILER_GCC +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wpedantic" +# endif +# if GLM_COMPILER & GLM_COMPILER_CLANG +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wgnu-anonymous-struct" +# pragma clang diagnostic ignored "-Wnested-anon-types" +# endif + + union + { + struct { T x, y, z, w;}; + typename detail::storage::value>::type data; + }; + +# if GLM_COMPILER & GLM_COMPILER_CLANG +# pragma clang diagnostic pop +# endif +# if GLM_COMPILER & GLM_COMPILER_GCC +# pragma GCC diagnostic pop +# endif +# else + T x, y, z, w; +# endif + + // -- Component accesses -- + + typedef length_t length_type; + /// Return the count of components of a quaternion + GLM_FUNC_DECL static length_type length(){return 4;} + + GLM_FUNC_DECL T & operator[](length_type i); + GLM_FUNC_DECL T const & operator[](length_type i) const; + + // -- Implicit basic constructors -- + + GLM_FUNC_DECL GLM_CONSTEXPR tquat() GLM_DEFAULT_CTOR; + GLM_FUNC_DECL GLM_CONSTEXPR tquat(tquat const & q) GLM_DEFAULT; + template + GLM_FUNC_DECL GLM_CONSTEXPR tquat(tquat const & q); + + // -- Explicit basic constructors -- + + GLM_FUNC_DECL GLM_CONSTEXPR_CTOR explicit tquat(ctor); + GLM_FUNC_DECL GLM_CONSTEXPR tquat(T const & s, tvec3 const & v); + GLM_FUNC_DECL GLM_CONSTEXPR tquat(T const & w, T const & x, T const & y, T const & z); + + // -- Conversion constructors -- + + template + GLM_FUNC_DECL GLM_CONSTEXPR GLM_EXPLICIT tquat(tquat const & q); + + /// Explicit conversion operators +# if GLM_HAS_EXPLICIT_CONVERSION_OPERATORS + GLM_FUNC_DECL explicit operator tmat3x3(); + GLM_FUNC_DECL explicit operator tmat4x4(); +# endif + + /// Create a quaternion from two normalized axis + /// + /// @param u A first normalized axis + /// @param v A second normalized axis + /// @see gtc_quaternion + /// @see http://lolengine.net/blog/2013/09/18/beautiful-maths-quaternion-from-vectors + GLM_FUNC_DECL tquat(tvec3 const & u, tvec3 const & v); + + /// Build a quaternion from euler angles (pitch, yaw, roll), in radians. + GLM_FUNC_DECL GLM_EXPLICIT tquat(tvec3 const & eulerAngles); + GLM_FUNC_DECL GLM_EXPLICIT tquat(tmat3x3 const & m); + GLM_FUNC_DECL GLM_EXPLICIT tquat(tmat4x4 const & m); + + // -- Unary arithmetic operators -- + + GLM_FUNC_DECL tquat & operator=(tquat const & m) GLM_DEFAULT; + + template + GLM_FUNC_DECL tquat & operator=(tquat const & m); + template + GLM_FUNC_DECL tquat & operator+=(tquat const & q); + template + GLM_FUNC_DECL tquat & operator-=(tquat const & q); + template + GLM_FUNC_DECL tquat & operator*=(tquat const & q); + template + GLM_FUNC_DECL tquat & operator*=(U s); + template + GLM_FUNC_DECL tquat & operator/=(U s); + }; + + // -- Unary bit operators -- + + template + GLM_FUNC_DECL tquat operator+(tquat const & q); + + template + GLM_FUNC_DECL tquat operator-(tquat const & q); + + // -- Binary operators -- + + template + GLM_FUNC_DECL tquat operator+(tquat const & q, tquat const & p); + + template + GLM_FUNC_DECL tquat operator*(tquat const & q, tquat const & p); + + template + GLM_FUNC_DECL tvec3 operator*(tquat const & q, tvec3 const & v); + + template + GLM_FUNC_DECL tvec3 operator*(tvec3 const & v, tquat const & q); + + template + GLM_FUNC_DECL tvec4 operator*(tquat const & q, tvec4 const & v); + + template + GLM_FUNC_DECL tvec4 operator*(tvec4 const & v, tquat const & q); + + template + GLM_FUNC_DECL tquat operator*(tquat const & q, T const & s); + + template + GLM_FUNC_DECL tquat operator*(T const & s, tquat const & q); + + template + GLM_FUNC_DECL tquat operator/(tquat const & q, T const & s); + + // -- Boolean operators -- + + template + GLM_FUNC_DECL bool operator==(tquat const & q1, tquat const & q2); + + template + GLM_FUNC_DECL bool operator!=(tquat const & q1, tquat const & q2); + + /// Returns the length of the quaternion. + /// + /// @see gtc_quaternion + template + GLM_FUNC_DECL T length(tquat const & q); + + /// Returns the normalized quaternion. + /// + /// @see gtc_quaternion + template + GLM_FUNC_DECL tquat normalize(tquat const & q); + + /// Returns dot product of q1 and q2, i.e., q1[0] * q2[0] + q1[1] * q2[1] + ... + /// + /// @see gtc_quaternion + template class quatType> + GLM_FUNC_DECL T dot(quatType const & x, quatType const & y); + + /// Spherical linear interpolation of two quaternions. + /// The interpolation is oriented and the rotation is performed at constant speed. + /// For short path spherical linear interpolation, use the slerp function. + /// + /// @param x A quaternion + /// @param y A quaternion + /// @param a Interpolation factor. The interpolation is defined beyond the range [0, 1]. + /// @tparam T Value type used to build the quaternion. Supported: half, float or double. + /// @see gtc_quaternion + /// @see - slerp(tquat const & x, tquat const & y, T const & a) + template + GLM_FUNC_DECL tquat mix(tquat const & x, tquat const & y, T a); + + /// Linear interpolation of two quaternions. + /// The interpolation is oriented. + /// + /// @param x A quaternion + /// @param y A quaternion + /// @param a Interpolation factor. The interpolation is defined in the range [0, 1]. + /// @tparam T Value type used to build the quaternion. Supported: half, float or double. + /// @see gtc_quaternion + template + GLM_FUNC_DECL tquat lerp(tquat const & x, tquat const & y, T a); + + /// Spherical linear interpolation of two quaternions. + /// The interpolation always take the short path and the rotation is performed at constant speed. + /// + /// @param x A quaternion + /// @param y A quaternion + /// @param a Interpolation factor. The interpolation is defined beyond the range [0, 1]. + /// @tparam T Value type used to build the quaternion. Supported: half, float or double. + /// @see gtc_quaternion + template + GLM_FUNC_DECL tquat slerp(tquat const & x, tquat const & y, T a); + + /// Returns the q conjugate. + /// + /// @see gtc_quaternion + template + GLM_FUNC_DECL tquat conjugate(tquat const & q); + + /// Returns the q inverse. + /// + /// @see gtc_quaternion + template + GLM_FUNC_DECL tquat inverse(tquat const & q); + + /// Rotates a quaternion from a vector of 3 components axis and an angle. + /// + /// @param q Source orientation + /// @param angle Angle expressed in radians. + /// @param axis Axis of the rotation + /// + /// @see gtc_quaternion + template + GLM_FUNC_DECL tquat rotate(tquat const & q, T const & angle, tvec3 const & axis); + + /// Returns euler angles, pitch as x, yaw as y, roll as z. + /// The result is expressed in radians if GLM_FORCE_RADIANS is defined or degrees otherwise. + /// + /// @see gtc_quaternion + template + GLM_FUNC_DECL tvec3 eulerAngles(tquat const & x); + + /// Returns roll value of euler angles expressed in radians. + /// + /// @see gtx_quaternion + template + GLM_FUNC_DECL T roll(tquat const & x); + + /// Returns pitch value of euler angles expressed in radians. + /// + /// @see gtx_quaternion + template + GLM_FUNC_DECL T pitch(tquat const & x); + + /// Returns yaw value of euler angles expressed in radians. + /// + /// @see gtx_quaternion + template + GLM_FUNC_DECL T yaw(tquat const & x); + + /// Converts a quaternion to a 3 * 3 matrix. + /// + /// @see gtc_quaternion + template + GLM_FUNC_DECL tmat3x3 mat3_cast(tquat const & x); + + /// Converts a quaternion to a 4 * 4 matrix. + /// + /// @see gtc_quaternion + template + GLM_FUNC_DECL tmat4x4 mat4_cast(tquat const & x); + + /// Converts a 3 * 3 matrix to a quaternion. + /// + /// @see gtc_quaternion + template + GLM_FUNC_DECL tquat quat_cast(tmat3x3 const & x); + + /// Converts a 4 * 4 matrix to a quaternion. + /// + /// @see gtc_quaternion + template + GLM_FUNC_DECL tquat quat_cast(tmat4x4 const & x); + + /// Returns the quaternion rotation angle. + /// + /// @see gtc_quaternion + template + GLM_FUNC_DECL T angle(tquat const & x); + + /// Returns the q rotation axis. + /// + /// @see gtc_quaternion + template + GLM_FUNC_DECL tvec3 axis(tquat const & x); + + /// Build a quaternion from an angle and a normalized axis. + /// + /// @param angle Angle expressed in radians. + /// @param axis Axis of the quaternion, must be normalized. + /// + /// @see gtc_quaternion + template + GLM_FUNC_DECL tquat angleAxis(T const & angle, tvec3 const & axis); + + /// Returns the component-wise comparison result of x < y. + /// + /// @tparam quatType Floating-point quaternion types. + /// + /// @see gtc_quaternion + template + GLM_FUNC_DECL tvec4 lessThan(tquat const & x, tquat const & y); + + /// Returns the component-wise comparison of result x <= y. + /// + /// @tparam quatType Floating-point quaternion types. + /// + /// @see gtc_quaternion + template + GLM_FUNC_DECL tvec4 lessThanEqual(tquat const & x, tquat const & y); + + /// Returns the component-wise comparison of result x > y. + /// + /// @tparam quatType Floating-point quaternion types. + /// + /// @see gtc_quaternion + template + GLM_FUNC_DECL tvec4 greaterThan(tquat const & x, tquat const & y); + + /// Returns the component-wise comparison of result x >= y. + /// + /// @tparam quatType Floating-point quaternion types. + /// + /// @see gtc_quaternion + template + GLM_FUNC_DECL tvec4 greaterThanEqual(tquat const & x, tquat const & y); + + /// Returns the component-wise comparison of result x == y. + /// + /// @tparam quatType Floating-point quaternion types. + /// + /// @see gtc_quaternion + template + GLM_FUNC_DECL tvec4 equal(tquat const & x, tquat const & y); + + /// Returns the component-wise comparison of result x != y. + /// + /// @tparam quatType Floating-point quaternion types. + /// + /// @see gtc_quaternion + template + GLM_FUNC_DECL tvec4 notEqual(tquat const & x, tquat const & y); + + /// Returns true if x holds a NaN (not a number) + /// representation in the underlying implementation's set of + /// floating point representations. Returns false otherwise, + /// including for implementations with no NaN + /// representations. + /// + /// /!\ When using compiler fast math, this function may fail. + /// + /// @tparam genType Floating-point scalar or vector types. + template + GLM_FUNC_DECL tvec4 isnan(tquat const & x); + + /// Returns true if x holds a positive infinity or negative + /// infinity representation in the underlying implementation's + /// set of floating point representations. Returns false + /// otherwise, including for implementations with no infinity + /// representations. + /// + /// @tparam genType Floating-point scalar or vector types. + template + GLM_FUNC_DECL tvec4 isinf(tquat const & x); + + /// @} +} //namespace glm + +#include "quaternion.inl" diff --git a/external/include/glm/gtc/quaternion.inl b/external/include/glm/gtc/quaternion.inl new file mode 100644 index 0000000..c9b2af7 --- /dev/null +++ b/external/include/glm/gtc/quaternion.inl @@ -0,0 +1,795 @@ +/// @ref gtc_quaternion +/// @file glm/gtc/quaternion.inl + +#include "../trigonometric.hpp" +#include "../geometric.hpp" +#include "../exponential.hpp" +#include + +namespace glm{ +namespace detail +{ + template + struct compute_dot + { + static GLM_FUNC_QUALIFIER T call(tquat const& x, tquat const& y) + { + tvec4 tmp(x.x * y.x, x.y * y.y, x.z * y.z, x.w * y.w); + return (tmp.x + tmp.y) + (tmp.z + tmp.w); + } + }; + + template + struct compute_quat_add + { + static tquat call(tquat const& q, tquat const& p) + { + return tquat(q.w + p.w, q.x + p.x, q.y + p.y, q.z + p.z); + } + }; + + template + struct compute_quat_sub + { + static tquat call(tquat const& q, tquat const& p) + { + return tquat(q.w - p.w, q.x - p.x, q.y - p.y, q.z - p.z); + } + }; + + template + struct compute_quat_mul_scalar + { + static tquat call(tquat const& q, T s) + { + return tquat(q.w * s, q.x * s, q.y * s, q.z * s); + } + }; + + template + struct compute_quat_div_scalar + { + static tquat call(tquat const& q, T s) + { + return tquat(q.w / s, q.x / s, q.y / s, q.z / s); + } + }; + + template + struct compute_quat_mul_vec4 + { + static tvec4 call(tquat const & q, tvec4 const & v) + { + return tvec4(q * tvec3(v), v.w); + } + }; +}//namespace detail + + // -- Component accesses -- + + template + GLM_FUNC_QUALIFIER T & tquat::operator[](typename tquat::length_type i) + { + assert(i >= 0 && i < this->length()); + return (&x)[i]; + } + + template + GLM_FUNC_QUALIFIER T const & tquat::operator[](typename tquat::length_type i) const + { + assert(i >= 0 && i < this->length()); + return (&x)[i]; + } + + // -- Implicit basic constructors -- + +# if !GLM_HAS_DEFAULTED_FUNCTIONS || !defined(GLM_FORCE_NO_CTOR_INIT) + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR tquat::tquat() +# ifndef GLM_FORCE_NO_CTOR_INIT + : x(0), y(0), z(0), w(1) +# endif + {} +# endif + +# if !GLM_HAS_DEFAULTED_FUNCTIONS + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR tquat::tquat(tquat const & q) + : x(q.x), y(q.y), z(q.z), w(q.w) + {} +# endif//!GLM_HAS_DEFAULTED_FUNCTIONS + + template + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR tquat::tquat(tquat const & q) + : x(q.x), y(q.y), z(q.z), w(q.w) + {} + + // -- Explicit basic constructors -- + + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR tquat::tquat(ctor) + {} + + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR tquat::tquat(T const & s, tvec3 const & v) + : x(v.x), y(v.y), z(v.z), w(s) + {} + + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR tquat::tquat(T const & w, T const & x, T const & y, T const & z) + : x(x), y(y), z(z), w(w) + {} + + // -- Conversion constructors -- + + template + template + GLM_FUNC_QUALIFIER GLM_CONSTEXPR tquat::tquat(tquat const & q) + : x(static_cast(q.x)) + , y(static_cast(q.y)) + , z(static_cast(q.z)) + , w(static_cast(q.w)) + {} + + //template + //GLM_FUNC_QUALIFIER tquat::tquat + //( + // valType const & pitch, + // valType const & yaw, + // valType const & roll + //) + //{ + // tvec3 eulerAngle(pitch * valType(0.5), yaw * valType(0.5), roll * valType(0.5)); + // tvec3 c = glm::cos(eulerAngle * valType(0.5)); + // tvec3 s = glm::sin(eulerAngle * valType(0.5)); + // + // this->w = c.x * c.y * c.z + s.x * s.y * s.z; + // this->x = s.x * c.y * c.z - c.x * s.y * s.z; + // this->y = c.x * s.y * c.z + s.x * c.y * s.z; + // this->z = c.x * c.y * s.z - s.x * s.y * c.z; + //} + + template + GLM_FUNC_QUALIFIER tquat::tquat(tvec3 const & u, tvec3 const & v) + { + tvec3 const LocalW(cross(u, v)); + T Dot = detail::compute_dot::value>::call(u, v); + tquat q(T(1) + Dot, LocalW.x, LocalW.y, LocalW.z); + + *this = normalize(q); + } + + template + GLM_FUNC_QUALIFIER tquat::tquat(tvec3 const & eulerAngle) + { + tvec3 c = glm::cos(eulerAngle * T(0.5)); + tvec3 s = glm::sin(eulerAngle * T(0.5)); + + this->w = c.x * c.y * c.z + s.x * s.y * s.z; + this->x = s.x * c.y * c.z - c.x * s.y * s.z; + this->y = c.x * s.y * c.z + s.x * c.y * s.z; + this->z = c.x * c.y * s.z - s.x * s.y * c.z; + } + + template + GLM_FUNC_QUALIFIER tquat::tquat(tmat3x3 const & m) + { + *this = quat_cast(m); + } + + template + GLM_FUNC_QUALIFIER tquat::tquat(tmat4x4 const & m) + { + *this = quat_cast(m); + } + +# if GLM_HAS_EXPLICIT_CONVERSION_OPERATORS + template + GLM_FUNC_QUALIFIER tquat::operator tmat3x3() + { + return mat3_cast(*this); + } + + template + GLM_FUNC_QUALIFIER tquat::operator tmat4x4() + { + return mat4_cast(*this); + } +# endif//GLM_HAS_EXPLICIT_CONVERSION_OPERATORS + + template + GLM_FUNC_QUALIFIER tquat conjugate(tquat const & q) + { + return tquat(q.w, -q.x, -q.y, -q.z); + } + + template + GLM_FUNC_QUALIFIER tquat inverse(tquat const & q) + { + return conjugate(q) / dot(q, q); + } + + // -- Unary arithmetic operators -- + +# if !GLM_HAS_DEFAULTED_FUNCTIONS + template + GLM_FUNC_QUALIFIER tquat & tquat::operator=(tquat const & q) + { + this->w = q.w; + this->x = q.x; + this->y = q.y; + this->z = q.z; + return *this; + } +# endif//!GLM_HAS_DEFAULTED_FUNCTIONS + + template + template + GLM_FUNC_QUALIFIER tquat & tquat::operator=(tquat const & q) + { + this->w = static_cast(q.w); + this->x = static_cast(q.x); + this->y = static_cast(q.y); + this->z = static_cast(q.z); + return *this; + } + + template + template + GLM_FUNC_QUALIFIER tquat & tquat::operator+=(tquat const& q) + { + return (*this = detail::compute_quat_add::value>::call(*this, tquat(q))); + } + + template + template + GLM_FUNC_QUALIFIER tquat & tquat::operator-=(tquat const& q) + { + return (*this = detail::compute_quat_sub::value>::call(*this, tquat(q))); + } + + template + template + GLM_FUNC_QUALIFIER tquat & tquat::operator*=(tquat const & r) + { + tquat const p(*this); + tquat const q(r); + + this->w = p.w * q.w - p.x * q.x - p.y * q.y - p.z * q.z; + this->x = p.w * q.x + p.x * q.w + p.y * q.z - p.z * q.y; + this->y = p.w * q.y + p.y * q.w + p.z * q.x - p.x * q.z; + this->z = p.w * q.z + p.z * q.w + p.x * q.y - p.y * q.x; + return *this; + } + + template + template + GLM_FUNC_QUALIFIER tquat & tquat::operator*=(U s) + { + return (*this = detail::compute_quat_mul_scalar::value>::call(*this, static_cast(s))); + } + + template + template + GLM_FUNC_QUALIFIER tquat & tquat::operator/=(U s) + { + return (*this = detail::compute_quat_div_scalar::value>::call(*this, static_cast(s))); + } + + // -- Unary bit operators -- + + template + GLM_FUNC_QUALIFIER tquat operator+(tquat const & q) + { + return q; + } + + template + GLM_FUNC_QUALIFIER tquat operator-(tquat const & q) + { + return tquat(-q.w, -q.x, -q.y, -q.z); + } + + // -- Binary operators -- + + template + GLM_FUNC_QUALIFIER tquat operator+(tquat const & q, tquat const & p) + { + return tquat(q) += p; + } + + template + GLM_FUNC_QUALIFIER tquat operator*(tquat const & q, tquat const & p) + { + return tquat(q) *= p; + } + + template + GLM_FUNC_QUALIFIER tvec3 operator*(tquat const & q, tvec3 const & v) + { + tvec3 const QuatVector(q.x, q.y, q.z); + tvec3 const uv(glm::cross(QuatVector, v)); + tvec3 const uuv(glm::cross(QuatVector, uv)); + + return v + ((uv * q.w) + uuv) * static_cast(2); + } + + template + GLM_FUNC_QUALIFIER tvec3 operator*(tvec3 const & v, tquat const & q) + { + return glm::inverse(q) * v; + } + + template + GLM_FUNC_QUALIFIER tvec4 operator*(tquat const& q, tvec4 const& v) + { + return detail::compute_quat_mul_vec4::value>::call(q, v); + } + + template + GLM_FUNC_QUALIFIER tvec4 operator*(tvec4 const & v, tquat const & q) + { + return glm::inverse(q) * v; + } + + template + GLM_FUNC_QUALIFIER tquat operator*(tquat const & q, T const & s) + { + return tquat( + q.w * s, q.x * s, q.y * s, q.z * s); + } + + template + GLM_FUNC_QUALIFIER tquat operator*(T const & s, tquat const & q) + { + return q * s; + } + + template + GLM_FUNC_QUALIFIER tquat operator/(tquat const & q, T const & s) + { + return tquat( + q.w / s, q.x / s, q.y / s, q.z / s); + } + + // -- Boolean operators -- + + template + GLM_FUNC_QUALIFIER bool operator==(tquat const & q1, tquat const & q2) + { + return (q1.x == q2.x) && (q1.y == q2.y) && (q1.z == q2.z) && (q1.w == q2.w); + } + + template + GLM_FUNC_QUALIFIER bool operator!=(tquat const & q1, tquat const & q2) + { + return (q1.x != q2.x) || (q1.y != q2.y) || (q1.z != q2.z) || (q1.w != q2.w); + } + + // -- Operations -- + + template + GLM_FUNC_QUALIFIER T length(tquat const & q) + { + return glm::sqrt(dot(q, q)); + } + + template + GLM_FUNC_QUALIFIER tquat normalize(tquat const & q) + { + T len = length(q); + if(len <= T(0)) // Problem + return tquat(1, 0, 0, 0); + T oneOverLen = T(1) / len; + return tquat(q.w * oneOverLen, q.x * oneOverLen, q.y * oneOverLen, q.z * oneOverLen); + } + + template + GLM_FUNC_QUALIFIER tquat cross(tquat const & q1, tquat const & q2) + { + return tquat( + q1.w * q2.w - q1.x * q2.x - q1.y * q2.y - q1.z * q2.z, + q1.w * q2.x + q1.x * q2.w + q1.y * q2.z - q1.z * q2.y, + q1.w * q2.y + q1.y * q2.w + q1.z * q2.x - q1.x * q2.z, + q1.w * q2.z + q1.z * q2.w + q1.x * q2.y - q1.y * q2.x); + } +/* + // (x * sin(1 - a) * angle / sin(angle)) + (y * sin(a) * angle / sin(angle)) + template + GLM_FUNC_QUALIFIER tquat mix(tquat const & x, tquat const & y, T const & a) + { + if(a <= T(0)) return x; + if(a >= T(1)) return y; + + float fCos = dot(x, y); + tquat y2(y); //BUG!!! tquat y2; + if(fCos < T(0)) + { + y2 = -y; + fCos = -fCos; + } + + //if(fCos > 1.0f) // problem + float k0, k1; + if(fCos > T(0.9999)) + { + k0 = T(1) - a; + k1 = T(0) + a; //BUG!!! 1.0f + a; + } + else + { + T fSin = sqrt(T(1) - fCos * fCos); + T fAngle = atan(fSin, fCos); + T fOneOverSin = static_cast(1) / fSin; + k0 = sin((T(1) - a) * fAngle) * fOneOverSin; + k1 = sin((T(0) + a) * fAngle) * fOneOverSin; + } + + return tquat( + k0 * x.w + k1 * y2.w, + k0 * x.x + k1 * y2.x, + k0 * x.y + k1 * y2.y, + k0 * x.z + k1 * y2.z); + } + + template + GLM_FUNC_QUALIFIER tquat mix2 + ( + tquat const & x, + tquat const & y, + T const & a + ) + { + bool flip = false; + if(a <= static_cast(0)) return x; + if(a >= static_cast(1)) return y; + + T cos_t = dot(x, y); + if(cos_t < T(0)) + { + cos_t = -cos_t; + flip = true; + } + + T alpha(0), beta(0); + + if(T(1) - cos_t < 1e-7) + beta = static_cast(1) - alpha; + else + { + T theta = acos(cos_t); + T sin_t = sin(theta); + beta = sin(theta * (T(1) - alpha)) / sin_t; + alpha = sin(alpha * theta) / sin_t; + } + + if(flip) + alpha = -alpha; + + return normalize(beta * x + alpha * y); + } +*/ + + template + GLM_FUNC_QUALIFIER tquat mix(tquat const & x, tquat const & y, T a) + { + T cosTheta = dot(x, y); + + // Perform a linear interpolation when cosTheta is close to 1 to avoid side effect of sin(angle) becoming a zero denominator + if(cosTheta > T(1) - epsilon()) + { + // Linear interpolation + return tquat( + mix(x.w, y.w, a), + mix(x.x, y.x, a), + mix(x.y, y.y, a), + mix(x.z, y.z, a)); + } + else + { + // Essential Mathematics, page 467 + T angle = acos(cosTheta); + return (sin((T(1) - a) * angle) * x + sin(a * angle) * y) / sin(angle); + } + } + + template + GLM_FUNC_QUALIFIER tquat lerp(tquat const & x, tquat const & y, T a) + { + // Lerp is only defined in [0, 1] + assert(a >= static_cast(0)); + assert(a <= static_cast(1)); + + return x * (T(1) - a) + (y * a); + } + + template + GLM_FUNC_QUALIFIER tquat slerp(tquat const & x, tquat const & y, T a) + { + tquat z = y; + + T cosTheta = dot(x, y); + + // If cosTheta < 0, the interpolation will take the long way around the sphere. + // To fix this, one quat must be negated. + if (cosTheta < T(0)) + { + z = -y; + cosTheta = -cosTheta; + } + + // Perform a linear interpolation when cosTheta is close to 1 to avoid side effect of sin(angle) becoming a zero denominator + if(cosTheta > T(1) - epsilon()) + { + // Linear interpolation + return tquat( + mix(x.w, z.w, a), + mix(x.x, z.x, a), + mix(x.y, z.y, a), + mix(x.z, z.z, a)); + } + else + { + // Essential Mathematics, page 467 + T angle = acos(cosTheta); + return (sin((T(1) - a) * angle) * x + sin(a * angle) * z) / sin(angle); + } + } + + template + GLM_FUNC_QUALIFIER tquat rotate(tquat const & q, T const & angle, tvec3 const & v) + { + tvec3 Tmp = v; + + // Axis of rotation must be normalised + T len = glm::length(Tmp); + if(abs(len - T(1)) > T(0.001)) + { + T oneOverLen = static_cast(1) / len; + Tmp.x *= oneOverLen; + Tmp.y *= oneOverLen; + Tmp.z *= oneOverLen; + } + + T const AngleRad(angle); + T const Sin = sin(AngleRad * T(0.5)); + + return q * tquat(cos(AngleRad * T(0.5)), Tmp.x * Sin, Tmp.y * Sin, Tmp.z * Sin); + //return gtc::quaternion::cross(q, tquat(cos(AngleRad * T(0.5)), Tmp.x * fSin, Tmp.y * fSin, Tmp.z * fSin)); + } + + template + GLM_FUNC_QUALIFIER tvec3 eulerAngles(tquat const & x) + { + return tvec3(pitch(x), yaw(x), roll(x)); + } + + template + GLM_FUNC_QUALIFIER T roll(tquat const & q) + { + return T(atan(T(2) * (q.x * q.y + q.w * q.z), q.w * q.w + q.x * q.x - q.y * q.y - q.z * q.z)); + } + + template + GLM_FUNC_QUALIFIER T pitch(tquat const & q) + { + return T(atan(T(2) * (q.y * q.z + q.w * q.x), q.w * q.w - q.x * q.x - q.y * q.y + q.z * q.z)); + } + + template + GLM_FUNC_QUALIFIER T yaw(tquat const & q) + { + return asin(clamp(T(-2) * (q.x * q.z - q.w * q.y), T(-1), T(1))); + } + + template + GLM_FUNC_QUALIFIER tmat3x3 mat3_cast(tquat const & q) + { + tmat3x3 Result(T(1)); + T qxx(q.x * q.x); + T qyy(q.y * q.y); + T qzz(q.z * q.z); + T qxz(q.x * q.z); + T qxy(q.x * q.y); + T qyz(q.y * q.z); + T qwx(q.w * q.x); + T qwy(q.w * q.y); + T qwz(q.w * q.z); + + Result[0][0] = T(1) - T(2) * (qyy + qzz); + Result[0][1] = T(2) * (qxy + qwz); + Result[0][2] = T(2) * (qxz - qwy); + + Result[1][0] = T(2) * (qxy - qwz); + Result[1][1] = T(1) - T(2) * (qxx + qzz); + Result[1][2] = T(2) * (qyz + qwx); + + Result[2][0] = T(2) * (qxz + qwy); + Result[2][1] = T(2) * (qyz - qwx); + Result[2][2] = T(1) - T(2) * (qxx + qyy); + return Result; + } + + template + GLM_FUNC_QUALIFIER tmat4x4 mat4_cast(tquat const & q) + { + return tmat4x4(mat3_cast(q)); + } + + template + GLM_FUNC_QUALIFIER tquat quat_cast(tmat3x3 const & m) + { + T fourXSquaredMinus1 = m[0][0] - m[1][1] - m[2][2]; + T fourYSquaredMinus1 = m[1][1] - m[0][0] - m[2][2]; + T fourZSquaredMinus1 = m[2][2] - m[0][0] - m[1][1]; + T fourWSquaredMinus1 = m[0][0] + m[1][1] + m[2][2]; + + int biggestIndex = 0; + T fourBiggestSquaredMinus1 = fourWSquaredMinus1; + if(fourXSquaredMinus1 > fourBiggestSquaredMinus1) + { + fourBiggestSquaredMinus1 = fourXSquaredMinus1; + biggestIndex = 1; + } + if(fourYSquaredMinus1 > fourBiggestSquaredMinus1) + { + fourBiggestSquaredMinus1 = fourYSquaredMinus1; + biggestIndex = 2; + } + if(fourZSquaredMinus1 > fourBiggestSquaredMinus1) + { + fourBiggestSquaredMinus1 = fourZSquaredMinus1; + biggestIndex = 3; + } + + T biggestVal = sqrt(fourBiggestSquaredMinus1 + T(1)) * T(0.5); + T mult = static_cast(0.25) / biggestVal; + + tquat Result(uninitialize); + switch(biggestIndex) + { + case 0: + Result.w = biggestVal; + Result.x = (m[1][2] - m[2][1]) * mult; + Result.y = (m[2][0] - m[0][2]) * mult; + Result.z = (m[0][1] - m[1][0]) * mult; + break; + case 1: + Result.w = (m[1][2] - m[2][1]) * mult; + Result.x = biggestVal; + Result.y = (m[0][1] + m[1][0]) * mult; + Result.z = (m[2][0] + m[0][2]) * mult; + break; + case 2: + Result.w = (m[2][0] - m[0][2]) * mult; + Result.x = (m[0][1] + m[1][0]) * mult; + Result.y = biggestVal; + Result.z = (m[1][2] + m[2][1]) * mult; + break; + case 3: + Result.w = (m[0][1] - m[1][0]) * mult; + Result.x = (m[2][0] + m[0][2]) * mult; + Result.y = (m[1][2] + m[2][1]) * mult; + Result.z = biggestVal; + break; + + default: // Silence a -Wswitch-default warning in GCC. Should never actually get here. Assert is just for sanity. + assert(false); + break; + } + return Result; + } + + template + GLM_FUNC_QUALIFIER tquat quat_cast(tmat4x4 const & m4) + { + return quat_cast(tmat3x3(m4)); + } + + template + GLM_FUNC_QUALIFIER T angle(tquat const & x) + { + return acos(x.w) * T(2); + } + + template + GLM_FUNC_QUALIFIER tvec3 axis(tquat const & x) + { + T tmp1 = static_cast(1) - x.w * x.w; + if(tmp1 <= static_cast(0)) + return tvec3(0, 0, 1); + T tmp2 = static_cast(1) / sqrt(tmp1); + return tvec3(x.x * tmp2, x.y * tmp2, x.z * tmp2); + } + + template + GLM_FUNC_QUALIFIER tquat angleAxis(T const & angle, tvec3 const & v) + { + tquat Result(uninitialize); + + T const a(angle); + T const s = glm::sin(a * static_cast(0.5)); + + Result.w = glm::cos(a * static_cast(0.5)); + Result.x = v.x * s; + Result.y = v.y * s; + Result.z = v.z * s; + return Result; + } + + template + GLM_FUNC_QUALIFIER tvec4 lessThan(tquat const & x, tquat const & y) + { + tvec4 Result(uninitialize); + for(length_t i = 0; i < x.length(); ++i) + Result[i] = x[i] < y[i]; + return Result; + } + + template + GLM_FUNC_QUALIFIER tvec4 lessThanEqual(tquat const & x, tquat const & y) + { + tvec4 Result(uninitialize); + for(length_t i = 0; i < x.length(); ++i) + Result[i] = x[i] <= y[i]; + return Result; + } + + template + GLM_FUNC_QUALIFIER tvec4 greaterThan(tquat const & x, tquat const & y) + { + tvec4 Result(uninitialize); + for(length_t i = 0; i < x.length(); ++i) + Result[i] = x[i] > y[i]; + return Result; + } + + template + GLM_FUNC_QUALIFIER tvec4 greaterThanEqual(tquat const & x, tquat const & y) + { + tvec4 Result(uninitialize); + for(length_t i = 0; i < x.length(); ++i) + Result[i] = x[i] >= y[i]; + return Result; + } + + template + GLM_FUNC_QUALIFIER tvec4 equal(tquat const & x, tquat const & y) + { + tvec4 Result(uninitialize); + for(length_t i = 0; i < x.length(); ++i) + Result[i] = x[i] == y[i]; + return Result; + } + + template + GLM_FUNC_QUALIFIER tvec4 notEqual(tquat const & x, tquat const & y) + { + tvec4 Result(uninitialize); + for(length_t i = 0; i < x.length(); ++i) + Result[i] = x[i] != y[i]; + return Result; + } + + template + GLM_FUNC_QUALIFIER tvec4 isnan(tquat const& q) + { + GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'isnan' only accept floating-point inputs"); + + return tvec4(isnan(q.x), isnan(q.y), isnan(q.z), isnan(q.w)); + } + + template + GLM_FUNC_QUALIFIER tvec4 isinf(tquat const& q) + { + GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'isinf' only accept floating-point inputs"); + + return tvec4(isinf(q.x), isinf(q.y), isinf(q.z), isinf(q.w)); + } +}//namespace glm + +#if GLM_ARCH != GLM_ARCH_PURE && GLM_HAS_ALIGNED_TYPE +# include "quaternion_simd.inl" +#endif + diff --git a/external/include/glm/gtc/quaternion_simd.inl b/external/include/glm/gtc/quaternion_simd.inl new file mode 100644 index 0000000..cca874b --- /dev/null +++ b/external/include/glm/gtc/quaternion_simd.inl @@ -0,0 +1,198 @@ +/// @ref core +/// @file glm/gtc/quaternion_simd.inl + +#if GLM_ARCH & GLM_ARCH_SSE2_BIT + +namespace glm{ +namespace detail +{ +/* + template + struct compute_quat_mul + { + static tquat call(tquat const& q1, tquat const& q2) + { + // SSE2 STATS: 11 shuffle, 8 mul, 8 add + // SSE4 STATS: 3 shuffle, 4 mul, 4 dpps + + __m128 const mul0 = _mm_mul_ps(q1.Data, _mm_shuffle_ps(q2.Data, q2.Data, _MM_SHUFFLE(0, 1, 2, 3))); + __m128 const mul1 = _mm_mul_ps(q1.Data, _mm_shuffle_ps(q2.Data, q2.Data, _MM_SHUFFLE(1, 0, 3, 2))); + __m128 const mul2 = _mm_mul_ps(q1.Data, _mm_shuffle_ps(q2.Data, q2.Data, _MM_SHUFFLE(2, 3, 0, 1))); + __m128 const mul3 = _mm_mul_ps(q1.Data, q2.Data); + +# if GLM_ARCH & GLM_ARCH_SSE41_BIT + __m128 const add0 = _mm_dp_ps(mul0, _mm_set_ps(1.0f, -1.0f, 1.0f, 1.0f), 0xff); + __m128 const add1 = _mm_dp_ps(mul1, _mm_set_ps(1.0f, 1.0f, 1.0f, -1.0f), 0xff); + __m128 const add2 = _mm_dp_ps(mul2, _mm_set_ps(1.0f, 1.0f, -1.0f, 1.0f), 0xff); + __m128 const add3 = _mm_dp_ps(mul3, _mm_set_ps(1.0f, -1.0f, -1.0f, -1.0f), 0xff); +# else + __m128 const mul4 = _mm_mul_ps(mul0, _mm_set_ps(1.0f, -1.0f, 1.0f, 1.0f)); + __m128 const add0 = _mm_add_ps(mul0, _mm_movehl_ps(mul4, mul4)); + __m128 const add4 = _mm_add_ss(add0, _mm_shuffle_ps(add0, add0, 1)); + + __m128 const mul5 = _mm_mul_ps(mul1, _mm_set_ps(1.0f, 1.0f, 1.0f, -1.0f)); + __m128 const add1 = _mm_add_ps(mul1, _mm_movehl_ps(mul5, mul5)); + __m128 const add5 = _mm_add_ss(add1, _mm_shuffle_ps(add1, add1, 1)); + + __m128 const mul6 = _mm_mul_ps(mul2, _mm_set_ps(1.0f, 1.0f, -1.0f, 1.0f)); + __m128 const add2 = _mm_add_ps(mul6, _mm_movehl_ps(mul6, mul6)); + __m128 const add6 = _mm_add_ss(add2, _mm_shuffle_ps(add2, add2, 1)); + + __m128 const mul7 = _mm_mul_ps(mul3, _mm_set_ps(1.0f, -1.0f, -1.0f, -1.0f)); + __m128 const add3 = _mm_add_ps(mul3, _mm_movehl_ps(mul7, mul7)); + __m128 const add7 = _mm_add_ss(add3, _mm_shuffle_ps(add3, add3, 1)); + #endif + + // This SIMD code is a politically correct way of doing this, but in every test I've tried it has been slower than + // the final code below. I'll keep this here for reference - maybe somebody else can do something better... + // + //__m128 xxyy = _mm_shuffle_ps(add4, add5, _MM_SHUFFLE(0, 0, 0, 0)); + //__m128 zzww = _mm_shuffle_ps(add6, add7, _MM_SHUFFLE(0, 0, 0, 0)); + // + //return _mm_shuffle_ps(xxyy, zzww, _MM_SHUFFLE(2, 0, 2, 0)); + + tquat Result(uninitialize); + _mm_store_ss(&Result.x, add4); + _mm_store_ss(&Result.y, add5); + _mm_store_ss(&Result.z, add6); + _mm_store_ss(&Result.w, add7); + return Result; + } + }; +*/ + + template + struct compute_dot + { + static GLM_FUNC_QUALIFIER float call(tquat const& x, tquat const& y) + { + return _mm_cvtss_f32(glm_vec1_dot(x.data, y.data)); + } + }; + + template + struct compute_quat_add + { + static tquat call(tquat const& q, tquat const& p) + { + tquat Result(uninitialize); + Result.data = _mm_add_ps(q.data, p.data); + return Result; + } + }; + +# if GLM_ARCH & GLM_ARCH_AVX_BIT + template + struct compute_quat_add + { + static tquat call(tquat const & a, tquat const & b) + { + tquat Result(uninitialize); + Result.data = _mm256_add_pd(a.data, b.data); + return Result; + } + }; +# endif + + template + struct compute_quat_sub + { + static tquat call(tquat const& q, tquat const& p) + { + tvec4 Result(uninitialize); + Result.data = _mm_sub_ps(q.data, p.data); + return Result; + } + }; + +# if GLM_ARCH & GLM_ARCH_AVX_BIT + template + struct compute_quat_sub + { + static tquat call(tquat const & a, tquat const & b) + { + tquat Result(uninitialize); + Result.data = _mm256_sub_pd(a.data, b.data); + return Result; + } + }; +# endif + + template + struct compute_quat_mul_scalar + { + static tquat call(tquat const& q, float s) + { + tvec4 Result(uninitialize); + Result.data = _mm_mul_ps(q.data, _mm_set_ps1(s)); + return Result; + } + }; + +# if GLM_ARCH & GLM_ARCH_AVX_BIT + template + struct compute_quat_mul_scalar + { + static tquat call(tquat const& q, double s) + { + tquat Result(uninitialize); + Result.data = _mm256_mul_pd(q.data, _mm_set_ps1(s)); + return Result; + } + }; +# endif + + template + struct compute_quat_div_scalar + { + static tquat call(tquat const& q, float s) + { + tvec4 Result(uninitialize); + Result.data = _mm_div_ps(q.data, _mm_set_ps1(s)); + return Result; + } + }; + +# if GLM_ARCH & GLM_ARCH_AVX_BIT + template + struct compute_quat_div_scalar + { + static tquat call(tquat const& q, double s) + { + tquat Result(uninitialize); + Result.data = _mm256_div_pd(q.data, _mm_set_ps1(s)); + return Result; + } + }; +# endif + + template + struct compute_quat_mul_vec4 + { + static tvec4 call(tquat const& q, tvec4 const& v) + { + __m128 const q_wwww = _mm_shuffle_ps(q.data, q.data, _MM_SHUFFLE(3, 3, 3, 3)); + __m128 const q_swp0 = _mm_shuffle_ps(q.data, q.data, _MM_SHUFFLE(3, 0, 2, 1)); + __m128 const q_swp1 = _mm_shuffle_ps(q.data, q.data, _MM_SHUFFLE(3, 1, 0, 2)); + __m128 const v_swp0 = _mm_shuffle_ps(v.data, v.data, _MM_SHUFFLE(3, 0, 2, 1)); + __m128 const v_swp1 = _mm_shuffle_ps(v.data, v.data, _MM_SHUFFLE(3, 1, 0, 2)); + + __m128 uv = _mm_sub_ps(_mm_mul_ps(q_swp0, v_swp1), _mm_mul_ps(q_swp1, v_swp0)); + __m128 uv_swp0 = _mm_shuffle_ps(uv, uv, _MM_SHUFFLE(3, 0, 2, 1)); + __m128 uv_swp1 = _mm_shuffle_ps(uv, uv, _MM_SHUFFLE(3, 1, 0, 2)); + __m128 uuv = _mm_sub_ps(_mm_mul_ps(q_swp0, uv_swp1), _mm_mul_ps(q_swp1, uv_swp0)); + + __m128 const two = _mm_set1_ps(2.0f); + uv = _mm_mul_ps(uv, _mm_mul_ps(q_wwww, two)); + uuv = _mm_mul_ps(uuv, two); + + tvec4 Result(uninitialize); + Result.data = _mm_add_ps(v.Data, _mm_add_ps(uv, uuv)); + return Result; + } + }; +}//namespace detail +}//namespace glm + +#endif//GLM_ARCH & GLM_ARCH_SSE2_BIT + diff --git a/external/include/glm/gtc/random.hpp b/external/include/glm/gtc/random.hpp new file mode 100644 index 0000000..fa3956e --- /dev/null +++ b/external/include/glm/gtc/random.hpp @@ -0,0 +1,98 @@ +/// @ref gtc_random +/// @file glm/gtc/random.hpp +/// +/// @see core (dependence) +/// @see gtc_half_float (dependence) +/// @see gtx_random (extended) +/// +/// @defgroup gtc_random GLM_GTC_random +/// @ingroup gtc +/// +/// @brief Generate random number from various distribution methods. +/// +/// need to be included to use these functionalities. + +#pragma once + +// Dependency: +#include "../vec2.hpp" +#include "../vec3.hpp" + +#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_EXT_INCLUDED) +# pragma message("GLM: GLM_GTC_random extension included") +#endif + +namespace glm +{ + /// @addtogroup gtc_random + /// @{ + + /// Generate random numbers in the interval [Min, Max], according a linear distribution + /// + /// @param Min + /// @param Max + /// @tparam genType Value type. Currently supported: float or double scalars. + /// @see gtc_random + template + GLM_FUNC_DECL genTYpe linearRand( + genTYpe Min, + genTYpe Max); + + /// Generate random numbers in the interval [Min, Max], according a linear distribution + /// + /// @param Min + /// @param Max + /// @tparam T Value type. Currently supported: float or double. + /// @tparam vecType A vertor type: tvec1, tvec2, tvec3, tvec4 or compatible + /// @see gtc_random + template class vecType> + GLM_FUNC_DECL vecType linearRand( + vecType const & Min, + vecType const & Max); + + /// Generate random numbers in the interval [Min, Max], according a gaussian distribution + /// + /// @param Mean + /// @param Deviation + /// @see gtc_random + template + GLM_FUNC_DECL genType gaussRand( + genType Mean, + genType Deviation); + + /// Generate a random 2D vector which coordinates are regulary distributed on a circle of a given radius + /// + /// @param Radius + /// @see gtc_random + template + GLM_FUNC_DECL tvec2 circularRand( + T Radius); + + /// Generate a random 3D vector which coordinates are regulary distributed on a sphere of a given radius + /// + /// @param Radius + /// @see gtc_random + template + GLM_FUNC_DECL tvec3 sphericalRand( + T Radius); + + /// Generate a random 2D vector which coordinates are regulary distributed within the area of a disk of a given radius + /// + /// @param Radius + /// @see gtc_random + template + GLM_FUNC_DECL tvec2 diskRand( + T Radius); + + /// Generate a random 3D vector which coordinates are regulary distributed within the volume of a ball of a given radius + /// + /// @param Radius + /// @see gtc_random + template + GLM_FUNC_DECL tvec3 ballRand( + T Radius); + + /// @} +}//namespace glm + +#include "random.inl" diff --git a/external/include/glm/gtc/random.inl b/external/include/glm/gtc/random.inl new file mode 100644 index 0000000..ad5926e --- /dev/null +++ b/external/include/glm/gtc/random.inl @@ -0,0 +1,350 @@ +/// @ref gtc_random +/// @file glm/gtc/random.inl + +#include "../geometric.hpp" +#include "../exponential.hpp" +#include +#include +#include + +namespace glm{ +namespace detail +{ + template class vecType> + struct compute_rand + { + GLM_FUNC_QUALIFIER static vecType call(); + }; + + template + struct compute_rand + { + GLM_FUNC_QUALIFIER static tvec1 call() + { + return tvec1( + std::rand() % std::numeric_limits::max()); + } + }; + + template + struct compute_rand + { + GLM_FUNC_QUALIFIER static tvec2 call() + { + return tvec2( + std::rand() % std::numeric_limits::max(), + std::rand() % std::numeric_limits::max()); + } + }; + + template + struct compute_rand + { + GLM_FUNC_QUALIFIER static tvec3 call() + { + return tvec3( + std::rand() % std::numeric_limits::max(), + std::rand() % std::numeric_limits::max(), + std::rand() % std::numeric_limits::max()); + } + }; + + template + struct compute_rand + { + GLM_FUNC_QUALIFIER static tvec4 call() + { + return tvec4( + std::rand() % std::numeric_limits::max(), + std::rand() % std::numeric_limits::max(), + std::rand() % std::numeric_limits::max(), + std::rand() % std::numeric_limits::max()); + } + }; + + template class vecType> + struct compute_rand + { + GLM_FUNC_QUALIFIER static vecType call() + { + return + (vecType(compute_rand::call()) << static_cast(8)) | + (vecType(compute_rand::call()) << static_cast(0)); + } + }; + + template class vecType> + struct compute_rand + { + GLM_FUNC_QUALIFIER static vecType call() + { + return + (vecType(compute_rand::call()) << static_cast(16)) | + (vecType(compute_rand::call()) << static_cast(0)); + } + }; + + template class vecType> + struct compute_rand + { + GLM_FUNC_QUALIFIER static vecType call() + { + return + (vecType(compute_rand::call()) << static_cast(32)) | + (vecType(compute_rand::call()) << static_cast(0)); + } + }; + + template class vecType> + struct compute_linearRand + { + GLM_FUNC_QUALIFIER static vecType call(vecType const & Min, vecType const & Max); + }; + + template class vecType> + struct compute_linearRand + { + GLM_FUNC_QUALIFIER static vecType call(vecType const & Min, vecType const & Max) + { + return (vecType(compute_rand::call() % vecType(Max + static_cast(1) - Min))) + Min; + } + }; + + template class vecType> + struct compute_linearRand + { + GLM_FUNC_QUALIFIER static vecType call(vecType const & Min, vecType const & Max) + { + return (compute_rand::call() % (Max + static_cast(1) - Min)) + Min; + } + }; + + template class vecType> + struct compute_linearRand + { + GLM_FUNC_QUALIFIER static vecType call(vecType const & Min, vecType const & Max) + { + return (vecType(compute_rand::call() % vecType(Max + static_cast(1) - Min))) + Min; + } + }; + + template class vecType> + struct compute_linearRand + { + GLM_FUNC_QUALIFIER static vecType call(vecType const & Min, vecType const & Max) + { + return (compute_rand::call() % (Max + static_cast(1) - Min)) + Min; + } + }; + + template class vecType> + struct compute_linearRand + { + GLM_FUNC_QUALIFIER static vecType call(vecType const & Min, vecType const & Max) + { + return (vecType(compute_rand::call() % vecType(Max + static_cast(1) - Min))) + Min; + } + }; + + template class vecType> + struct compute_linearRand + { + GLM_FUNC_QUALIFIER static vecType call(vecType const & Min, vecType const & Max) + { + return (compute_rand::call() % (Max + static_cast(1) - Min)) + Min; + } + }; + + template class vecType> + struct compute_linearRand + { + GLM_FUNC_QUALIFIER static vecType call(vecType const & Min, vecType const & Max) + { + return (vecType(compute_rand::call() % vecType(Max + static_cast(1) - Min))) + Min; + } + }; + + template class vecType> + struct compute_linearRand + { + GLM_FUNC_QUALIFIER static vecType call(vecType const & Min, vecType const & Max) + { + return (compute_rand::call() % (Max + static_cast(1) - Min)) + Min; + } + }; + + template