Bläddra i källkod

Fixed ticket #147 refract for scalar

Christophe Riccio 14 år sedan
förälder
incheckning
369e929910
2 ändrade filer med 28 tillägg och 2 borttagningar
  1. 19 0
      glm/core/func_geometric.inl
  2. 9 2
      test/core/core_func_geometric.cpp

+ 19 - 0
glm/core/func_geometric.inl

@@ -283,6 +283,25 @@ namespace glm
 	}
 
     // refract
+    template <typename genType>
+    GLM_FUNC_QUALIFIER genType refract
+	(
+		genType const & I, 
+		genType const & N, 
+		genType const & eta
+	)
+    {
+		//It could be a vector
+		//GLM_STATIC_ASSERT(detail::type<genType>::is_float);
+
+        genType dotValue = dot(N, I);
+        genType k = genType(1) - eta * eta * (genType(1) - dotValue * dotValue);
+        if(k < genType(0))
+            return genType(0);
+        else
+            return eta * I - (eta * dotValue + sqrt(k)) * N;
+    }
+
     template <typename genType>
     GLM_FUNC_QUALIFIER genType refract
 	(

+ 9 - 2
test/core/core_func_geometric.cpp

@@ -34,17 +34,24 @@ int test_refract()
 {
 	int Error = 0;
 
+	{
+		float A(1.0f);
+		float B(1.0f);
+		float C = glm::refract(A, B, 0.5f);
+		Error += C == 1.0f ? 0 : 1;
+	}
+
 	{
 		glm::vec2 A(1.0f, 0.0f);
 		glm::vec2 B(0.0f, 1.0f);
-		glm::vec2 C = glm::reflect(A, B);
+		glm::vec2 C = glm::refract(A, B, 0.5f);
 		Error += C == glm::vec2(-1.0, 0.0) ? 0 : 1;
 	}
 
 	{
 		glm::dvec2 A(1.0f, 0.0f);
 		glm::dvec2 B(0.0f, 1.0f);
-		glm::dvec2 C = glm::reflect(A, B);
+		glm::dvec2 C = glm::refract(A, B, 0.5);
 		Error += C == glm::dvec2(-1.0, 0.0) ? 0 : 1;
 	}