Using C++ casts

This commit is contained in:
Christophe Riccio
2013-09-08 00:22:17 +02:00
parent b7c020b6fe
commit b9266c07b0
64 changed files with 966 additions and 1001 deletions

View File

@@ -47,7 +47,7 @@ namespace glm
public:
typedef T value_type;
angle(value_type const & x) :
angle(T const & x) :
data(x)
{}

View File

@@ -61,7 +61,7 @@ namespace glm
typename genType::boolType epsilonEqual(
genType const & x,
genType const & y,
typename genType::value_type const & epsilon);
typename genType::T const & epsilon);
/// Returns the component-wise comparison of |x - y| < epsilon.
/// True if this expression is satisfied.
@@ -81,7 +81,7 @@ namespace glm
typename genType::boolType epsilonNotEqual(
genType const & x,
genType const & y,
typename genType::value_type const & epsilon);
typename genType::T const & epsilon);
/// Returns the component-wise comparison of |x - y| >= epsilon.
/// True if this expression is not satisfied.

View File

@@ -180,8 +180,8 @@ namespace glm
)
{
detail::tmat4x4<T, defaultp> Result(1);
Result[0][0] = T(2) / (right - left);
Result[1][1] = T(2) / (top - bottom);
Result[0][0] = static_cast<T>(2) / (right - left);
Result[1][1] = static_cast<T>(2) / (top - bottom);
Result[2][2] = - T(2) / (zFar - zNear);
Result[3][0] = - (right + left) / (right - left);
Result[3][1] = - (top + bottom) / (top - bottom);
@@ -199,8 +199,8 @@ namespace glm
)
{
detail::tmat4x4<T, defaultp> Result(1);
Result[0][0] = T(2) / (right - left);
Result[1][1] = T(2) / (top - bottom);
Result[0][0] = static_cast<T>(2) / (right - left);
Result[1][1] = static_cast<T>(2) / (top - bottom);
Result[2][2] = - T(1);
Result[3][0] = - (right + left) / (right - left);
Result[3][1] = - (top + bottom) / (top - bottom);
@@ -337,8 +337,8 @@ namespace glm
detail::tmat4x4<T, defaultp> Result(T(0));
Result[0][0] = (T(2) * zNear) / (right - left);
Result[1][1] = (T(2) * zNear) / (top - bottom);
Result[2][2] = T(0.0001) - T(1);
Result[2][3] = T(-1);
Result[2][2] = static_cast<T>(0.0001) - T(1);
Result[2][3] = static_cast<T>(-1);
Result[3][2] = - (T(0.0001) - T(2)) * zNear;
return Result;
}

View File

@@ -128,7 +128,7 @@ namespace glm
GLM_FUNC_QUALIFIER detail::tvec4<T, P> grad4(T const & j, detail::tvec4<T, P> const & ip)
{
detail::tvec3<T, P> pXYZ = floor(fract(detail::tvec3<T, P>(j) * detail::tvec3<T, P>(ip)) * T(7)) * ip[2] - T(1);
T pW = T(1.5) - dot(abs(pXYZ), detail::tvec3<T, P>(1));
T pW = static_cast<T>(1.5) - dot(abs(pXYZ), detail::tvec3<T, P>(1));
detail::tvec4<T, P> s = detail::tvec4<T, P>(lessThan(detail::tvec4<T, P>(pXYZ, pW), detail::tvec4<T, P>(0.0)));
pXYZ = pXYZ + (detail::tvec3<T, P>(s) * T(2) - T(1)) * s.w;
return detail::tvec4<T, P>(pXYZ, pW);
@@ -148,7 +148,7 @@ namespace glm
detail::tvec4<T, P> i = glm::permute(glm::permute(ix) + iy);
detail::tvec4<T, P> gx = T(2) * glm::fract(i / T(41)) - T(1);
detail::tvec4<T, P> gx = static_cast<T>(2) * glm::fract(i / T(41)) - T(1);
detail::tvec4<T, P> gy = glm::abs(gx) - T(0.5);
detail::tvec4<T, P> tx = glm::floor(gx + T(0.5));
gx = gx - tx;
@@ -470,7 +470,7 @@ namespace glm
detail::tvec4<T, P> i = permute(permute(ix) + iy);
detail::tvec4<T, P> gx = T(2) * fract(i / T(41)) - T(1);
detail::tvec4<T, P> gx = static_cast<T>(2) * fract(i / T(41)) - T(1);
detail::tvec4<T, P> gy = abs(gx) - T(0.5);
detail::tvec4<T, P> tx = floor(gx + T(0.5));
gx = gx - tx;
@@ -741,14 +741,14 @@ namespace glm
// 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)
detail::tvec3<T, P> x = T(2) * fract(p * C.w) - T(1);
detail::tvec3<T, P> x = static_cast<T>(2) * fract(p * C.w) - T(1);
detail::tvec3<T, P> h = abs(x) - T(0.5);
detail::tvec3<T, P> ox = floor(x + T(0.5));
detail::tvec3<T, P> a0 = x - ox;
// Normalise gradients implicitly by scaling m
// Inlined for speed: m *= taylorInvSqrt( a0*a0 + h*h );
m *= T(1.79284291400159) - T(0.85373472095314) * (a0 * a0 + h * h);
m *= static_cast<T>(1.79284291400159) - T(0.85373472095314) * (a0 * a0 + h * h);
// Compute final noise value at P
detail::tvec3<T, P> g;
@@ -792,7 +792,7 @@ namespace glm
// 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_ = T(0.142857142857); // 1.0/7.0
T n_ = static_cast<T>(0.142857142857); // 1.0/7.0
detail::tvec3<T, P> ns(n_ * detail::tvec3<T, P>(D.w, D.y, D.z) - detail::tvec3<T, P>(D.x, D.z, D.x));
detail::tvec4<T, P> j(p - T(49) * floor(p * ns.z * ns.z)); // mod(p,7*7)
@@ -844,7 +844,7 @@ namespace glm
-0.447213595499958); // -1 + 4 * G4
// (sqrt(5) - 1)/4 = F4, used once below
T const F4 = T(0.309016994374947451);
T const F4 = static_cast<T>(0.309016994374947451);
// First corner
detail::tvec4<T, P> i = floor(v + dot(v, vec4(F4)));
@@ -858,15 +858,15 @@ namespace glm
detail::tvec3<T, P> isYZ = step(detail::tvec3<T, P>(x0.z, x0.w, x0.w), detail::tvec3<T, P>(x0.y, x0.y, x0.z));
// i0.x = dot(isX, vec3(1.0));
//i0.x = isX.x + isX.y + isX.z;
//i0.yzw = T(1) - isX;
//i0.yzw = static_cast<T>(1) - isX;
i0 = detail::tvec4<T, P>(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 - detail::tvec2<T, P>(isYZ.x, isYZ.y);
i0.z += T(1) - isYZ.x;
i0.w += T(1) - isYZ.y;
i0.z += static_cast<T>(1) - isYZ.x;
i0.w += static_cast<T>(1) - isYZ.y;
i0.z += isYZ.z;
i0.w += T(1) - isYZ.z;
i0.w += static_cast<T>(1) - isYZ.z;
// i0 now contains the unique values 0,1,2,3 in each channel
detail::tvec4<T, P> i3 = clamp(i0, 0.0, 1.0);

View File

@@ -71,13 +71,13 @@ namespace detail
GLM_FUNC_DECL explicit tquat(
tquat<U, Q> const & q);
GLM_FUNC_DECL explicit tquat(
value_type const & s,
T const & s,
glm::detail::tvec3<T, P> const & v);
GLM_FUNC_DECL explicit tquat(
value_type const & w,
value_type const & x,
value_type const & y,
value_type const & z);
T const & w,
T const & x,
T const & y,
T const & z);
// Convertions
@@ -91,11 +91,11 @@ namespace detail
// Accesses
GLM_FUNC_DECL value_type & operator[](size_type i);
GLM_FUNC_DECL value_type const & operator[](size_type i) const;
GLM_FUNC_DECL T const & operator[](size_type i) const;
// Operators
GLM_FUNC_DECL tquat<T, P> & operator*=(value_type const & s);
GLM_FUNC_DECL tquat<T, P> & operator/=(value_type const & s);
GLM_FUNC_DECL tquat<T, P> & operator*=(T const & s);
GLM_FUNC_DECL tquat<T, P> & operator/=(T const & s);
};
template <typename T, precision P>

View File

@@ -381,7 +381,7 @@ namespace detail
(
detail::tquat<T, P> const & x,
detail::tquat<T, P> const & y,
typename detail::tquat<T, P>::value_type const & a
typename detail::tquat<T, P>::T const & a
)
{
if(a <= typename detail::tquat<T, P>::value_type(0)) return x;
@@ -406,7 +406,7 @@ namespace detail
{
typename detail::tquat<T, P>::value_type fSin = sqrt(T(1) - fCos * fCos);
typename detail::tquat<T, P>::value_type fAngle = atan(fSin, fCos);
typename detail::tquat<T, P>::value_type fOneOverSin = T(1) / fSin;
typename detail::tquat<T, P>::value_type fOneOverSin = static_cast<T>(1) / fSin;
k0 = sin((typename detail::tquat<T, P>::value_type(1) - a) * fAngle) * fOneOverSin;
k1 = sin((typename detail::tquat<T, P>::value_type(0) + a) * fAngle) * fOneOverSin;
}
@@ -427,8 +427,8 @@ namespace detail
)
{
bool flip = false;
if(a <= T(0)) return x;
if(a >= T(1)) return y;
if(a <= static_cast<T>(0)) return x;
if(a >= static_cast<T>(1)) return y;
T cos_t = dot(x, y);
if(cos_t < T(0))
@@ -440,7 +440,7 @@ namespace detail
T alpha(0), beta(0);
if(T(1) - cos_t < 1e-7)
beta = T(1) - alpha;
beta = static_cast<T>(1) - alpha;
else
{
T theta = acos(cos_t);
@@ -493,8 +493,8 @@ namespace detail
)
{
// Lerp is only defined in [0, 1]
assert(a >= T(0));
assert(a <= T(1));
assert(a >= static_cast<T>(0));
assert(a <= static_cast<T>(1));
return x * (T(1) - a) + (y * a);
}
@@ -559,7 +559,7 @@ namespace detail
GLM_FUNC_QUALIFIER detail::tquat<T, P> rotate
(
detail::tquat<T, P> const & q,
typename detail::tquat<T, P>::value_type const & angle,
typename detail::tquat<T, P>::T const & angle,
detail::tvec3<T, P> const & v
)
{
@@ -569,7 +569,7 @@ namespace detail
typename detail::tquat<T, P>::value_type len = glm::length(Tmp);
if(abs(len - T(1)) > T(0.001))
{
T oneOverLen = T(1) / len;
T oneOverLen = static_cast<T>(1) / len;
Tmp.x *= oneOverLen;
Tmp.y *= oneOverLen;
Tmp.z *= oneOverLen;
@@ -694,7 +694,7 @@ namespace detail
}
typename detail::tquat<T, P>::value_type biggestVal = sqrt(fourBiggestSquaredMinus1 + T(1)) * T(0.5);
typename detail::tquat<T, P>::value_type mult = T(0.25) / biggestVal;
typename detail::tquat<T, P>::value_type mult = static_cast<T>(0.25) / biggestVal;
detail::tquat<T, P> Result;
switch(biggestIndex)
@@ -759,10 +759,10 @@ namespace detail
detail::tquat<T, P> const & x
)
{
T tmp1 = T(1) - x.w * x.w;
if(tmp1 <= T(0))
T tmp1 = static_cast<T>(1) - x.w * x.w;
if(tmp1 <= static_cast<T>(0))
return detail::tvec3<T, P>(0, 0, 1);
T tmp2 = T(1) / sqrt(tmp1);
T tmp2 = static_cast<T>(1) / sqrt(tmp1);
return detail::tvec3<T, P>(x.x * tmp2, x.y * tmp2, x.z * tmp2);
}