core_func_swizzle.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. ///////////////////////////////////////////////////////////////////////////////////
  2. /// OpenGL Mathematics (glm.g-truc.net)
  3. ///
  4. /// Copyright (c) 2005 - 2015 G-Truc Creation (www.g-truc.net)
  5. /// Permission is hereby granted, free of charge, to any person obtaining a copy
  6. /// of this software and associated documentation files (the "Software"), to deal
  7. /// in the Software without restriction, including without limitation the rights
  8. /// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. /// copies of the Software, and to permit persons to whom the Software is
  10. /// furnished to do so, subject to the following conditions:
  11. ///
  12. /// The above copyright notice and this permission notice shall be included in
  13. /// all copies or substantial portions of the Software.
  14. ///
  15. /// Restrictions:
  16. /// By making use of the Software for military purposes, you choose to make
  17. /// a Bunny unhappy.
  18. ///
  19. /// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. /// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. /// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. /// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. /// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. /// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. /// THE SOFTWARE.
  26. ///
  27. /// @file test/core/core_func_swizzle.cpp
  28. /// @date 2011-10-16 / 2014-11-25
  29. /// @author Christophe Riccio
  30. ///////////////////////////////////////////////////////////////////////////////////
  31. #define GLM_MESSAGES
  32. #define GLM_SWIZZLE
  33. #include <glm/glm.hpp>
  34. int test_ivec2_swizzle()
  35. {
  36. int Error = 0;
  37. glm::ivec2 A(1, 2);
  38. glm::ivec2 B = A.yx();
  39. glm::ivec2 C = B.yx();
  40. Error += A != B ? 0 : 1;
  41. Error += A == C ? 0 : 1;
  42. return Error;
  43. }
  44. int test_ivec3_swizzle()
  45. {
  46. int Error = 0;
  47. glm::ivec3 A(1, 2, 3);
  48. glm::ivec3 B = A.zyx();
  49. glm::ivec3 C = B.zyx();
  50. Error += A != B ? 0 : 1;
  51. Error += A == C ? 0 : 1;
  52. return Error;
  53. }
  54. int test_ivec4_swizzle()
  55. {
  56. int Error = 0;
  57. glm::ivec4 A(1, 2, 3, 4);
  58. glm::ivec4 B = A.wzyx();
  59. glm::ivec4 C = B.wzyx();
  60. Error += A != B ? 0 : 1;
  61. Error += A == C ? 0 : 1;
  62. return Error;
  63. }
  64. int test_vec4_swizzle()
  65. {
  66. int Error = 0;
  67. glm::vec4 A(1, 2, 3, 4);
  68. glm::vec4 B = A.wzyx();
  69. glm::vec4 C = B.wzyx();
  70. float f = glm::dot(C.wzyx(), C.xyzw());
  71. Error += A != B ? 0 : 1;
  72. Error += A == C ? 0 : 1;
  73. return Error;
  74. }
  75. int main()
  76. {
  77. int Error = 0;
  78. Error += test_ivec2_swizzle();
  79. Error += test_ivec3_swizzle();
  80. Error += test_ivec4_swizzle();
  81. Error += test_vec4_swizzle();
  82. return Error;
  83. }