Platformer in OpenGL
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
3.0 KiB

5 years ago
  1. #define GLM_ENABLE_EXPERIMENTAL
  2. #include <glm/gtx/component_wise.hpp>
  3. #include <glm/gtc/type_precision.hpp>
  4. #include <glm/gtc/epsilon.hpp>
  5. #include <glm/gtc/constants.hpp>
  6. #include <limits>
  7. namespace compNormalize
  8. {
  9. int run()
  10. {
  11. int Error(0);
  12. {
  13. glm::vec4 const A = glm::compNormalize<float>(glm::u8vec4(0, 127, 128, 255));
  14. Error += glm::epsilonEqual(A.x, 0.0f, glm::epsilon<float>()) ? 0 : 1;
  15. Error += A.y < 0.5f ? 0 : 1;
  16. Error += A.z > 0.5f ? 0 : 1;
  17. Error += glm::epsilonEqual(A.w, 1.0f, glm::epsilon<float>()) ? 0 : 1;
  18. }
  19. {
  20. glm::vec4 const A = glm::compNormalize<float>(glm::i8vec4(-128, -1, 0, 127));
  21. Error += glm::epsilonEqual(A.x,-1.0f, glm::epsilon<float>()) ? 0 : 1;
  22. Error += A.y < 0.0f ? 0 : 1;
  23. Error += A.z > 0.0f ? 0 : 1;
  24. Error += glm::epsilonEqual(A.w, 1.0f, glm::epsilon<float>()) ? 0 : 1;
  25. }
  26. {
  27. glm::vec4 const A = glm::compNormalize<float>(glm::u16vec4(
  28. std::numeric_limits<glm::u16>::min(),
  29. (std::numeric_limits<glm::u16>::max() >> 1) + 0,
  30. (std::numeric_limits<glm::u16>::max() >> 1) + 1,
  31. std::numeric_limits<glm::u16>::max()));
  32. Error += glm::epsilonEqual(A.x, 0.0f, glm::epsilon<float>()) ? 0 : 1;
  33. Error += A.y < 0.5f ? 0 : 1;
  34. Error += A.z > 0.5f ? 0 : 1;
  35. Error += glm::epsilonEqual(A.w, 1.0f, glm::epsilon<float>()) ? 0 : 1;
  36. }
  37. {
  38. glm::vec4 const A = glm::compNormalize<float>(glm::i16vec4(
  39. std::numeric_limits<glm::i16>::min(),
  40. static_cast<glm::i16>(-1),
  41. static_cast<glm::i16>(0),
  42. std::numeric_limits<glm::i16>::max()));
  43. Error += glm::epsilonEqual(A.x,-1.0f, glm::epsilon<float>()) ? 0 : 1;
  44. Error += A.y < 0.0f ? 0 : 1;
  45. Error += A.z > 0.0f ? 0 : 1;
  46. Error += glm::epsilonEqual(A.w, 1.0f, glm::epsilon<float>()) ? 0 : 1;
  47. }
  48. return Error;
  49. }
  50. }//namespace compNormalize
  51. namespace compScale
  52. {
  53. int run()
  54. {
  55. int Error(0);
  56. {
  57. glm::u8vec4 const A = glm::compScale<glm::u8>(glm::vec4(0.0f, 0.2f, 0.5f, 1.0f));
  58. Error += A.x == std::numeric_limits<glm::u8>::min() ? 0 : 1;
  59. Error += A.y < (std::numeric_limits<glm::u8>::max() >> 2) ? 0 : 1;
  60. Error += A.z == 127 ? 0 : 1;
  61. Error += A.w == 255 ? 0 : 1;
  62. }
  63. {
  64. glm::i8vec4 const A = glm::compScale<glm::i8>(glm::vec4(0.0f,-1.0f, 0.5f, 1.0f));
  65. Error += A.x == 0 ? 0 : 1;
  66. Error += A.y == -128 ? 0 : 1;
  67. Error += A.z == 63 ? 0 : 1;
  68. Error += A.w == 127 ? 0 : 1;
  69. }
  70. {
  71. glm::u16vec4 const A = glm::compScale<glm::u16>(glm::vec4(0.0f, 0.2f, 0.5f, 1.0f));
  72. Error += A.x == std::numeric_limits<glm::u16>::min() ? 0 : 1;
  73. Error += A.y < (std::numeric_limits<glm::u16>::max() >> 2) ? 0 : 1;
  74. Error += A.z == 32767 ? 0 : 1;
  75. Error += A.w == 65535 ? 0 : 1;
  76. }
  77. {
  78. glm::i16vec4 const A = glm::compScale<glm::i16>(glm::vec4(0.0f,-1.0f, 0.5f, 1.0f));
  79. Error += A.x == 0 ? 0 : 1;
  80. Error += A.y == -32768 ? 0 : 1;
  81. Error += A.z == 16383 ? 0 : 1;
  82. Error += A.w == 32767 ? 0 : 1;
  83. }
  84. return Error;
  85. }
  86. }// compScale
  87. int main()
  88. {
  89. int Error(0);
  90. Error += compNormalize::run();
  91. Error += compScale::run();
  92. return Error;
  93. }