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.

99 lines
2.8 KiB

5 years ago
  1. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2. // OpenGL Mathematics Copyright (c) 2005 - 2012 G-Truc Creation (www.g-truc.net)
  3. ///////////////////////////////////////////////////////////////////////////////////////////////////
  4. // Created : 2011-05-31
  5. // Updated : 2011-05-31
  6. // Licence : This source is under MIT licence
  7. // File : test/gtx/random.cpp
  8. ///////////////////////////////////////////////////////////////////////////////////////////////////
  9. #include <glm/glm.hpp>
  10. #include <glm/gtx/random.hpp>
  11. #include <glm/gtx/epsilon.hpp>
  12. #include <iostream>
  13. int test_signedRand1()
  14. {
  15. int Error = 0;
  16. {
  17. float ResultFloat = 0.0f;
  18. double ResultDouble = 0.0f;
  19. for(std::size_t i = 0; i < 100000; ++i)
  20. {
  21. ResultFloat += glm::signedRand1<float>();
  22. ResultDouble += glm::signedRand1<double>();
  23. }
  24. Error += glm::equalEpsilon(ResultFloat, 0.0f, 0.0001f);
  25. Error += glm::equalEpsilon(ResultDouble, 0.0, 0.0001);
  26. }
  27. return Error;
  28. }
  29. int test_normalizedRand2()
  30. {
  31. int Error = 0;
  32. {
  33. std::size_t Max = 100000;
  34. float ResultFloat = 0.0f;
  35. double ResultDouble = 0.0f;
  36. for(std::size_t i = 0; i < Max; ++i)
  37. {
  38. ResultFloat += glm::length(glm::normalizedRand2<float>());
  39. ResultDouble += glm::length(glm::normalizedRand2<double>());
  40. }
  41. Error += glm::equalEpsilon(ResultFloat, float(Max), 0.000001f) ? 0 : 1;
  42. Error += glm::equalEpsilon(ResultDouble, double(Max), 0.000001) ? 0 : 1;
  43. assert(!Error);
  44. }
  45. return Error;
  46. }
  47. int test_normalizedRand3()
  48. {
  49. int Error = 0;
  50. {
  51. std::size_t Max = 100000;
  52. float ResultFloatA = 0.0f;
  53. float ResultFloatB = 0.0f;
  54. float ResultFloatC = 0.0f;
  55. double ResultDoubleA = 0.0f;
  56. double ResultDoubleB = 0.0f;
  57. double ResultDoubleC = 0.0f;
  58. for(std::size_t i = 0; i < Max; ++i)
  59. {
  60. ResultFloatA += glm::length(glm::normalizedRand3<float>());
  61. ResultDoubleA += glm::length(glm::normalizedRand3<double>());
  62. ResultFloatB += glm::length(glm::normalizedRand3(2.0f, 2.0f));
  63. ResultDoubleB += glm::length(glm::normalizedRand3(2.0, 2.0));
  64. ResultFloatC += glm::length(glm::normalizedRand3(1.0f, 3.0f));
  65. ResultDoubleC += glm::length(glm::normalizedRand3(1.0, 3.0));
  66. }
  67. Error += glm::equalEpsilon(ResultFloatA, float(Max), 0.0001f) ? 0 : 1;
  68. Error += glm::equalEpsilon(ResultDoubleA, double(Max), 0.0001) ? 0 : 1;
  69. Error += glm::equalEpsilon(ResultFloatB, float(Max * 2), 0.0001f) ? 0 : 1;
  70. Error += glm::equalEpsilon(ResultDoubleB, double(Max * 2), 0.0001) ? 0 : 1;
  71. Error += (ResultFloatC >= float(Max) && ResultFloatC <= float(Max * 3)) ? 0 : 1;
  72. Error += (ResultDoubleC >= double(Max) && ResultDoubleC <= double(Max * 3)) ? 0 : 1;
  73. }
  74. return Error;
  75. }
  76. int main()
  77. {
  78. int Error = 0;
  79. Error += test_signedRand1();
  80. Error += test_normalizedRand2();
  81. Error += test_normalizedRand3();
  82. return Error;
  83. }