Browse Source

Fixed quaternion tests

Christophe Riccio 14 years ago
parent
commit
39580d05f0
1 changed files with 45 additions and 0 deletions
  1. 45 0
      test/gtx/gtx_quaternion.cpp

+ 45 - 0
test/gtx/gtx_quaternion.cpp

@@ -11,6 +11,23 @@
 #include <glm/gtx/quaternion.hpp>
 #include <glm/gtx/epsilon.hpp>
 
+int test_quat_mix()
+{
+	int Error = 0;
+    
+	glm::quat A = glm::angleAxis(0.0f, glm::vec3(0, 0, 1));
+	glm::quat B = glm::angleAxis(90.0f, glm::vec3(0, 0, 1));
+    glm::quat C = glm::mix(A, B, 0.5f);
+    glm::quat D = glm::angleAxis(45.0f, glm::vec3(0, 0, 1));
+    
+    Error += glm::equalEpsilon(C.x, D.x, 0.01f) ? 0 : 1;
+	Error += glm::equalEpsilon(C.y, D.y, 0.01f) ? 0 : 1;
+	Error += glm::equalEpsilon(C.z, D.z, 0.01f) ? 0 : 1;
+	Error += glm::equalEpsilon(C.w, D.w, 0.01f) ? 0 : 1;
+    
+	return Error;
+}
+
 int test_quat_fastMix()
 {
 	int Error = 0;
@@ -94,14 +111,42 @@ int test_quat_angle()
     return Error;
 }
 
+int test_quat_normalize()
+{
+    int Error = 0;
+ 
+    {
+        glm::quat Q = glm::angleAxis(45.0f, glm::vec3(0, 0, 1));
+        glm::quat N = glm::normalize(Q);
+        float L = glm::length(N);
+        Error += glm::equalEpsilon(L, 1.0f, 0.000001f) ? 0 : 1;
+    }
+    {
+        glm::quat Q = glm::angleAxis(45.0f, glm::vec3(0, 0, 2));
+        glm::quat N = glm::normalize(Q);
+        float L = glm::length(N);
+        Error += glm::equalEpsilon(L, 1.0f, 0.000001f) ? 0 : 1;
+    }
+    {
+        glm::quat Q = glm::angleAxis(45.0f, glm::vec3(1, 2, 3));
+        glm::quat N = glm::normalize(Q);
+        float L = glm::length(N);
+        Error += glm::equalEpsilon(L, 1.0f, 0.000001f) ? 0 : 1;
+    }
+
+    return Error;
+}
+
 int main()
 {
 	int Error = 0;
     
     Error += test_quat_angle();
 	Error += test_quat_angleAxis();
+	Error += test_quat_mix();
     Error += test_quat_fastMix();
     Error += test_quat_shortMix();
+    Error += test_quat_normalize();
 
 	return Error;
 }