Browse Source

Add static constants to vec4

- Tests, too
Jesse Talavera-Greenberg 10 years ago
parent
commit
02b011651b
3 changed files with 103 additions and 0 deletions
  1. 16 0
      glm/detail/type_vec4.hpp
  2. 64 0
      glm/detail/type_vec4.inl
  3. 23 0
      test/core/core_type_vec4.cpp

+ 16 - 0
glm/detail/type_vec4.hpp

@@ -112,6 +112,22 @@ namespace detail
 			static GLM_RELAXED_CONSTEXPR precision prec = P;
 			static GLM_RELAXED_CONSTEXPR precision prec = P;
 #		endif//GLM_META_PROG_HELPERS
 #		endif//GLM_META_PROG_HELPERS
 
 
+		static const type ZERO;
+		static const type X;
+		static const type Y;
+		static const type Z;
+		static const type W;
+		static const type XY;
+		static const type XZ;
+		static const type XW;
+		static const type YZ;
+		static const type YW;
+		static const type ZW;
+		static const type XYZ;
+		static const type XYW;
+		static const type XZW;
+		static const type YZW;
+		static const type XYZW;
 		// -- Data --
 		// -- Data --
 
 
 #		if GLM_HAS_ANONYMOUS_UNION && GLM_NOT_BUGGY_VC32BITS
 #		if GLM_HAS_ANONYMOUS_UNION && GLM_NOT_BUGGY_VC32BITS

+ 64 - 0
glm/detail/type_vec4.inl

@@ -32,6 +32,70 @@
 
 
 namespace glm
 namespace glm
 {
 {
+template <typename T, precision P>
+const tvec4<T, P> tvec4<T, P>::ZERO =
+		tvec4<T, P>(static_cast<T>(0), static_cast<T>(0), static_cast<T>(0), static_cast<T>(0));
+
+template <typename T, precision P>
+const tvec4<T, P> tvec4<T, P>::X =
+		tvec4<T, P>(static_cast<T>(1), static_cast<T>(0), static_cast<T>(0), static_cast<T>(0));
+
+template <typename T, precision P>
+const tvec4<T, P> tvec4<T, P>::Y =
+		tvec4<T, P>(static_cast<T>(0), static_cast<T>(1), static_cast<T>(0), static_cast<T>(0));
+
+template <typename T, precision P>
+const tvec4<T, P> tvec4<T, P>::Z =
+		tvec4<T, P>(static_cast<T>(0), static_cast<T>(0), static_cast<T>(1), static_cast<T>(0));
+
+template <typename T, precision P>
+const tvec4<T, P> tvec4<T, P>::W =
+		tvec4<T, P>(static_cast<T>(0), static_cast<T>(0), static_cast<T>(0), static_cast<T>(1));
+
+template <typename T, precision P>
+const tvec4<T, P> tvec4<T, P>::XY =
+		tvec4<T, P>(static_cast<T>(1), static_cast<T>(1), static_cast<T>(0), static_cast<T>(0));
+
+template <typename T, precision P>
+const tvec4<T, P> tvec4<T, P>::XZ =
+		tvec4<T, P>(static_cast<T>(1), static_cast<T>(0), static_cast<T>(1), static_cast<T>(0));
+
+template <typename T, precision P>
+const tvec4<T, P> tvec4<T, P>::XW =
+		tvec4<T, P>(static_cast<T>(1), static_cast<T>(0), static_cast<T>(0), static_cast<T>(1));
+
+template <typename T, precision P>
+const tvec4<T, P> tvec4<T, P>::YZ =
+		tvec4<T, P>(static_cast<T>(0), static_cast<T>(1), static_cast<T>(1), static_cast<T>(0));
+
+template <typename T, precision P>
+const tvec4<T, P> tvec4<T, P>::YW =
+		tvec4<T, P>(static_cast<T>(0), static_cast<T>(1), static_cast<T>(0), static_cast<T>(1));
+
+template <typename T, precision P>
+const tvec4<T, P> tvec4<T, P>::ZW =
+		tvec4<T, P>(static_cast<T>(0), static_cast<T>(0), static_cast<T>(1), static_cast<T>(1));
+
+template <typename T, precision P>
+const tvec4<T, P> tvec4<T, P>::XYZ =
+		tvec4<T, P>(static_cast<T>(1), static_cast<T>(1), static_cast<T>(1), static_cast<T>(0));
+
+template <typename T, precision P>
+const tvec4<T, P> tvec4<T, P>::XYW =
+		tvec4<T, P>(static_cast<T>(1), static_cast<T>(1), static_cast<T>(0), static_cast<T>(1));
+
+template <typename T, precision P>
+const tvec4<T, P> tvec4<T, P>::XZW =
+		tvec4<T, P>(static_cast<T>(1), static_cast<T>(0), static_cast<T>(1), static_cast<T>(1));
+
+template <typename T, precision P>
+const tvec4<T, P> tvec4<T, P>::YZW =
+		tvec4<T, P>(static_cast<T>(0), static_cast<T>(1), static_cast<T>(1), static_cast<T>(1));
+
+template <typename T, precision P>
+const tvec4<T, P> tvec4<T, P>::XYZW =
+		tvec4<T, P>(static_cast<T>(1), static_cast<T>(1), static_cast<T>(1), static_cast<T>(1));
+
 	// -- Implicit basic constructors --
 	// -- Implicit basic constructors --
 
 
 #	if !GLM_HAS_DEFAULTED_FUNCTIONS || !defined(GLM_FORCE_NO_CTOR_INIT)
 #	if !GLM_HAS_DEFAULTED_FUNCTIONS || !defined(GLM_FORCE_NO_CTOR_INIT)

+ 23 - 0
test/core/core_type_vec4.cpp

@@ -376,6 +376,28 @@ int test_operator_increment()
 	return Error;
 	return Error;
 }
 }
 
 
+int test_vec4_static_const() {
+	int Error(0);
+
+	Error += (glm::ivec4(0, 0, 0, 0) == glm::ivec4::ZERO) ? 0 : 1;
+	Error += (glm::vec4(1, 0, 0, 0) == glm::vec4::X) ? 0 : 1;
+	Error += (glm::bvec4(false, true, false, false) == glm::bvec4::Y) ? 0 : 1;
+	Error += (glm::bvec4(false, false, true, false) == glm::bvec4::Z) ? 0 : 1;
+	Error += (glm::uvec4(0u, 0u, 0u, 1u) == glm::uvec4::W) ? 0 : 1;
+	Error += (glm::dvec4(1, 1, 0, 0) == glm::dvec4::XY) ? 0 : 1;
+	Error += (glm::vec4(1, 0, 1, 0) == glm::vec4::XZ) ? 0 : 1;
+	Error += (glm::vec4(1, 0, 0, 1) == glm::vec4::XW) ? 0 : 1;
+	Error += (glm::uvec4(0u, 1u, 1u, 0u) == glm::uvec4::YZ) ? 0 : 1;
+	Error += (glm::vec4(0, 1, 0, 1) == glm::vec4::YW) ? 0 : 1;
+	Error += (glm::dvec4(1, 1, 1, 0) == glm::dvec4::XYZ) ? 0 : 1;
+	Error += (glm::vec4(1, 1, 0, 1) == glm::vec4::XYW) ? 0 : 1;
+	Error += (glm::vec4(1, 0, 1, 1) == glm::vec4::XZW) ? 0 : 1;
+	Error += (glm::vec4(0, 1, 1, 1) == glm::vec4::YZW) ? 0 : 1;
+	Error += (glm::vec4(1, 1, 1, 1) == glm::vec4::XYZW) ? 0 : 1;
+
+	return Error;
+}
+
 struct AoS
 struct AoS
 {
 {
 	glm::vec4 A;
 	glm::vec4 A;
@@ -486,6 +508,7 @@ int main()
 		Error += test_vec4_perf_SoA(Size);
 		Error += test_vec4_perf_SoA(Size);
 #	endif//NDEBUG
 #	endif//NDEBUG
 
 
+	Error += test_vec4_static_const();
 	Error += test_vec4_ctor();
 	Error += test_vec4_ctor();
 	Error += test_vec4_size();
 	Error += test_vec4_size();
 	Error += test_vec4_operators();
 	Error += test_vec4_operators();