Merge branch '0.9.2' into gtx_ulp

This commit is contained in:
Christophe Riccio 2011-05-05 12:35:03 +01:00
commit 378da68899
7 changed files with 205 additions and 137 deletions

View File

@ -8,7 +8,7 @@ add_definitions(-D_CRT_SECURE_NO_WARNINGS)
#add_definitions(-pedantic)
#add_definitions(-S)
#add_definitions(-s)
add_definitions(-msse2)
#add_definitions(-msse2)
#add_definitions(-m32)
#add_definitions(-mfpmath=387)
#add_definitions(-ffast-math)

View File

@ -269,13 +269,13 @@ namespace glm
GLM_STATIC_ASSERT(std::numeric_limits<genIUType>::is_integer, "'bitfieldExtract' only accept integer values");
assert(Offset + Bits <= sizeof(genIUType));
genIUType Result = 0;
genIUType Result(0);
if(std::numeric_limits<genIUType>::is_signed)
Result |= (1 << (sizeof(genIUType) * 8 - 1)) & (1 << (Offset + Bits - 1));
Result |= (genIUType(1) << (sizeof(genIUType) * genIUType(8) - genIUType(1))) & (genIUType(1) << (Offset + Bits - genIUType(1)));
genIUType Mask = 0;
genIUType Mask(0);
for(int Bit = Offset; Bit < Bits; ++Bit)
Mask |= (1 << Bit);
Mask |= (genIUType(1) << Bit);
return Result | ((Mask & Value) >> Offset);
}
@ -340,7 +340,7 @@ namespace glm
genIUType Mask = 0;
for(int Bit = Offset; Bit < Offset + Bits; ++Bit)
Mask |= (1 << Bit);
Mask |= (genIUType(1) << Bit);
return (Base & ~Mask) | (Insert & Mask);
}
@ -398,8 +398,8 @@ namespace glm
genIUType Result = 0;
for(std::size_t i = 0; i < sizeof(genIUType) * std::size_t(8); ++i)
if(Value & (1 << i))
Result |= (genIUType(1) << (sizeof(genIUType) * std::size_t(8)) - genIUType(1) - i);
if(Value & (genIUType(1) << genIUType(i)))
Result |= (genIUType(1) << (genIUType(sizeof(genIUType)) * genIUType(8)) - genIUType(1) - genIUType(i));
return Result;
}
@ -448,7 +448,7 @@ namespace glm
int Count = 0;
for(std::size_t i = 0; i < sizeof(genIUType) * std::size_t(8); ++i)
{
if(Value & (1 << i))
if(Value & (genIUType(1) << i))
++Count;
}
return Count;

View File

@ -326,7 +326,7 @@ namespace quaternion{
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 <typename T>
GLM_FUNC_QUALIFIER detail::tquat<T> mix
@ -406,6 +406,18 @@ namespace quaternion{
return normalize(beta * x + alpha * y);
}
*/
template <typename T>
GLM_FUNC_QUALIFIER detail::tquat<T> mix
(
detail::tquat<T> const & x,
detail::tquat<T> const & y,
T const & a
)
{
T angle = acos(dot(x, y));
return (sin((1 - a) * angle) * x + sin(a * angle) * y) / sin(angle);
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tquat<T> conjugate

View File

@ -109,7 +109,7 @@ namespace glm
detail::tquat<valType> const & q,
detail::tvec4<valType> const & v);
//! Returns the q rotation angle.
//! Returns the quaternion rotation angle.
//! From GLM_GTX_quaternion extension.
template <typename valType>
valType angle(
@ -191,6 +191,22 @@ namespace glm
detail::tquat<valType> toQuat(
detail::tmat4x4<valType> const & x){return gtc::quaternion::quat_cast(x);}
//! Quaternion interpolation using the rotation short path.
//! From GLM_GTX_quaternion extension.
template <typename T>
detail::tquat<T> shortMix(
detail::tquat<T> const & x,
detail::tquat<T> const & y,
T const & a);
//! Quaternion normalized linear interpolation.
//! From GLM_GTX_quaternion extension.
template <typename T>
detail::tquat<T> fastMix(
detail::tquat<T> const & x,
detail::tquat<T> const & y,
T const & a);
///@}
}//namespace quaternion

View File

@ -245,6 +245,59 @@ namespace quaternion
return detail::tvec3<valType>(pitch(x), yaw(x), roll(x));
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tquat<T> shortMix
(
detail::tquat<T> const & x,
detail::tquat<T> const & y,
T const & a
)
{
if(a <= typename detail::tquat<T>::value_type(0)) return x;
if(a >= typename detail::tquat<T>::value_type(1)) return y;
float fCos = dot(x, y);
detail::tquat<T> y2(y); //BUG!!! tquat<T> y2;
if(fCos < typename detail::tquat<T>::value_type(0))
{
y2 = -y;
fCos = -fCos;
}
//if(fCos > 1.0f) // problem
float k0, k1;
if(fCos > typename detail::tquat<T>::value_type(0.9999))
{
k0 = typename detail::tquat<T>::value_type(1) - a;
k1 = typename detail::tquat<T>::value_type(0) + a; //BUG!!! 1.0f + a;
}
else
{
typename detail::tquat<T>::value_type fSin = sqrt(T(1) - fCos * fCos);
typename detail::tquat<T>::value_type fAngle = atan(fSin, fCos);
typename detail::tquat<T>::value_type fOneOverSin = T(1) / fSin;
k0 = sin((typename detail::tquat<T>::value_type(1) - a) * fAngle) * fOneOverSin;
k1 = sin((typename detail::tquat<T>::value_type(0) + a) * fAngle) * fOneOverSin;
}
return detail::tquat<T>(
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 <typename T>
GLM_FUNC_QUALIFIER detail::tquat<T> fastMix
(
detail::tquat<T> const & x,
detail::tquat<T> const & y,
T const & a
)
{
return glm::normalize(x * (1 - a) + (y * a));
}
}//namespace quaternion
}//namespace gtx
}//namespace glm

View File

@ -1,148 +1,135 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Mathematics Copyright (c) 2005 - 2011 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2011-01-15
// Updated : 2011-01-15
// Created : 2011-05-03
// Updated : 2011-05-03
// Licence : This source is under MIT licence
// File : test/gtx/simd-mat4.cpp
// File : test/core/func_integer.cpp
///////////////////////////////////////////////////////////////////////////////////////////////////
#define GLM_INSTRUCTION_SET GLM_PLATFORM_SSE3 | GLM_PLATFORM_SSE2
#include <glm/glm.hpp>
#include <glm/gtx/number_precision.hpp>
#include <iostream>
int test_static_assert()
enum result
{
//glm::lessThan(glm::mat4(0), glm::mat4(4));
SUCCESS,
FAIL,
ASSERT,
STATIC_ASSERT
};
return 0;
}
int test_lessThan_vec2()
namespace extractField
{
glm::bvec2 O = glm::bvec2(true, false);
template <typename genType, typename sizeType>
struct type
{
genType Value;
sizeType BitFirst;
sizeType BitCount;
genType Return;
result Result;
};
glm::bvec2 A = glm::lessThan(glm::vec2(0, 6), glm::vec2(4, 2));
assert(glm::all(glm::equal(O, A)));
typedef type<glm::uint64, glm::uint> typeU64;
glm::bvec2 B = glm::lessThan(glm::ivec2(0, 6), glm::ivec2(4, 2));
assert(glm::all(glm::equal(O, B)));
typeU64 const Data64[] =
{
{0xffffffffffffffff, 8, 0, 0x0000000000000000, SUCCESS},
{0x0000000000000000, 0,64, 0x0000000000000000, SUCCESS},
{0xffffffffffffffff, 0,64, 0xffffffffffffffff, SUCCESS},
{0x0f0f0f0f0f0f0f0f, 0,64, 0x0f0f0f0f0f0f0f0f, SUCCESS},
{0x0000000000000000, 8, 0, 0x0000000000000000, SUCCESS},
{0x8000000000000000,63, 1, 0x0000000000000001, SUCCESS},
{0x7fffffffffffffff,63, 1, 0x0000000000000000, SUCCESS},
{0x0000000000000300, 8, 8, 0x0000000000000003, SUCCESS},
{0x000000000000ff00, 8, 8, 0x00000000000000ff, SUCCESS},
{0xfffffffffffffff0, 0, 5, 0x0000000000000010, SUCCESS},
{0x00000000000000ff, 1, 3, 0x0000000000000007, SUCCESS},
{0x00000000000000ff, 0, 3, 0x0000000000000007, SUCCESS},
{0x0000000000000000, 0, 2, 0x0000000000000000, SUCCESS},
{0xffffffffffffffff, 0, 8, 0x00000000000000ff, SUCCESS},
{0xffffffff00000000,32,32, 0x00000000ffffffff, SUCCESS},
{0xfffffffffffffff0, 0, 8, 0x0000000000000000, FAIL},
{0xffffffffffffffff,32,32, 0x0000000000000000, FAIL},
//{0xffffffffffffffff,64, 1, 0x0000000000000000, ASSERT}, // Throw an assert
//{0xffffffffffffffff, 0,65, 0x0000000000000000, ASSERT}, // Throw an assert
//{0xffffffffffffffff,33,32, 0x0000000000000000, ASSERT}, // Throw an assert
};
glm::bvec2 C = glm::lessThan(glm::uvec2(0, 6), glm::uvec2(4, 2));
assert(glm::all(glm::equal(O, C)));
int test()
{
glm::uint32 count = sizeof(Data64) / sizeof(typeU64);
return 0;
}
for(glm::uint32 i = 0; i < count; ++i)
{
glm::uint64 Return = glm::bitfieldExtract(
Data64[i].Value,
Data64[i].BitFirst,
Data64[i].BitCount);
int test_lessThan_vec3()
bool Compare = Data64[i].Return == Return;
if(Data64[i].Result == SUCCESS && Compare)
continue;
else if(Data64[i].Result == FAIL && !Compare)
continue;
std::cout << "glm::bitfieldExtract test fail on test " << i << std::endl;
return 1;
}
return 0;
}
}//extractField
namespace bitRevert
{
glm::bvec3 O = glm::bvec3(true, true, false);
template <typename genType>
struct type
{
genType Value;
genType Return;
result Result;
};
glm::bvec3 A = glm::lessThan(glm::vec3(0, 1, 6), glm::vec3(4, 5, 2));
assert(glm::all(glm::equal(O, A)));
typedef type<glm::uint64> typeU64;
glm::bvec3 B = glm::lessThan(glm::ivec3(0, 1, 6), glm::ivec3(4, 5, 2));
assert(glm::all(glm::equal(O, B)));
typeU64 const Data64[] =
{
{0xffffffffffffffff, 0xffffffffffffffff, SUCCESS},
{0x0000000000000000, 0x0000000000000000, SUCCESS},
{0xf000000000000000, 0x000000000000000f, SUCCESS},
};
glm::bvec3 C = glm::lessThan(glm::uvec3(0, 1, 6), glm::uvec3(4, 5, 2));
assert(glm::all(glm::equal(O, C)));
int test()
{
glm::uint32 count = sizeof(Data64) / sizeof(typeU64);
return 0;
}
for(glm::uint32 i = 0; i < count; ++i)
{
glm::uint64 Return = glm::bitfieldReverse(
Data64[i].Value);
int test_lessThan_vec4()
{
glm::bvec4 O = glm::bvec4(true, true, false, false);
bool Compare = Data64[i].Return == Return;
glm::bvec4 A = glm::lessThan(glm::vec4(0, 1, 6, 7), glm::vec4(4, 5, 2, 3));
assert(glm::all(glm::equal(O, A)));
if(Data64[i].Result == SUCCESS && Compare)
continue;
else if(Data64[i].Result == FAIL && !Compare)
continue;
glm::bvec4 B = glm::lessThan(glm::ivec4(0, 1, 6, 7), glm::ivec4(4, 5, 2, 3));
assert(glm::all(glm::equal(O, B)));
glm::bvec4 C = glm::lessThan(glm::uvec4(0, 1, 6, 7), glm::uvec4(4, 5, 2, 3));
assert(glm::all(glm::equal(O, C)));
return 0;
}
int test_greaterThanEqual_vec2()
{
glm::bvec2 O = glm::bvec2(false, true);
glm::bvec2 A = glm::greaterThanEqual(glm::vec2(0, 6), glm::vec2(4, 2));
assert(glm::all(glm::equal(O, A)));
glm::bvec2 B = glm::greaterThanEqual(glm::ivec2(0, 6), glm::ivec2(4, 2));
assert(glm::all(glm::equal(O, B)));
glm::bvec2 C = glm::greaterThanEqual(glm::uvec2(0, 6), glm::uvec2(4, 2));
assert(glm::all(glm::equal(O, C)));
return 0;
}
int test_greaterThanEqual_vec3()
{
glm::bvec3 O = glm::bvec3(false, false, true);
glm::bvec3 A = glm::greaterThanEqual(glm::vec3(0, 1, 6), glm::vec3(4, 5, 2));
assert(glm::all(glm::equal(O, A)));
glm::bvec3 B = glm::greaterThanEqual(glm::ivec3(0, 1, 6), glm::ivec3(4, 5, 2));
assert(glm::all(glm::equal(O, B)));
glm::bvec3 C = glm::greaterThanEqual(glm::uvec3(0, 1, 6), glm::uvec3(4, 5, 2));
assert(glm::all(glm::equal(O, C)));
return 0;
}
int test_greaterThanEqual_vec4()
{
glm::bvec4 O = glm::bvec4(false, false, true, true);
glm::bvec4 A = glm::greaterThanEqual(glm::vec4(0, 1, 6, 7), glm::vec4(4, 5, 2, 3));
assert(glm::all(glm::equal(O, A)));
glm::bvec4 B = glm::greaterThanEqual(glm::ivec4(0, 1, 6, 7), glm::ivec4(4, 5, 2, 3));
assert(glm::all(glm::equal(O, B)));
glm::bvec4 C = glm::greaterThanEqual(glm::uvec4(0, 1, 6, 7), glm::uvec4(4, 5, 2, 3));
assert(glm::all(glm::equal(O, C)));
return 0;
}
int test_all()
{
assert(glm::all(glm::bvec2(true, true)));
assert(!glm::all(glm::bvec2(true, false)));
assert(!glm::all(glm::bvec2(false, false)));
assert(glm::all(glm::bvec3(true, true, true)));
assert(!glm::all(glm::bvec3(true, false, true)));
assert(!glm::all(glm::bvec3(false, false, false)));
assert(glm::all(glm::bvec4(true, true, true, true)));
assert(!glm::all(glm::bvec4(true, false, true, false)));
assert(!glm::all(glm::bvec4(false, false, false, false)));
return 0;
}
std::cout << "glm::bitfieldReverse test fail on test " << i << std::endl;
return 1;
}
return 0;
}
}//bitRevert
int main()
{
int Failed = 0;
Failed += test_static_assert();
Failed += test_lessThan_vec2();
Failed += test_lessThan_vec3();
Failed += test_lessThan_vec4();
Failed += test_greaterThanEqual_vec2();
Failed += test_greaterThanEqual_vec3();
Failed += test_greaterThanEqual_vec4();
Failed += test_all();
return Failed;
int Error = 0;
Error += ::extractField::test();
Error += ::bitRevert::test();
return Error;
}

View File

@ -129,7 +129,7 @@ namespace bitRevert
int main()
{
bool Error = 0;
int Error = 0;
Error += ::extractField::test();
Error += ::bitRevert::test();
return Error;