range.hpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /// @ref gtx_range
  2. /// @file glm/gtx/range.hpp
  3. /// @author Joshua Moerman
  4. ///
  5. /// @defgroup gtx_range GLM_GTX_range
  6. /// @ingroup gtx
  7. ///
  8. /// Include <glm/gtx/range.hpp> to use the features of this extension.
  9. ///
  10. /// Defines begin and end for vectors and matrices. Useful for range-based for loop.
  11. /// The range is defined over the elements, not over columns or rows (e.g. mat4 has 16 elements).
  12. #pragma once
  13. // Dependencies
  14. #include "../detail/setup.hpp"
  15. #ifndef GLM_ENABLE_EXPERIMENTAL
  16. # error "GLM: GLM_GTX_range is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
  17. #endif
  18. #if !GLM_HAS_RANGE_FOR
  19. # error "GLM_GTX_range requires C++11 suppport or 'range for'"
  20. #endif
  21. #include "../gtc/type_ptr.hpp"
  22. #include "../gtc/vec1.hpp"
  23. namespace glm
  24. {
  25. /// @addtogroup gtx_range
  26. /// @{
  27. # if GLM_COMPILER & GLM_COMPILER_VC
  28. # pragma warning(push)
  29. # pragma warning(disable : 4100) // unreferenced formal parameter
  30. # endif
  31. template<typename T, qualifier Q>
  32. inline length_t components(vec<1, T, Q> const& v)
  33. {
  34. return v.length();
  35. }
  36. template<typename T, qualifier Q>
  37. inline length_t components(vec<2, T, Q> const& v)
  38. {
  39. return v.length();
  40. }
  41. template<typename T, qualifier Q>
  42. inline length_t components(vec<3, T, Q> const& v)
  43. {
  44. return v.length();
  45. }
  46. template<typename T, qualifier Q>
  47. inline length_t components(vec<4, T, Q> const& v)
  48. {
  49. return v.length();
  50. }
  51. template<typename genType>
  52. inline length_t components(genType const& m)
  53. {
  54. return m.length() * m[0].length();
  55. }
  56. template<typename genType>
  57. inline typename genType::value_type const * begin(genType const& v)
  58. {
  59. return value_ptr(v);
  60. }
  61. template<typename genType>
  62. inline typename genType::value_type const * end(genType const& v)
  63. {
  64. return begin(v) + components(v);
  65. }
  66. template<typename genType>
  67. inline typename genType::value_type * begin(genType& v)
  68. {
  69. return value_ptr(v);
  70. }
  71. template<typename genType>
  72. inline typename genType::value_type * end(genType& v)
  73. {
  74. return begin(v) + components(v);
  75. }
  76. # if GLM_COMPILER & GLM_COMPILER_VC
  77. # pragma warning(pop)
  78. # endif
  79. /// @}
  80. }//namespace glm