151 строка
4.8 KiB

  1. //
  2. // Lol Engine
  3. //
  4. // Copyright: (c) 2010-2014 Sam Hocevar <sam@hocevar.net>
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the Do What The Fuck You Want To
  7. // Public License, Version 2, as published by Sam Hocevar. See
  8. // http://www.wtfpl.net/ for more details.
  9. //
  10. #include <lol/engine-internal.h>
  11. #include <ostream> /* std::ostream */
  12. namespace lol
  13. {
  14. #define LOL_PRINTF_TOSTRING(type, ...) \
  15. template<> void type::printf() const { Log::Debug(__VA_ARGS__); } \
  16. template<> String type::tostring() const { return String::Printf(__VA_ARGS__); }
  17. LOL_PRINTF_TOSTRING(vec2, "[ %6.6f %6.6f ]\n", x, y);
  18. LOL_PRINTF_TOSTRING(ivec2, "[ %i %i ]\n", x, y);
  19. LOL_PRINTF_TOSTRING(cmplx, "[ %6.6f %6.6f ]\n", x, y);
  20. LOL_PRINTF_TOSTRING(vec3, "[ %6.6f %6.6f %6.6f ]\n", x, y, z);
  21. LOL_PRINTF_TOSTRING(ivec3, "[ %i %i %i ]\n", x, y, z);
  22. LOL_PRINTF_TOSTRING(vec4, "[ %6.6f %6.6f %6.6f %6.6f ]\n", x, y, z, w);
  23. LOL_PRINTF_TOSTRING(ivec4, "[ %i %i %i %i ]\n", x, y, z, w);
  24. LOL_PRINTF_TOSTRING(quat, "[ %6.6f %6.6f %6.6f %6.6f ]\n", w, x, y, z);
  25. template<> void mat2::printf() const
  26. {
  27. mat2 const &p = *this;
  28. Log::Debug("[ %6.6f %6.6f\n", p[0][0], p[1][0]);
  29. Log::Debug(" %6.6f %6.6f ]\n", p[0][1], p[1][1]);
  30. }
  31. template<> String mat2::tostring() const
  32. {
  33. mat2 const &p = *this;
  34. return String::Printf("[ %6.6f %6.6f\n", p[0][0], p[1][0]) +
  35. String::Printf(" %6.6f %6.6f ]\n", p[0][1], p[1][1]);
  36. }
  37. template<> void mat3::printf() const
  38. {
  39. mat3 const &p = *this;
  40. Log::Debug("[ %6.6f %6.6f %6.6f\n", p[0][0], p[1][0], p[2][0]);
  41. Log::Debug(" %6.6f %6.6f %6.6f\n", p[0][1], p[1][1], p[2][1]);
  42. Log::Debug(" %6.6f %6.6f %6.6f ]\n", p[0][2], p[1][2], p[2][2]);
  43. }
  44. template<> String mat3::tostring() const
  45. {
  46. mat3 const &p = *this;
  47. return String::Printf("[ %6.6f %6.6f %6.6f\n", p[0][0], p[1][0], p[2][0]) +
  48. String::Printf(" %6.6f %6.6f %6.6f\n", p[0][1], p[1][1], p[2][1]) +
  49. String::Printf(" %6.6f %6.6f %6.6f ]\n", p[0][2], p[1][2], p[2][2]);
  50. }
  51. template<> void mat4::printf() const
  52. {
  53. mat4 const &p = *this;
  54. Log::Debug("[ %6.6f %6.6f %6.6f %6.6f\n",
  55. p[0][0], p[1][0], p[2][0], p[3][0]);
  56. Log::Debug(" %6.6f %6.6f %6.6f %6.6f\n",
  57. p[0][1], p[1][1], p[2][1], p[3][1]);
  58. Log::Debug(" %6.6f %6.6f %6.6f %6.6f\n",
  59. p[0][2], p[1][2], p[2][2], p[3][2]);
  60. Log::Debug(" %6.6f %6.6f %6.6f %6.6f ]\n",
  61. p[0][3], p[1][3], p[2][3], p[3][3]);
  62. }
  63. template<> String mat4::tostring() const
  64. {
  65. mat4 const &p = *this;
  66. return String::Printf("[ %6.6f %6.6f %6.6f %6.6f\n",
  67. p[0][0], p[1][0], p[2][0], p[3][0]) +
  68. String::Printf(" %6.6f %6.6f %6.6f %6.6f\n",
  69. p[0][1], p[1][1], p[2][1], p[3][1]) +
  70. String::Printf(" %6.6f %6.6f %6.6f %6.6f\n",
  71. p[0][2], p[1][2], p[2][2], p[3][2]) +
  72. String::Printf(" %6.6f %6.6f %6.6f %6.6f ]\n",
  73. p[0][3], p[1][3], p[2][3], p[3][3]);
  74. }
  75. template<> std::ostream &operator<<(std::ostream &stream, ivec2 const &v)
  76. {
  77. return stream << "(" << v.x << ", " << v.y << ")";
  78. }
  79. template<> std::ostream &operator<<(std::ostream &stream, ivec3 const &v)
  80. {
  81. return stream << "(" << v.x << ", " << v.y << ", " << v.z << ")";
  82. }
  83. template<> std::ostream &operator<<(std::ostream &stream, ivec4 const &v)
  84. {
  85. return stream << "(" << v.x << ", " << v.y << ", "
  86. << v.z << ", " << v.w << ")";
  87. }
  88. template<> std::ostream &operator<<(std::ostream &stream, vec2 const &v)
  89. {
  90. return stream << "(" << v.x << ", " << v.y << ")";
  91. }
  92. template<> std::ostream &operator<<(std::ostream &stream, cmplx const &v)
  93. {
  94. return stream << "(" << v.x << ", " << v.y << ")";
  95. }
  96. template<> std::ostream &operator<<(std::ostream &stream, vec3 const &v)
  97. {
  98. return stream << "(" << v.x << ", " << v.y << ", " << v.z << ")";
  99. }
  100. template<> std::ostream &operator<<(std::ostream &stream, vec4 const &v)
  101. {
  102. return stream << "(" << v.x << ", " << v.y << ", "
  103. << v.z << ", " << v.w << ")";
  104. }
  105. template<> std::ostream &operator<<(std::ostream &stream, quat const &v)
  106. {
  107. return stream << "(" << v.x << ", " << v.y << ", "
  108. << v.z << ", " << v.w << ")";
  109. }
  110. template<> std::ostream &operator<<(std::ostream &stream, mat4 const &m)
  111. {
  112. stream << "((" << m[0][0] << ", " << m[1][0]
  113. << ", " << m[2][0] << ", " << m[3][0] << "), ";
  114. stream << "(" << m[0][1] << ", " << m[1][1]
  115. << ", " << m[2][1] << ", " << m[3][1] << "), ";
  116. stream << "(" << m[0][2] << ", " << m[1][2]
  117. << ", " << m[2][2] << ", " << m[3][2] << "), ";
  118. stream << "(" << m[0][3] << ", " << m[1][3]
  119. << ", " << m[2][3] << ", " << m[3][3] << "))";
  120. return stream;
  121. }
  122. } /* namespace lol */