Fixed cast and clean up

master
Christophe Riccio ago%!(EXTRA string=9 years)
parent ad262c3592
commit 1c5fd06c2d
  1. 8
      glm/gtc/bitfield.inl
  2. 16
      glm/gtc/color_space.inl
  3. 219
      glm/gtc/matrix_transform.inl
  4. 70
      glm/gtx/quaternion.inl
  5. 19
      glm/gtx/transform.inl
  6. 86
      glm/gtx/transform2.inl

@ -231,7 +231,7 @@ namespace detail
} }
template <typename T, precision P, template <typename, precision> class vecIUType> template <typename T, precision P, template <typename, precision> class vecIUType>
GLM_FUNC_QUALIFIER vecIUType<T, P> mask(vecIUType<T, P> const & v) GLM_FUNC_QUALIFIER vecIUType<T, P> mask(vecIUType<T, P> const& v)
{ {
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_integer, "'mask' accepts only integer values"); GLM_STATIC_ASSERT(std::numeric_limits<T>::is_integer, "'mask' accepts only integer values");
@ -266,7 +266,7 @@ namespace detail
} }
template <typename T, precision P, template <typename, precision> class vecType> template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> bitfieldRotateLeft(vecType<T, P> const & In, int Shift) GLM_FUNC_QUALIFIER vecType<T, P> bitfieldRotateLeft(vecType<T, P> const& In, int Shift)
{ {
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_integer, "'bitfieldRotateLeft' accepts only integer values"); GLM_STATIC_ASSERT(std::numeric_limits<T>::is_integer, "'bitfieldRotateLeft' accepts only integer values");
@ -281,7 +281,7 @@ namespace detail
} }
template <typename T, precision P, template <typename, precision> class vecType> template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> bitfieldFillOne(vecType<T, P> const & Value, int FirstBit, int BitCount) GLM_FUNC_QUALIFIER vecType<T, P> bitfieldFillOne(vecType<T, P> const& Value, int FirstBit, int BitCount)
{ {
return Value | static_cast<T>(mask(BitCount) << FirstBit); return Value | static_cast<T>(mask(BitCount) << FirstBit);
} }
@ -293,7 +293,7 @@ namespace detail
} }
template <typename T, precision P, template <typename, precision> class vecType> template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> bitfieldFillZero(vecType<T, P> const & Value, int FirstBit, int BitCount) GLM_FUNC_QUALIFIER vecType<T, P> bitfieldFillZero(vecType<T, P> const& Value, int FirstBit, int BitCount)
{ {
return Value & static_cast<T>(~(mask(BitCount) << FirstBit)); return Value & static_cast<T>(~(mask(BitCount) << FirstBit));
} }

@ -7,7 +7,7 @@ namespace detail
template <typename T, precision P, template <typename, precision> class vecType> template <typename T, precision P, template <typename, precision> class vecType>
struct compute_rgbToSrgb struct compute_rgbToSrgb
{ {
GLM_FUNC_QUALIFIER static vecType<T, P> call(vecType<T, P> const & ColorRGB, T GammaCorrection) GLM_FUNC_QUALIFIER static vecType<T, P> call(vecType<T, P> const& ColorRGB, T GammaCorrection)
{ {
vecType<T, P> const ClampedColor(clamp(ColorRGB, static_cast<T>(0), static_cast<T>(1))); vecType<T, P> const ClampedColor(clamp(ColorRGB, static_cast<T>(0), static_cast<T>(1)));
@ -21,7 +21,7 @@ namespace detail
template <typename T, precision P> template <typename T, precision P>
struct compute_rgbToSrgb<T, P, tvec4> struct compute_rgbToSrgb<T, P, tvec4>
{ {
GLM_FUNC_QUALIFIER static tvec4<T, P> call(tvec4<T, P> const & ColorRGB, T GammaCorrection) GLM_FUNC_QUALIFIER static tvec4<T, P> call(tvec4<T, P> const& ColorRGB, T GammaCorrection)
{ {
return tvec4<T, P>(compute_rgbToSrgb<T, P, tvec3>::call(tvec3<T, P>(ColorRGB), GammaCorrection), ColorRGB.a); return tvec4<T, P>(compute_rgbToSrgb<T, P, tvec3>::call(tvec3<T, P>(ColorRGB), GammaCorrection), ColorRGB.a);
} }
@ -30,7 +30,7 @@ namespace detail
template <typename T, precision P, template <typename, precision> class vecType> template <typename T, precision P, template <typename, precision> class vecType>
struct compute_srgbToRgb struct compute_srgbToRgb
{ {
GLM_FUNC_QUALIFIER static vecType<T, P> call(vecType<T, P> const & ColorSRGB, T Gamma) GLM_FUNC_QUALIFIER static vecType<T, P> call(vecType<T, P> const& ColorSRGB, T Gamma)
{ {
return mix( return mix(
pow((ColorSRGB + static_cast<T>(0.055)) * static_cast<T>(0.94786729857819905213270142180095), vecType<T, P>(Gamma)), pow((ColorSRGB + static_cast<T>(0.055)) * static_cast<T>(0.94786729857819905213270142180095), vecType<T, P>(Gamma)),
@ -42,7 +42,7 @@ namespace detail
template <typename T, precision P> template <typename T, precision P>
struct compute_srgbToRgb<T, P, tvec4> struct compute_srgbToRgb<T, P, tvec4>
{ {
GLM_FUNC_QUALIFIER static tvec4<T, P> call(tvec4<T, P> const & ColorSRGB, T Gamma) GLM_FUNC_QUALIFIER static tvec4<T, P> call(tvec4<T, P> const& ColorSRGB, T Gamma)
{ {
return tvec4<T, P>(compute_srgbToRgb<T, P, tvec3>::call(tvec3<T, P>(ColorSRGB), Gamma), ColorSRGB.a); return tvec4<T, P>(compute_srgbToRgb<T, P, tvec3>::call(tvec3<T, P>(ColorSRGB), Gamma), ColorSRGB.a);
} }
@ -50,25 +50,25 @@ namespace detail
}//namespace detail }//namespace detail
template <typename T, precision P, template <typename, precision> class vecType> template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> convertLinearToSRGB(vecType<T, P> const & ColorLinear) GLM_FUNC_QUALIFIER vecType<T, P> convertLinearToSRGB(vecType<T, P> const& ColorLinear)
{ {
return detail::compute_rgbToSrgb<T, P, vecType>::call(ColorLinear, static_cast<T>(0.41666)); return detail::compute_rgbToSrgb<T, P, vecType>::call(ColorLinear, static_cast<T>(0.41666));
} }
template <typename T, precision P, template <typename, precision> class vecType> template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> convertLinearToSRGB(vecType<T, P> const & ColorLinear, T Gamma) GLM_FUNC_QUALIFIER vecType<T, P> convertLinearToSRGB(vecType<T, P> const& ColorLinear, T Gamma)
{ {
return detail::compute_rgbToSrgb<T, P, vecType>::call(ColorLinear, static_cast<T>(1) / Gamma); return detail::compute_rgbToSrgb<T, P, vecType>::call(ColorLinear, static_cast<T>(1) / Gamma);
} }
template <typename T, precision P, template <typename, precision> class vecType> template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> convertSRGBToLinear(vecType<T, P> const & ColorSRGB) GLM_FUNC_QUALIFIER vecType<T, P> convertSRGBToLinear(vecType<T, P> const& ColorSRGB)
{ {
return detail::compute_srgbToRgb<T, P, vecType>::call(ColorSRGB, static_cast<T>(2.4)); return detail::compute_srgbToRgb<T, P, vecType>::call(ColorSRGB, static_cast<T>(2.4));
} }
template <typename T, precision P, template <typename, precision> class vecType> template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> convertSRGBToLinear(vecType<T, P> const & ColorSRGB, T Gamma) GLM_FUNC_QUALIFIER vecType<T, P> convertSRGBToLinear(vecType<T, P> const& ColorSRGB, T Gamma)
{ {
return detail::compute_srgbToRgb<T, P, vecType>::call(ColorSRGB, Gamma); return detail::compute_srgbToRgb<T, P, vecType>::call(ColorSRGB, Gamma);
} }

@ -8,11 +8,7 @@
namespace glm namespace glm
{ {
template <typename T, precision P> template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat4x4<T, P> translate GLM_FUNC_QUALIFIER tmat4x4<T, P> translate(tmat4x4<T, P> const & m, tvec3<T, P> const & v)
(
tmat4x4<T, P> const & m,
tvec3<T, P> const & v
)
{ {
tmat4x4<T, P> Result(m); tmat4x4<T, P> Result(m);
Result[3] = m[0] * v[0] + m[1] * v[1] + m[2] * v[2] + m[3]; Result[3] = m[0] * v[0] + m[1] * v[1] + m[2] * v[2] + m[3];
@ -20,12 +16,7 @@ namespace glm
} }
template <typename T, precision P> template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat4x4<T, P> rotate GLM_FUNC_QUALIFIER tmat4x4<T, P> rotate(tmat4x4<T, P> const & m, T angle, tvec3<T, P> const & v)
(
tmat4x4<T, P> const & m,
T angle,
tvec3<T, P> const & v
)
{ {
T const a = angle; T const a = angle;
T const c = cos(a); T const c = cos(a);
@ -36,15 +27,15 @@ namespace glm
tmat4x4<T, P> Rotate(uninitialize); tmat4x4<T, P> Rotate(uninitialize);
Rotate[0][0] = c + temp[0] * axis[0]; Rotate[0][0] = c + temp[0] * axis[0];
Rotate[0][1] = 0 + temp[0] * axis[1] + s * axis[2]; Rotate[0][1] = temp[0] * axis[1] + s * axis[2];
Rotate[0][2] = 0 + temp[0] * axis[2] - s * axis[1]; Rotate[0][2] = temp[0] * axis[2] - s * axis[1];
Rotate[1][0] = 0 + temp[1] * axis[0] - s * axis[2]; Rotate[1][0] = temp[1] * axis[0] - s * axis[2];
Rotate[1][1] = c + temp[1] * axis[1]; Rotate[1][1] = c + temp[1] * axis[1];
Rotate[1][2] = 0 + temp[1] * axis[2] + s * axis[0]; Rotate[1][2] = temp[1] * axis[2] + s * axis[0];
Rotate[2][0] = 0 + temp[2] * axis[0] + s * axis[1]; Rotate[2][0] = temp[2] * axis[0] + s * axis[1];
Rotate[2][1] = 0 + temp[2] * axis[1] - s * axis[0]; Rotate[2][1] = temp[2] * axis[1] - s * axis[0];
Rotate[2][2] = c + temp[2] * axis[2]; Rotate[2][2] = c + temp[2] * axis[2];
tmat4x4<T, P> Result(uninitialize); tmat4x4<T, P> Result(uninitialize);
@ -56,12 +47,7 @@ namespace glm
} }
template <typename T, precision P> template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat4x4<T, P> rotate_slow GLM_FUNC_QUALIFIER tmat4x4<T, P> rotate_slow(tmat4x4<T, P> const & m, T angle, tvec3<T, P> const & v)
(
tmat4x4<T, P> const & m,
T angle,
tvec3<T, P> const & v
)
{ {
T const a = angle; T const a = angle;
T const c = cos(a); T const c = cos(a);
@ -70,31 +56,27 @@ namespace glm
tvec3<T, P> axis = normalize(v); tvec3<T, P> axis = normalize(v);
Result[0][0] = c + (1 - c) * axis.x * axis.x; Result[0][0] = c + (static_cast<T>(1) - c) * axis.x * axis.x;
Result[0][1] = (1 - c) * axis.x * axis.y + s * axis.z; Result[0][1] = (static_cast<T>(1) - c) * axis.x * axis.y + s * axis.z;
Result[0][2] = (1 - c) * axis.x * axis.z - s * axis.y; Result[0][2] = (static_cast<T>(1) - c) * axis.x * axis.z - s * axis.y;
Result[0][3] = 0; Result[0][3] = static_cast<T>(0);
Result[1][0] = (1 - c) * axis.y * axis.x - s * axis.z; Result[1][0] = (static_cast<T>(1) - c) * axis.y * axis.x - s * axis.z;
Result[1][1] = c + (1 - c) * axis.y * axis.y; Result[1][1] = c + (static_cast<T>(1) - c) * axis.y * axis.y;
Result[1][2] = (1 - c) * axis.y * axis.z + s * axis.x; Result[1][2] = (static_cast<T>(1) - c) * axis.y * axis.z + s * axis.x;
Result[1][3] = 0; Result[1][3] = static_cast<T>(0);
Result[2][0] = (1 - c) * axis.z * axis.x + s * axis.y; Result[2][0] = (static_cast<T>(1) - c) * axis.z * axis.x + s * axis.y;
Result[2][1] = (1 - c) * axis.z * axis.y - s * axis.x; Result[2][1] = (static_cast<T>(1) - c) * axis.z * axis.y - s * axis.x;
Result[2][2] = c + (1 - c) * axis.z * axis.z; Result[2][2] = c + (static_cast<T>(1) - c) * axis.z * axis.z;
Result[2][3] = 0; Result[2][3] = static_cast<T>(0);
Result[3] = tvec4<T, P>(0, 0, 0, 1); Result[3] = tvec4<T, P>(0, 0, 0, 1);
return m * Result; return m * Result;
} }
template <typename T, precision P> template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat4x4<T, P> scale GLM_FUNC_QUALIFIER tmat4x4<T, P> scale(tmat4x4<T, P> const & m, tvec3<T, P> const & v)
(
tmat4x4<T, P> const & m,
tvec3<T, P> const & v
)
{ {
tmat4x4<T, P> Result(uninitialize); tmat4x4<T, P> Result(uninitialize);
Result[0] = m[0] * v[0]; Result[0] = m[0] * v[0];
@ -105,11 +87,7 @@ namespace glm
} }
template <typename T, precision P> template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat4x4<T, P> scale_slow GLM_FUNC_QUALIFIER tmat4x4<T, P> scale_slow(tmat4x4<T, P> const & m, tvec3<T, P> const & v)
(
tmat4x4<T, P> const & m,
tvec3<T, P> const & v
)
{ {
tmat4x4<T, P> Result(T(1)); tmat4x4<T, P> Result(T(1));
Result[0][0] = v.x; Result[0][0] = v.x;
@ -267,13 +245,7 @@ namespace glm
} }
template <typename T> template <typename T>
GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> perspective GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> perspective(T fovy, T aspect, T zNear, T zFar)
(
T fovy,
T aspect,
T zNear,
T zFar
)
{ {
# if GLM_COORDINATE_SYSTEM == GLM_LEFT_HANDED # if GLM_COORDINATE_SYSTEM == GLM_LEFT_HANDED
return perspectiveLH(fovy, aspect, zNear, zFar); return perspectiveLH(fovy, aspect, zNear, zFar);
@ -283,12 +255,7 @@ namespace glm
} }
template <typename T> template <typename T>
GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> perspectiveRH GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> perspectiveRH(T fovy, T aspect, T zNear, T zFar)
(
T fovy,
T aspect,
T zNear, T zFar
)
{ {
assert(abs(aspect - std::numeric_limits<T>::epsilon()) > static_cast<T>(0)); assert(abs(aspect - std::numeric_limits<T>::epsilon()) > static_cast<T>(0));
@ -311,12 +278,7 @@ namespace glm
} }
template <typename T> template <typename T>
GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> perspectiveLH GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> perspectiveLH(T fovy, T aspect, T zNear, T zFar)
(
T fovy,
T aspect,
T zNear, T zFar
)
{ {
assert(abs(aspect - std::numeric_limits<T>::epsilon()) > static_cast<T>(0)); assert(abs(aspect - std::numeric_limits<T>::epsilon()) > static_cast<T>(0));
@ -339,12 +301,7 @@ namespace glm
} }
template <typename T> template <typename T>
GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> perspectiveFov GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> perspectiveFov(T fov, T width, T height, T zNear, T zFar)
(
T fov,
T width, T height,
T zNear, T zFar
)
{ {
# if GLM_COORDINATE_SYSTEM == GLM_LEFT_HANDED # if GLM_COORDINATE_SYSTEM == GLM_LEFT_HANDED
return perspectiveFovLH(fov, width, height, zNear, zFar); return perspectiveFovLH(fov, width, height, zNear, zFar);
@ -354,12 +311,7 @@ namespace glm
} }
template <typename T> template <typename T>
GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> perspectiveFovRH GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> perspectiveFovRH(T fov, T width, T height, T zNear, T zFar)
(
T fov,
T width, T height,
T zNear, T zFar
)
{ {
assert(width > static_cast<T>(0)); assert(width > static_cast<T>(0));
assert(height > static_cast<T>(0)); assert(height > static_cast<T>(0));
@ -386,12 +338,7 @@ namespace glm
} }
template <typename T> template <typename T>
GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> perspectiveFovLH GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> perspectiveFovLH(T fov, T width, T height, T zNear, T zFar)
(
T fov,
T width, T height,
T zNear, T zFar
)
{ {
assert(width > static_cast<T>(0)); assert(width > static_cast<T>(0));
assert(height > static_cast<T>(0)); assert(height > static_cast<T>(0));
@ -418,12 +365,7 @@ namespace glm
} }
template <typename T> template <typename T>
GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> infinitePerspective GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> infinitePerspective(T fovy, T aspect, T zNear)
(
T fovy,
T aspect,
T zNear
)
{ {
# if GLM_COORDINATE_SYSTEM == GLM_LEFT_HANDED # if GLM_COORDINATE_SYSTEM == GLM_LEFT_HANDED
return infinitePerspectiveLH(fovy, aspect, zNear); return infinitePerspectiveLH(fovy, aspect, zNear);
@ -433,68 +375,52 @@ namespace glm
} }
template <typename T> template <typename T>
GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> infinitePerspectiveRH GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> infinitePerspectiveRH(T fovy, T aspect, T zNear)
(
T fovy,
T aspect,
T zNear
)
{ {
T const range = tan(fovy / T(2)) * zNear; T const range = tan(fovy / static_cast<T>(2)) * zNear;
T const left = -range * aspect; T const left = -range * aspect;
T const right = range * aspect; T const right = range * aspect;
T const bottom = -range; T const bottom = -range;
T const top = range; T const top = range;
tmat4x4<T, defaultp> Result(T(0)); tmat4x4<T, defaultp> Result(static_cast<T>(0));
Result[0][0] = (T(2) * zNear) / (right - left); Result[0][0] = (static_cast<T>(2) * zNear) / (right - left);
Result[1][1] = (T(2) * zNear) / (top - bottom); Result[1][1] = (static_cast<T>(2) * zNear) / (top - bottom);
Result[2][2] = - T(1); Result[2][2] = - static_cast<T>(1);
Result[2][3] = - T(1); Result[2][3] = - static_cast<T>(1);
Result[3][2] = - T(2) * zNear; Result[3][2] = - static_cast<T>(2) * zNear;
return Result; return Result;
} }
template <typename T> template <typename T>
GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> infinitePerspectiveLH GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> infinitePerspectiveLH(T fovy, T aspect, T zNear)
(
T fovy,
T aspect,
T zNear
)
{ {
T const range = tan(fovy / T(2)) * zNear; T const range = tan(fovy / static_cast<T>(2)) * zNear;
T const left = -range * aspect; T const left = -range * aspect;
T const right = range * aspect; T const right = range * aspect;
T const bottom = -range; T const bottom = -range;
T const top = range; T const top = range;
tmat4x4<T, defaultp> Result(T(0)); tmat4x4<T, defaultp> Result(T(0));
Result[0][0] = (T(2) * zNear) / (right - left); Result[0][0] = (static_cast<T>(2) * zNear) / (right - left);
Result[1][1] = (T(2) * zNear) / (top - bottom); Result[1][1] = (static_cast<T>(2) * zNear) / (top - bottom);
Result[2][2] = T(1); Result[2][2] = static_cast<T>(1);
Result[2][3] = T(1); Result[2][3] = static_cast<T>(1);
Result[3][2] = - T(2) * zNear; Result[3][2] = - static_cast<T>(2) * zNear;
return Result; return Result;
} }
// Infinite projection matrix: http://www.terathon.com/gdc07_lengyel.pdf // Infinite projection matrix: http://www.terathon.com/gdc07_lengyel.pdf
template <typename T> template <typename T>
GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> tweakedInfinitePerspective GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> tweakedInfinitePerspective(T fovy, T aspect, T zNear, T ep)
(
T fovy,
T aspect,
T zNear,
T ep
)
{ {
T const range = tan(fovy / T(2)) * zNear; T const range = tan(fovy / static_cast<T>(2)) * zNear;
T const left = -range * aspect; T const left = -range * aspect;
T const right = range * aspect; T const right = range * aspect;
T const bottom = -range; T const bottom = -range;
T const top = range; T const top = range;
tmat4x4<T, defaultp> Result(T(0)); tmat4x4<T, defaultp> Result(static_cast<T>(0));
Result[0][0] = (static_cast<T>(2) * zNear) / (right - left); Result[0][0] = (static_cast<T>(2) * zNear) / (right - left);
Result[1][1] = (static_cast<T>(2) * zNear) / (top - bottom); Result[1][1] = (static_cast<T>(2) * zNear) / (top - bottom);
Result[2][2] = ep - static_cast<T>(1); Result[2][2] = ep - static_cast<T>(1);
@ -504,12 +430,7 @@ namespace glm
} }
template <typename T> template <typename T>
GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> tweakedInfinitePerspective GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> tweakedInfinitePerspective(T fovy, T aspect, T zNear)
(
T fovy,
T aspect,
T zNear
)
{ {
return tweakedInfinitePerspective(fovy, aspect, zNear, epsilon<T>()); return tweakedInfinitePerspective(fovy, aspect, zNear, epsilon<T>());
} }
@ -523,16 +444,16 @@ namespace glm
tvec4<U, P> const & viewport tvec4<U, P> const & viewport
) )
{ {
tvec4<T, P> tmp = tvec4<T, P>(obj, T(1)); tvec4<T, P> tmp = tvec4<T, P>(obj, static_cast<T>(1));
tmp = model * tmp; tmp = model * tmp;
tmp = proj * tmp; tmp = proj * tmp;
tmp /= tmp.w; tmp /= tmp.w;
# if GLM_DEPTH_CLIP_SPACE == GLM_DEPTH_ZERO_TO_ONE # if GLM_DEPTH_CLIP_SPACE == GLM_DEPTH_ZERO_TO_ONE
tmp.x = tmp.x * T(0.5) + T(0.5); tmp.x = tmp.x * static_cast<T>(0.5) + static_cast<T>(0.5);
tmp.y = tmp.y * T(0.5) + T(0.5); tmp.y = tmp.y * static_cast<T>(0.5) + static_cast<T>(0.5);
# else # else
tmp = tmp * T(0.5) + T(0.5); tmp = tmp * static_cast<T>(0.5) + static_cast<T>(0.5);
# endif # endif
tmp[0] = tmp[0] * T(viewport[2]) + T(viewport[0]); tmp[0] = tmp[0] * T(viewport[2]) + T(viewport[0]);
tmp[1] = tmp[1] * T(viewport[3]) + T(viewport[1]); tmp[1] = tmp[1] * T(viewport[3]) + T(viewport[1]);
@ -555,10 +476,10 @@ namespace glm
tmp.x = (tmp.x - T(viewport[0])) / T(viewport[2]); tmp.x = (tmp.x - T(viewport[0])) / T(viewport[2]);
tmp.y = (tmp.y - T(viewport[1])) / T(viewport[3]); tmp.y = (tmp.y - T(viewport[1])) / T(viewport[3]);
# if GLM_DEPTH_CLIP_SPACE == GLM_DEPTH_ZERO_TO_ONE # if GLM_DEPTH_CLIP_SPACE == GLM_DEPTH_ZERO_TO_ONE
tmp.x = tmp.x * T(2) - T(1); tmp.x = tmp.x * static_cast<T>(2) - static_cast<T>(1);
tmp.y = tmp.y * T(2) - T(1); tmp.y = tmp.y * static_cast<T>(2) - static_cast<T>(1);
# else # else
tmp = tmp * T(2) - T(1); tmp = tmp * static_cast<T>(2) - static_cast<T>(1);
# endif # endif
tvec4<T, P> obj = Inverse * tmp; tvec4<T, P> obj = Inverse * tmp;
@ -568,36 +489,26 @@ namespace glm
} }
template <typename T, precision P, typename U> template <typename T, precision P, typename U>
GLM_FUNC_QUALIFIER tmat4x4<T, P> pickMatrix GLM_FUNC_QUALIFIER tmat4x4<T, P> pickMatrix(tvec2<T, P> const & center, tvec2<T, P> const & delta, tvec4<U, P> const & viewport)
(
tvec2<T, P> const & center,
tvec2<T, P> const & delta,
tvec4<U, P> const & viewport
)
{ {
assert(delta.x > T(0) && delta.y > T(0)); assert(delta.x > static_cast<T>(0) && delta.y > static_cast<T>(0));
tmat4x4<T, P> Result(1.0f); tmat4x4<T, P> Result(static_cast<T>(1));
if(!(delta.x > T(0) && delta.y > T(0))) if(!(delta.x > static_cast<T>(0) && delta.y > static_cast<T>(0)))
return Result; // Error return Result; // Error
tvec3<T, P> Temp( tvec3<T, P> Temp(
(T(viewport[2]) - T(2) * (center.x - T(viewport[0]))) / delta.x, (static_cast<T>(viewport[2]) - static_cast<T>(2) * (center.x - static_cast<T>(viewport[0]))) / delta.x,
(T(viewport[3]) - T(2) * (center.y - T(viewport[1]))) / delta.y, (static_cast<T>(viewport[3]) - static_cast<T>(2) * (center.y - static_cast<T>(viewport[1]))) / delta.y,
T(0)); static_cast<T>(0));
// Translate and scale the picked region to the entire window // Translate and scale the picked region to the entire window
Result = translate(Result, Temp); Result = translate(Result, Temp);
return scale(Result, tvec3<T, P>(T(viewport[2]) / delta.x, T(viewport[3]) / delta.y, T(1))); return scale(Result, tvec3<T, P>(static_cast<T>(viewport[2]) / delta.x, static_cast<T>(viewport[3]) / delta.y, static_cast<T>(1)));
} }
template <typename T, precision P> template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat4x4<T, P> lookAt GLM_FUNC_QUALIFIER tmat4x4<T, P> lookAt(tvec3<T, P> const & eye, tvec3<T, P> const & center, tvec3<T, P> const & up)
(
tvec3<T, P> const & eye,
tvec3<T, P> const & center,
tvec3<T, P> const & up
)
{ {
# if GLM_COORDINATE_SYSTEM == GLM_LEFT_HANDED # if GLM_COORDINATE_SYSTEM == GLM_LEFT_HANDED
return lookAtLH(eye, center, up); return lookAtLH(eye, center, up);

@ -7,21 +7,13 @@
namespace glm namespace glm
{ {
template <typename T, precision P> template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec3<T, P> cross GLM_FUNC_QUALIFIER tvec3<T, P> cross(tvec3<T, P> const& v, tquat<T, P> const& q)
(
tvec3<T, P> const & v,
tquat<T, P> const & q
)
{ {
return inverse(q) * v; return inverse(q) * v;
} }
template <typename T, precision P> template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec3<T, P> cross GLM_FUNC_QUALIFIER tvec3<T, P> cross(tquat<T, P> const& q, tvec3<T, P> const& v)
(
tquat<T, P> const & q,
tvec3<T, P> const & v
)
{ {
return q * v; return q * v;
} }
@ -51,25 +43,19 @@ namespace glm
} }
template <typename T, precision P> template <typename T, precision P>
GLM_FUNC_QUALIFIER tquat<T, P> exp GLM_FUNC_QUALIFIER tquat<T, P> exp(tquat<T, P> const& q)
(
tquat<T, P> const & q
)
{ {
tvec3<T, P> u(q.x, q.y, q.z); tvec3<T, P> u(q.x, q.y, q.z);
T Angle = glm::length(u); T const Angle = glm::length(u);
if (Angle < epsilon<T>()) if (Angle < epsilon<T>())
return tquat<T, P>(); return tquat<T, P>();
tvec3<T, P> v(u / Angle); tvec3<T, P> const v(u / Angle);
return tquat<T, P>(cos(Angle), sin(Angle) * v); return tquat<T, P>(cos(Angle), sin(Angle) * v);
} }
template <typename T, precision P> template <typename T, precision P>
GLM_FUNC_QUALIFIER tquat<T, P> log GLM_FUNC_QUALIFIER tquat<T, P> log(tquat<T, P> const& q)
(
tquat<T, P> const & q
)
{ {
tvec3<T, P> u(q.x, q.y, q.z); tvec3<T, P> u(q.x, q.y, q.z);
T Vec3Len = length(u); T Vec3Len = length(u);
@ -110,36 +96,25 @@ namespace glm
T Angle = acos(x.w / magnitude); T Angle = acos(x.w / magnitude);
T NewAngle = Angle * y; T NewAngle = Angle * y;
T Div = sin(NewAngle) / sin(Angle); T Div = sin(NewAngle) / sin(Angle);
T Mag = pow(magnitude, y-1); T Mag = pow(magnitude, y - static_cast<T>(1));
return tquat<T, P>(cos(NewAngle) * magnitude * Mag, x.x * Div * Mag, x.y * Div * Mag, x.z * Div * Mag); return tquat<T, P>(cos(NewAngle) * magnitude * Mag, x.x * Div * Mag, x.y * Div * Mag, x.z * Div * Mag);
} }
template <typename T, precision P> template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec3<T, P> rotate GLM_FUNC_QUALIFIER tvec3<T, P> rotate(tquat<T, P> const& q, tvec3<T, P> const& v)
(
tquat<T, P> const & q,
tvec3<T, P> const & v
)
{ {
return q * v; return q * v;
} }
template <typename T, precision P> template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec4<T, P> rotate GLM_FUNC_QUALIFIER tvec4<T, P> rotate(tquat<T, P> const& q, tvec4<T, P> const& v)
(
tquat<T, P> const & q,
tvec4<T, P> const & v
)
{ {
return q * v; return q * v;
} }
template <typename T, precision P> template <typename T, precision P>
GLM_FUNC_QUALIFIER T extractRealComponent GLM_FUNC_QUALIFIER T extractRealComponent(tquat<T, P> const& q)
(
tquat<T, P> const & q
)
{ {
T w = static_cast<T>(1) - q.x * q.x - q.y * q.y - q.z * q.z; T w = static_cast<T>(1) - q.x * q.x - q.y * q.y - q.z * q.z;
if(w < T(0)) if(w < T(0))
@ -149,21 +124,13 @@ namespace glm
} }
template <typename T, precision P> template <typename T, precision P>
GLM_FUNC_QUALIFIER T length2 GLM_FUNC_QUALIFIER T length2(tquat<T, P> const& q)
(
tquat<T, P> const & q
)
{ {
return q.x * q.x + q.y * q.y + q.z * q.z + q.w * q.w; return q.x * q.x + q.y * q.y + q.z * q.z + q.w * q.w;
} }
template <typename T, precision P> template <typename T, precision P>
GLM_FUNC_QUALIFIER tquat<T, P> shortMix GLM_FUNC_QUALIFIER tquat<T, P> shortMix(tquat<T, P> const& x, tquat<T, P> const& y, T const& a)
(
tquat<T, P> const & x,
tquat<T, P> const & y,
T const & a
)
{ {
if(a <= static_cast<T>(0)) return x; if(a <= static_cast<T>(0)) return x;
if(a >= static_cast<T>(1)) return y; if(a >= static_cast<T>(1)) return y;
@ -200,22 +167,13 @@ namespace glm
} }
template <typename T, precision P> template <typename T, precision P>
GLM_FUNC_QUALIFIER tquat<T, P> fastMix GLM_FUNC_QUALIFIER tquat<T, P> fastMix(tquat<T, P> const& x, tquat<T, P> const& y, T const & a)
(
tquat<T, P> const & x,
tquat<T, P> const & y,
T const & a
)
{ {
return glm::normalize(x * (static_cast<T>(1) - a) + (y * a)); return glm::normalize(x * (static_cast<T>(1) - a) + (y * a));
} }
template <typename T, precision P> template <typename T, precision P>
GLM_FUNC_QUALIFIER tquat<T, P> rotation GLM_FUNC_QUALIFIER tquat<T, P> rotation(tvec3<T, P> const& orig, tvec3<T, P> const& dest)
(
tvec3<T, P> const & orig,
tvec3<T, P> const & dest
)
{ {
T cosTheta = dot(orig, dest); T cosTheta = dot(orig, dest);
tvec3<T, P> rotationAxis; tvec3<T, P> rotationAxis;

@ -4,28 +4,21 @@
namespace glm namespace glm
{ {
template <typename T, precision P> template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat4x4<T, P> translate( GLM_FUNC_QUALIFIER tmat4x4<T, P> translate(tvec3<T, P> const & v)
tvec3<T, P> const & v)
{ {
return translate( return translate(tmat4x4<T, P>(static_cast<T>(1)), v);
tmat4x4<T, P>(1.0f), v);
} }
template <typename T, precision P> template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat4x4<T, P> rotate( GLM_FUNC_QUALIFIER tmat4x4<T, P> rotate(T angle, tvec3<T, P> const & v)
T angle,
tvec3<T, P> const & v)
{ {
return rotate( return rotate(tmat4x4<T, P>(static_cast<T>(1)), angle, v);
tmat4x4<T, P>(1), angle, v);
} }
template <typename T, precision P> template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat4x4<T, P> scale( GLM_FUNC_QUALIFIER tmat4x4<T, P> scale(tvec3<T, P> const & v)
tvec3<T, P> const & v)
{ {
return scale( return scale(tmat4x4<T, P>(static_cast<T>(1)), v);
tmat4x4<T, P>(1.0f), v);
} }
}//namespace glm }//namespace glm

@ -4,9 +4,7 @@
namespace glm namespace glm
{ {
template <typename T, precision P> template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat3x3<T, P> shearX2D( GLM_FUNC_QUALIFIER tmat3x3<T, P> shearX2D(tmat3x3<T, P> const& m, T s)
const tmat3x3<T, P>& m,
T s)
{ {
tmat3x3<T, P> r(1); tmat3x3<T, P> r(1);
r[0][1] = s; r[0][1] = s;
@ -14,9 +12,7 @@ namespace glm
} }
template <typename T, precision P> template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat3x3<T, P> shearY2D( GLM_FUNC_QUALIFIER tmat3x3<T, P> shearY2D(tmat3x3<T, P> const& m, T s)
const tmat3x3<T, P>& m,
T s)
{ {
tmat3x3<T, P> r(1); tmat3x3<T, P> r(1);
r[1][0] = s; r[1][0] = s;
@ -24,10 +20,7 @@ namespace glm
} }
template <typename T, precision P> template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat4x4<T, P> shearX3D( GLM_FUNC_QUALIFIER tmat4x4<T, P> shearX3D(tmat4x4<T, P> const& m, T s, T t)
const tmat4x4<T, P>& m,
T s,
T t)
{ {
tmat4x4<T, P> r(1); tmat4x4<T, P> r(1);
r[1][0] = s; r[1][0] = s;
@ -36,10 +29,7 @@ namespace glm
} }
template <typename T, precision P> template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat4x4<T, P> shearY3D( GLM_FUNC_QUALIFIER tmat4x4<T, P> shearY3D(tmat4x4<T, P> const& m, T s, T t)
const tmat4x4<T, P>& m,
T s,
T t)
{ {
tmat4x4<T, P> r(1); tmat4x4<T, P> r(1);
r[0][1] = s; r[0][1] = s;
@ -48,10 +38,7 @@ namespace glm
} }
template <typename T, precision P> template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat4x4<T, P> shearZ3D( GLM_FUNC_QUALIFIER tmat4x4<T, P> shearZ3D(tmat4x4<T, P> const& m, T s, T t)
const tmat4x4<T, P>& m,
T s,
T t)
{ {
tmat4x4<T, P> r(1); tmat4x4<T, P> r(1);
r[0][2] = s; r[0][2] = s;
@ -60,35 +47,31 @@ namespace glm
} }
template <typename T, precision P> template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat3x3<T, P> reflect2D( GLM_FUNC_QUALIFIER tmat3x3<T, P> reflect2D(tmat3x3<T, P> const& m, tvec3<T, P> const& normal)
const tmat3x3<T, P>& m,
const tvec3<T, P>& normal)
{ {
tmat3x3<T, P> r(1); tmat3x3<T, P> r(static_cast<T>(1));
r[0][0] = 1 - 2 * normal.x * normal.x; r[0][0] = static_cast<T>(1) - static_cast<T>(2) * normal.x * normal.x;
r[0][1] = -2 * normal.x * normal.y; r[0][1] = -static_cast<T>(2) * normal.x * normal.y;
r[1][0] = -2 * normal.x * normal.y; r[1][0] = -static_cast<T>(2) * normal.x * normal.y;
r[1][1] = 1 - 2 * normal.y * normal.y; r[1][1] = static_cast<T>(1) - static_cast<T>(2) * normal.y * normal.y;
return m * r; return m * r;
} }
template <typename T, precision P> template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat4x4<T, P> reflect3D( GLM_FUNC_QUALIFIER tmat4x4<T, P> reflect3D(tmat4x4<T, P> const& m, tvec3<T, P> const& normal)
const tmat4x4<T, P>& m,
const tvec3<T, P>& normal)
{ {
tmat4x4<T, P> r(1); tmat4x4<T, P> r(static_cast<T>(1));
r[0][0] = 1 - 2 * normal.x * normal.x; r[0][0] = static_cast<T>(1) - static_cast<T>(2) * normal.x * normal.x;
r[0][1] = -2 * normal.x * normal.y; r[0][1] = -static_cast<T>(2) * normal.x * normal.y;
r[0][2] = -2 * normal.x * normal.z; r[0][2] = -static_cast<T>(2) * normal.x * normal.z;
r[1][0] = -2 * normal.x * normal.y; r[1][0] = -static_cast<T>(2) * normal.x * normal.y;
r[1][1] = 1 - 2 * normal.y * normal.y; r[1][1] = static_cast<T>(1) - static_cast<T>(2) * normal.y * normal.y;
r[1][2] = -2 * normal.y * normal.z; r[1][2] = -static_cast<T>(2) * normal.y * normal.z;
r[2][0] = -2 * normal.x * normal.z; r[2][0] = -static_cast<T>(2) * normal.x * normal.z;
r[2][1] = -2 * normal.y * normal.z; r[2][1] = -static_cast<T>(2) * normal.y * normal.z;
r[2][2] = 1 - 2 * normal.z * normal.z; r[2][2] = static_cast<T>(1) - static_cast<T>(2) * normal.z * normal.z;
return m * r; return m * r;
} }
@ -97,11 +80,11 @@ namespace glm
const tmat3x3<T, P>& m, const tmat3x3<T, P>& m,
const tvec3<T, P>& normal) const tvec3<T, P>& normal)
{ {
tmat3x3<T, P> r(1); tmat3x3<T, P> r(static_cast<T>(1));
r[0][0] = 1 - normal.x * normal.x; r[0][0] = static_cast<T>(1) - normal.x * normal.x;
r[0][1] = - normal.x * normal.y; r[0][1] = - normal.x * normal.y;
r[1][0] = - normal.x * normal.y; r[1][0] = - normal.x * normal.y;
r[1][1] = 1 - normal.y * normal.y; r[1][1] = static_cast<T>(1) - normal.y * normal.y;
return m * r; return m * r;
} }
@ -110,26 +93,24 @@ namespace glm
const tmat4x4<T, P>& m, const tmat4x4<T, P>& m,
const tvec3<T, P>& normal) const tvec3<T, P>& normal)
{ {
tmat4x4<T, P> r(1); tmat4x4<T, P> r(static_cast<T>(1));
r[0][0] = 1 - normal.x * normal.x; r[0][0] = static_cast<T>(1) - normal.x * normal.x;
r[0][1] = - normal.x * normal.y; r[0][1] = - normal.x * normal.y;
r[0][2] = - normal.x * normal.z; r[0][2] = - normal.x * normal.z;
r[1][0] = - normal.x * normal.y; r[1][0] = - normal.x * normal.y;
r[1][1] = 1 - normal.y * normal.y; r[1][1] = static_cast<T>(1) - normal.y * normal.y;
r[1][2] = - normal.y * normal.z; r[1][2] = - normal.y * normal.z;
r[2][0] = - normal.x * normal.z; r[2][0] = - normal.x * normal.z;
r[2][1] = - normal.y * normal.z; r[2][1] = - normal.y * normal.z;
r[2][2] = 1 - normal.z * normal.z; r[2][2] = static_cast<T>(1) - normal.z * normal.z;
return m * r; return m * r;
} }
template <typename T, precision P> template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat4x4<T, P> scaleBias( GLM_FUNC_QUALIFIER tmat4x4<T, P> scaleBias(T scale, T bias)
T scale,
T bias)
{ {
tmat4x4<T, P> result; tmat4x4<T, P> result;
result[3] = tvec4<T, P>(tvec3<T, P>(bias), T(1)); result[3] = tvec4<T, P>(tvec3<T, P>(bias), static_cast<T>(1));
result[0][0] = scale; result[0][0] = scale;
result[1][1] = scale; result[1][1] = scale;
result[2][2] = scale; result[2][2] = scale;
@ -137,10 +118,7 @@ namespace glm
} }
template <typename T, precision P> template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat4x4<T, P> scaleBias( GLM_FUNC_QUALIFIER tmat4x4<T, P> scaleBias(tmat4x4<T, P> const& m, T scale, T bias)
const tmat4x4<T, P>& m,
T scale,
T bias)
{ {
return m * scaleBias(scale, bias); return m * scaleBias(scale, bias);
} }

Loading…
Cancel
Save