Base.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #ifndef BASE_H_
  2. #define BASE_H_
  3. // C++ includes
  4. #include <cmath>
  5. #include <cstdio>
  6. #include <cstdlib>
  7. #include <cstdarg>
  8. #include <cassert>
  9. #include <cmath>
  10. #include <cfloat>
  11. #include <ctime>
  12. #include <iostream>
  13. #include <fstream>
  14. #include <string>
  15. #include <vector>
  16. #include <list>
  17. #include <map>
  18. #include <algorithm>
  19. #include <sys/stat.h>
  20. // PNG
  21. #include <png.h>
  22. // Collada includes
  23. #include <dae.h>
  24. #include <dae/daeSIDResolver.h>
  25. #include <dae/domAny.h>
  26. #include <dom/domCOLLADA.h>
  27. #include <dom/domConstants.h>
  28. #include <dom/domElements.h>
  29. #include <dom/domCamera.h>
  30. #include <dom/domProfile_COMMON.h>
  31. // Defines
  32. #ifndef M_1_PI
  33. #define M_1_PI 0.31830988618379067154
  34. #endif
  35. #define MATH_FLOAT_SMALL 1.0e-37f
  36. #define MATH_TOLERANCE 2e-37f
  37. #define MATH_E 2.71828182845904523536f
  38. #define MATH_LOG10E 0.4342944819032518f
  39. #define MATH_LOG2E 1.442695040888963387f
  40. #define MATH_PI 3.14159265358979323846f
  41. #define MATH_PIOOVER2 1.57079632679489661923f
  42. #define MATH_PIOOVER4 M_PI_4
  43. #define MATH_PIX2 6.28318530717958647693f
  44. #define MATH_EPSILON 0.000001f
  45. #define MATH_DEG_TO_RAD(x) ((x) * 0.0174532925f)
  46. #define MATH_RAD_TO_DEG(x) ((x)* 57.29577951f)
  47. #define MATH_RANDOM_MINUS1_1() ((2.0f*((float)rand()/RAND_MAX))-1.0f) // Returns a random float between -1 and 1.
  48. #define MATH_RANDOM_0_1() ((float)rand()/RAND_MAX) // Returns a random float between 0 and 1.
  49. namespace gameplay
  50. {
  51. enum VertexUsage
  52. {
  53. UNKNOWN = 0,
  54. POSITION = 1,
  55. NORMAL = 2,
  56. COLOR = 3,
  57. TANGENT = 4,
  58. BINORMAL = 5,
  59. BLENDWEIGHTS = 6,
  60. BLENDINDICES = 7,
  61. TEXCOORD0 = 8,
  62. TEXCOORD1 = 9,
  63. TEXCOORD2 = 10,
  64. TEXCOORD3 = 11,
  65. TEXCOORD4 = 12,
  66. TEXCOORD5 = 13,
  67. TEXCOORD6 = 14,
  68. TEXCOORD7 = 15
  69. };
  70. void fillArray(float values[], float value, size_t length);
  71. /**
  72. * Returns the base name of the given path.
  73. * Example: "c:/foo/bar/model.dae" returns "model.dae"
  74. *
  75. * @param filepath File path.
  76. *
  77. * @return Base file name.
  78. */
  79. std::string getBaseName(const std::string& filepath);
  80. #define ISZERO(x) (fabs(x) < 0.000001f)
  81. // Object deletion macro
  82. #define SAFE_DELETE(x) \
  83. if (x) \
  84. { \
  85. delete x; \
  86. x = NULL; \
  87. }
  88. #ifdef NDEBUG
  89. #define DEBUGPRINT(x)
  90. #define DEBUGPRINT_VARG(x, ...)
  91. #else
  92. #define DEBUGPRINT(x) printf(x)
  93. #define DEBUGPRINT_VARG(x, ...) printf(x, __VA_ARGS__)
  94. #endif
  95. }
  96. #endif