|
|
|
@ -88,7 +88,9 @@ struct QuaternionTest: Corrade::TestSuite::Tester { |
|
|
|
void angle(); |
|
|
|
void angle(); |
|
|
|
void matrix(); |
|
|
|
void matrix(); |
|
|
|
void lerp(); |
|
|
|
void lerp(); |
|
|
|
|
|
|
|
void lerpNotNormalized(); |
|
|
|
void slerp(); |
|
|
|
void slerp(); |
|
|
|
|
|
|
|
void slerpNotNormalized(); |
|
|
|
void transformVector(); |
|
|
|
void transformVector(); |
|
|
|
void transformVectorNormalized(); |
|
|
|
void transformVectorNormalized(); |
|
|
|
|
|
|
|
|
|
|
|
@ -104,6 +106,8 @@ typedef Math::Quaternion<Float> Quaternion; |
|
|
|
typedef Math::Vector3<Float> Vector3; |
|
|
|
typedef Math::Vector3<Float> Vector3; |
|
|
|
typedef Math::Vector4<Float> Vector4; |
|
|
|
typedef Math::Vector4<Float> Vector4; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using namespace Math::Literals; |
|
|
|
|
|
|
|
|
|
|
|
QuaternionTest::QuaternionTest() { |
|
|
|
QuaternionTest::QuaternionTest() { |
|
|
|
addTests({&QuaternionTest::construct, |
|
|
|
addTests({&QuaternionTest::construct, |
|
|
|
&QuaternionTest::constructIdentity, |
|
|
|
&QuaternionTest::constructIdentity, |
|
|
|
@ -141,7 +145,9 @@ QuaternionTest::QuaternionTest() { |
|
|
|
&QuaternionTest::angle, |
|
|
|
&QuaternionTest::angle, |
|
|
|
&QuaternionTest::matrix, |
|
|
|
&QuaternionTest::matrix, |
|
|
|
&QuaternionTest::lerp, |
|
|
|
&QuaternionTest::lerp, |
|
|
|
|
|
|
|
&QuaternionTest::lerpNotNormalized, |
|
|
|
&QuaternionTest::slerp, |
|
|
|
&QuaternionTest::slerp, |
|
|
|
|
|
|
|
&QuaternionTest::slerpNotNormalized, |
|
|
|
&QuaternionTest::transformVector, |
|
|
|
&QuaternionTest::transformVector, |
|
|
|
&QuaternionTest::transformVectorNormalized, |
|
|
|
&QuaternionTest::transformVectorNormalized, |
|
|
|
|
|
|
|
|
|
|
|
@ -455,38 +461,32 @@ void QuaternionTest::matrix() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void QuaternionTest::lerp() { |
|
|
|
void QuaternionTest::lerp() { |
|
|
|
Quaternion a = Quaternion::rotation(Deg(15.0f), Vector3(1.0f/Constants<Float>::sqrt3())); |
|
|
|
Quaternion a = Quaternion::rotation(15.0_degf, Vector3(1.0f/Constants<Float>::sqrt3())); |
|
|
|
Quaternion b = Quaternion::rotation(Deg(23.0f), Vector3::xAxis()); |
|
|
|
Quaternion b = Quaternion::rotation(23.0_degf, Vector3::xAxis()); |
|
|
|
|
|
|
|
|
|
|
|
std::ostringstream o; |
|
|
|
|
|
|
|
Error redirectError{&o}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Math::lerp(a*3.0f, b, 0.35f); |
|
|
|
|
|
|
|
CORRADE_COMPARE(o.str(), "Math::lerp(): quaternions must be normalized\n"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
o.str({}); |
|
|
|
|
|
|
|
Math::lerp(a, b*-3.0f, 0.35f); |
|
|
|
|
|
|
|
CORRADE_COMPARE(o.str(), "Math::lerp(): quaternions must be normalized\n"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Quaternion lerp = Math::lerp(a, b, 0.35f); |
|
|
|
Quaternion lerp = Math::lerp(a, b, 0.35f); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CORRADE_VERIFY(lerp.isNormalized()); |
|
|
|
CORRADE_COMPARE(lerp, Quaternion({0.119127f, 0.049134f, 0.049134f}, 0.990445f)); |
|
|
|
CORRADE_COMPARE(lerp, Quaternion({0.119127f, 0.049134f, 0.049134f}, 0.990445f)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void QuaternionTest::slerp() { |
|
|
|
void QuaternionTest::lerpNotNormalized() { |
|
|
|
Quaternion a = Quaternion::rotation(Deg(15.0f), Vector3(1.0f/Constants<Float>::sqrt3())); |
|
|
|
std::ostringstream out; |
|
|
|
Quaternion b = Quaternion::rotation(Deg(23.0f), Vector3::xAxis()); |
|
|
|
Error redirectError{&out}; |
|
|
|
|
|
|
|
|
|
|
|
std::ostringstream o; |
|
|
|
Quaternion a; |
|
|
|
Error redirectError{&o}; |
|
|
|
Math::lerp(a*3.0f, a, 0.35f); |
|
|
|
|
|
|
|
Math::lerp(a, a*-3.0f, 0.35f); |
|
|
|
Math::slerp(a*3.0f, b, 0.35f); |
|
|
|
CORRADE_COMPARE(out.str(), |
|
|
|
CORRADE_COMPARE(o.str(), "Math::slerp(): quaternions must be normalized\n"); |
|
|
|
"Math::lerp(): quaternions must be normalized\n" |
|
|
|
|
|
|
|
"Math::lerp(): quaternions must be normalized\n"); |
|
|
|
o.str({}); |
|
|
|
} |
|
|
|
Math::slerp(a, b*-3.0f, 0.35f); |
|
|
|
|
|
|
|
CORRADE_COMPARE(o.str(), "Math::slerp(): quaternions must be normalized\n"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void QuaternionTest::slerp() { |
|
|
|
|
|
|
|
Quaternion a = Quaternion::rotation(15.0_degf, Vector3(1.0f/Constants<Float>::sqrt3())); |
|
|
|
|
|
|
|
Quaternion b = Quaternion::rotation(23.0_degf, Vector3::xAxis()); |
|
|
|
Quaternion slerp = Math::slerp(a, b, 0.35f); |
|
|
|
Quaternion slerp = Math::slerp(a, b, 0.35f); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CORRADE_VERIFY(slerp.isNormalized()); |
|
|
|
CORRADE_COMPARE(slerp, Quaternion({0.1191653f, 0.0491109f, 0.0491109f}, 0.9904423f)); |
|
|
|
CORRADE_COMPARE(slerp, Quaternion({0.1191653f, 0.0491109f, 0.0491109f}, 0.9904423f)); |
|
|
|
|
|
|
|
|
|
|
|
/* Avoid division by zero */ |
|
|
|
/* Avoid division by zero */ |
|
|
|
@ -494,6 +494,18 @@ void QuaternionTest::slerp() { |
|
|
|
CORRADE_COMPARE(Math::slerp(a, -a, 0.42f), a); |
|
|
|
CORRADE_COMPARE(Math::slerp(a, -a, 0.42f), a); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void QuaternionTest::slerpNotNormalized() { |
|
|
|
|
|
|
|
std::ostringstream out; |
|
|
|
|
|
|
|
Error redirectError{&out}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Quaternion a; |
|
|
|
|
|
|
|
Math::slerp(a*3.0f, a, 0.35f); |
|
|
|
|
|
|
|
Math::slerp(a, a*-3.0f, 0.35f); |
|
|
|
|
|
|
|
CORRADE_COMPARE(out.str(), |
|
|
|
|
|
|
|
"Math::slerp(): quaternions must be normalized\n" |
|
|
|
|
|
|
|
"Math::slerp(): quaternions must be normalized\n"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void QuaternionTest::transformVector() { |
|
|
|
void QuaternionTest::transformVector() { |
|
|
|
Quaternion a = Quaternion::rotation(Deg(23.0f), Vector3::xAxis()); |
|
|
|
Quaternion a = Quaternion::rotation(Deg(23.0f), Vector3::xAxis()); |
|
|
|
Matrix4 m = Matrix4::rotationX(Deg(23.0f)); |
|
|
|
Matrix4 m = Matrix4::rotationX(Deg(23.0f)); |
|
|
|
|