|
|
|
|
@ -58,6 +58,8 @@ class QuaternionTest: public Corrade::TestSuite::Tester {
|
|
|
|
|
void debug(); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
typedef Math::Deg<float> Deg; |
|
|
|
|
typedef Math::Rad<float> Rad; |
|
|
|
|
typedef Math::Matrix<3, float> Matrix3; |
|
|
|
|
typedef Math::Matrix4<float> Matrix4; |
|
|
|
|
typedef Math::Quaternion<float> Quaternion; |
|
|
|
|
@ -227,48 +229,48 @@ void QuaternionTest::rotation() {
|
|
|
|
|
std::ostringstream o; |
|
|
|
|
Error::setOutput(&o); |
|
|
|
|
|
|
|
|
|
float angle = deg(120.0f); |
|
|
|
|
Vector3 axis(1.0f/Constants<float>::sqrt3()); |
|
|
|
|
|
|
|
|
|
CORRADE_COMPARE(Quaternion::rotation(deg(-74.0f), {-1.0f, 2.0f, 2.0f}), Quaternion()); |
|
|
|
|
CORRADE_COMPARE(Quaternion::rotation(Deg(-74.0f), {-1.0f, 2.0f, 2.0f}), Quaternion()); |
|
|
|
|
CORRADE_COMPARE(o.str(), "Math::Quaternion::rotation(): axis must be normalized\n"); |
|
|
|
|
|
|
|
|
|
Quaternion q = Quaternion::rotation(angle, axis); |
|
|
|
|
Quaternion q = Quaternion::rotation(Deg(120.0f), axis); |
|
|
|
|
CORRADE_COMPARE(q, Quaternion(Vector3(0.5f, 0.5f, 0.5f), 0.5f)); |
|
|
|
|
CORRADE_COMPARE(q.rotationAngle(), angle); |
|
|
|
|
CORRADE_COMPARE_AS(q.rotationAngle(), Deg(120.0f), Deg); |
|
|
|
|
CORRADE_COMPARE(q.rotationAxis(), axis); |
|
|
|
|
CORRADE_COMPARE(q.rotationAxis().length(), 1.0f); |
|
|
|
|
|
|
|
|
|
/* Verify negative angle */ |
|
|
|
|
Quaternion q2 = Quaternion::rotation(deg(-120.0f), axis); |
|
|
|
|
Quaternion q2 = Quaternion::rotation(Deg(-120.0f), axis); |
|
|
|
|
CORRADE_COMPARE(q2, Quaternion(Vector3(-0.5f, -0.5f, -0.5f), 0.5f)); |
|
|
|
|
CORRADE_COMPARE(q2.rotationAngle(), deg(120.0f)); |
|
|
|
|
CORRADE_COMPARE_AS(q2.rotationAngle(), Deg(120.0f), Deg); |
|
|
|
|
CORRADE_COMPARE(q2.rotationAxis(), -axis); |
|
|
|
|
|
|
|
|
|
/* Default-constructed quaternion has zero angle and NaN axis */ |
|
|
|
|
CORRADE_COMPARE(Quaternion().rotationAngle(), deg(0.0f)); |
|
|
|
|
CORRADE_COMPARE_AS(Quaternion().rotationAngle(), Deg(0.0f), Deg); |
|
|
|
|
CORRADE_VERIFY(Quaternion().rotationAxis() != Quaternion().rotationAxis()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void QuaternionTest::angle() { |
|
|
|
|
std::ostringstream o; |
|
|
|
|
Corrade::Utility::Error::setOutput(&o); |
|
|
|
|
CORRADE_COMPARE(Quaternion::angle(Quaternion({1.0f, 2.0f, -3.0f}, -4.0f).normalized(), {{4.0f, -3.0f, 2.0f}, -1.0f}), |
|
|
|
|
std::numeric_limits<Vector3::Type>::quiet_NaN()); |
|
|
|
|
auto angle = Quaternion::angle(Quaternion({1.0f, 2.0f, -3.0f}, -4.0f).normalized(), {{4.0f, -3.0f, 2.0f}, -1.0f}); |
|
|
|
|
CORRADE_VERIFY(angle != angle); |
|
|
|
|
CORRADE_COMPARE(o.str(), "Math::Quaternion::angle(): quaternions must be normalized\n"); |
|
|
|
|
|
|
|
|
|
o.str(""); |
|
|
|
|
CORRADE_COMPARE(Quaternion::angle({{1.0f, 2.0f, -3.0f}, -4.0f}, Quaternion({4.0f, -3.0f, 2.0f}, -1.0f).normalized()), |
|
|
|
|
std::numeric_limits<Vector3::Type>::quiet_NaN()); |
|
|
|
|
angle = Quaternion::angle({{1.0f, 2.0f, -3.0f}, -4.0f}, Quaternion({4.0f, -3.0f, 2.0f}, -1.0f).normalized()); |
|
|
|
|
CORRADE_VERIFY(angle != angle); |
|
|
|
|
CORRADE_COMPARE(o.str(), "Math::Quaternion::angle(): quaternions must be normalized\n"); |
|
|
|
|
|
|
|
|
|
CORRADE_COMPARE(Quaternion::angle(Quaternion({1.0f, 2.0f, -3.0f}, -4.0f).normalized(), Quaternion({4.0f, -3.0f, 2.0f}, -1.0f).normalized()), |
|
|
|
|
rad(1.704528f)); |
|
|
|
|
CORRADE_COMPARE(Quaternion::angle(Quaternion({1.0f, 2.0f, -3.0f}, -4.0f).normalized(), |
|
|
|
|
Quaternion({4.0f, -3.0f, 2.0f}, -1.0f).normalized()), |
|
|
|
|
Rad(1.704528f)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void QuaternionTest::matrix() { |
|
|
|
|
Quaternion q = Quaternion::rotation(deg(37.0f), Vector3(1.0f/Constants<float>::sqrt3())); |
|
|
|
|
Matrix3 m = Matrix4::rotation(deg(37.0f), Vector3(1.0f/Constants<float>::sqrt3())).rotationScaling(); |
|
|
|
|
Quaternion q = Quaternion::rotation(Deg(37.0f), Vector3(1.0f/Constants<float>::sqrt3())); |
|
|
|
|
Matrix3 m = Matrix4::rotation(Deg(37.0f), Vector3(1.0f/Constants<float>::sqrt3())).rotationScaling(); |
|
|
|
|
|
|
|
|
|
/* Verify that negated quaternion gives the same rotation */ |
|
|
|
|
CORRADE_COMPARE(q.matrix(), m); |
|
|
|
|
@ -276,8 +278,8 @@ void QuaternionTest::matrix() {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void QuaternionTest::lerp() { |
|
|
|
|
Quaternion a = Quaternion::rotation(deg(15.0f), Vector3(1.0f/Constants<float>::sqrt3())); |
|
|
|
|
Quaternion b = Quaternion::rotation(deg(23.0f), Vector3::xAxis()); |
|
|
|
|
Quaternion a = Quaternion::rotation(Deg(15.0f), Vector3(1.0f/Constants<float>::sqrt3())); |
|
|
|
|
Quaternion b = Quaternion::rotation(Deg(23.0f), Vector3::xAxis()); |
|
|
|
|
|
|
|
|
|
std::ostringstream o; |
|
|
|
|
Corrade::Utility::Error::setOutput(&o); |
|
|
|
|
@ -298,8 +300,8 @@ void QuaternionTest::lerp() {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void QuaternionTest::slerp() { |
|
|
|
|
Quaternion a = Quaternion::rotation(deg(15.0f), Vector3(1.0f/Constants<float>::sqrt3())); |
|
|
|
|
Quaternion b = Quaternion::rotation(deg(23.0f), Vector3::xAxis()); |
|
|
|
|
Quaternion a = Quaternion::rotation(Deg(15.0f), Vector3(1.0f/Constants<float>::sqrt3())); |
|
|
|
|
Quaternion b = Quaternion::rotation(Deg(23.0f), Vector3::xAxis()); |
|
|
|
|
|
|
|
|
|
std::ostringstream o; |
|
|
|
|
Corrade::Utility::Error::setOutput(&o); |
|
|
|
|
@ -320,8 +322,8 @@ void QuaternionTest::slerp() {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void QuaternionTest::rotateVector() { |
|
|
|
|
Quaternion a = Quaternion::rotation(deg(23.0f), Vector3::xAxis()); |
|
|
|
|
Matrix4 m = Matrix4::rotationX(deg(23.0f)); |
|
|
|
|
Quaternion a = Quaternion::rotation(Deg(23.0f), Vector3::xAxis()); |
|
|
|
|
Matrix4 m = Matrix4::rotationX(Deg(23.0f)); |
|
|
|
|
Vector3 v(5.0f, -3.6f, 0.7f); |
|
|
|
|
|
|
|
|
|
Vector3 rotated = a.rotateVector(v); |
|
|
|
|
@ -330,8 +332,8 @@ void QuaternionTest::rotateVector() {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void QuaternionTest::rotateVectorNormalized() { |
|
|
|
|
Quaternion a = Quaternion::rotation(deg(23.0f), Vector3::xAxis()); |
|
|
|
|
Matrix4 m = Matrix4::rotationX(deg(23.0f)); |
|
|
|
|
Quaternion a = Quaternion::rotation(Deg(23.0f), Vector3::xAxis()); |
|
|
|
|
Matrix4 m = Matrix4::rotationX(Deg(23.0f)); |
|
|
|
|
Vector3 v(5.0f, -3.6f, 0.7f); |
|
|
|
|
|
|
|
|
|
std::ostringstream o; |
|
|
|
|
|