range.hpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. #if GLM_MESSAGES == GLM_ENABLE && !defined(GLM_EXT_INCLUDED)
  16. # ifndef GLM_ENABLE_EXPERIMENTAL
  17. # pragma message("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.")
  18. # else
  19. # pragma message("GLM: GLM_GTX_range extension included")
  20. # endif
  21. #endif
  22. #include "../gtc/type_ptr.hpp"
  23. #include "../gtc/vec1.hpp"
  24. namespace glm
  25. {
  26. /// @addtogroup gtx_range
  27. /// @{
  28. # if GLM_COMPILER & GLM_COMPILER_VC
  29. # pragma warning(push)
  30. # pragma warning(disable : 4100) // unreferenced formal parameter
  31. # endif
  32. template<typename T, qualifier Q>
  33. inline length_t components(vec<1, T, Q> const& v)
  34. {
  35. return v.length();
  36. }
  37. template<typename T, qualifier Q>
  38. inline length_t components(vec<2, T, Q> const& v)
  39. {
  40. return v.length();
  41. }
  42. template<typename T, qualifier Q>
  43. inline length_t components(vec<3, T, Q> const& v)
  44. {
  45. return v.length();
  46. }
  47. template<typename T, qualifier Q>
  48. inline length_t components(vec<4, T, Q> const& v)
  49. {
  50. return v.length();
  51. }
  52. template<typename genType>
  53. inline length_t components(genType const& m)
  54. {
  55. return m.length() * m[0].length();
  56. }
  57. template<typename genType>
  58. inline typename genType::value_type const * begin(genType const& v)
  59. {
  60. return value_ptr(v);
  61. }
  62. template<typename genType>
  63. inline typename genType::value_type const * end(genType const& v)
  64. {
  65. return begin(v) + components(v);
  66. }
  67. template<typename genType>
  68. inline typename genType::value_type * begin(genType& v)
  69. {
  70. return value_ptr(v);
  71. }
  72. template<typename genType>
  73. inline typename genType::value_type * end(genType& v)
  74. {
  75. return begin(v) + components(v);
  76. }
  77. # if GLM_COMPILER & GLM_COMPILER_VC
  78. # pragma warning(pop)
  79. # endif
  80. /// @}
  81. }//namespace glm