浏览代码

Added spherical and circular rand implementations

Christophe Riccio 14 年之前
父节点
当前提交
5f52e6a82f
共有 3 个文件被更改,包括 41 次插入6 次删除
  1. 4 4
      glm/gtc/random.hpp
  2. 35 0
      glm/gtc/random.inl
  3. 2 2
      test/gtc/gtc_random.cpp

+ 4 - 4
glm/gtc/random.hpp

@@ -66,10 +66,10 @@ namespace glm
 
 	/// Generate random numbers in the interval [Min, Max], according a gaussian distribution 
 	/// (From GLM_GTX_random extension)
-	template <typename T, template <typename> class vecType> 
-	vecType<T> gaussRand(
-		vecType<T> const & Mean, 
-		vecType<T> const & Deviation);
+	template <typename genType>
+	genType gaussRand(
+		genType const & Mean, 
+		genType const & Deviation);
 	
 	/// Generate a random 2D vector which coordinates are regulary distributed on a circle of a given radius
 	/// (From GLM_GTX_random extension)

+ 35 - 0
glm/gtc/random.inl

@@ -81,4 +81,39 @@ GLM_FUNC_QUALIFIER detail::tvec4<T> linearRand
 		linearRand(Min.w, Max.w));
 }
 
+template <>
+half gaussRand
+(
+	half const & Mean,	
+	half const & Deviation
+)
+{
+
+template <typename T> 
+detail::tvec2<T> circularRand
+(
+	T const & Radius
+)
+{
+	T a = compRand1<T>(T(0), T(6.283185307179586476925286766559f));
+	return detail::tvec2<T>(cos(a), sin(a)) * Radius;		
+}
+	
+template <typename T> 
+detail::tvec3<T> sphericalRand
+(
+	T const & Radius
+)
+{
+	T z = compRand1(T(-1), T(1));
+	T a = compRand1(T(0), T(6.283185307179586476925286766559f));
+	
+	T r = sqrt(T(1) - z * z);
+	
+	T x = r * cos(a);
+	T y = r * sin(a);
+	
+	return detail::tvec3<T>(x, y, z) * Radius;	
+}
+
 }//namespace glm

+ 2 - 2
test/gtc/gtc_random.cpp

@@ -12,7 +12,7 @@
 #include <glm/gtx/epsilon.hpp>
 #include <iostream>
 
-int test_signedRand1()
+int test_linearRand()
 {
 	int Error = 0;
 
@@ -93,7 +93,7 @@ int main()
 {
 	int Error = 0;
 
-	Error += test_signedRand1();
+	Error += test_linearRand();
 	Error += test_normalizedRand2();
 	Error += test_normalizedRand3();