Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //
  2. // Lol Engine
  3. //
  4. // Copyright © 2010—2015 Sam Hocevar <sam@hocevar.net>
  5. //
  6. // Lol Engine is free software. It comes without any warranty, to
  7. // the extent permitted by applicable law. You can redistribute it
  8. // and/or modify it under the terms of the Do What the Fuck You Want
  9. // to Public License, Version 2, as published by the WTFPL Task Force.
  10. // See http://www.wtfpl.net/ for more details.
  11. //
  12. #include <lol/engine-internal.h>
  13. #include <ostream> /* std::ostream */
  14. namespace lol
  15. {
  16. #define LOL_PRINTF_TOSTRING(type, ...) \
  17. template<> void type::printf() const { msg::debug(__VA_ARGS__); } \
  18. template<> std::string type::tostring() const { return format(__VA_ARGS__); }
  19. LOL_PRINTF_TOSTRING(vec2, "[ %6.6f %6.6f ]\n", x, y);
  20. LOL_PRINTF_TOSTRING(ivec2, "[ %i %i ]\n", x, y);
  21. LOL_PRINTF_TOSTRING(cmplx, "[ %6.6f %6.6f ]\n", x, y);
  22. LOL_PRINTF_TOSTRING(vec3, "[ %6.6f %6.6f %6.6f ]\n", x, y, z);
  23. LOL_PRINTF_TOSTRING(ivec3, "[ %i %i %i ]\n", x, y, z);
  24. LOL_PRINTF_TOSTRING(vec4, "[ %6.6f %6.6f %6.6f %6.6f ]\n", x, y, z, w);
  25. LOL_PRINTF_TOSTRING(ivec4, "[ %i %i %i %i ]\n", x, y, z, w);
  26. LOL_PRINTF_TOSTRING(quat, "[ %6.6f %6.6f %6.6f %6.6f ]\n", w, x, y, z);
  27. template<> void mat2::printf() const
  28. {
  29. mat2 const &p = *this;
  30. msg::debug("[ %6.6f %6.6f\n", p[0][0], p[1][0]);
  31. msg::debug(" %6.6f %6.6f ]\n", p[0][1], p[1][1]);
  32. }
  33. template<> std::string mat2::tostring() const
  34. {
  35. mat2 const &p = *this;
  36. return format("[ %6.6f %6.6f\n", p[0][0], p[1][0]) +
  37. format(" %6.6f %6.6f ]\n", p[0][1], p[1][1]);
  38. }
  39. template<> void mat3::printf() const
  40. {
  41. mat3 const &p = *this;
  42. msg::debug("[ %6.6f %6.6f %6.6f\n", p[0][0], p[1][0], p[2][0]);
  43. msg::debug(" %6.6f %6.6f %6.6f\n", p[0][1], p[1][1], p[2][1]);
  44. msg::debug(" %6.6f %6.6f %6.6f ]\n", p[0][2], p[1][2], p[2][2]);
  45. }
  46. template<> std::string mat3::tostring() const
  47. {
  48. mat3 const &p = *this;
  49. return format("[ %6.6f %6.6f %6.6f\n", p[0][0], p[1][0], p[2][0]) +
  50. format(" %6.6f %6.6f %6.6f\n", p[0][1], p[1][1], p[2][1]) +
  51. format(" %6.6f %6.6f %6.6f ]\n", p[0][2], p[1][2], p[2][2]);
  52. }
  53. template<> void mat4::printf() const
  54. {
  55. mat4 const &p = *this;
  56. msg::debug("[ %6.6f %6.6f %6.6f %6.6f\n",
  57. p[0][0], p[1][0], p[2][0], p[3][0]);
  58. msg::debug(" %6.6f %6.6f %6.6f %6.6f\n",
  59. p[0][1], p[1][1], p[2][1], p[3][1]);
  60. msg::debug(" %6.6f %6.6f %6.6f %6.6f\n",
  61. p[0][2], p[1][2], p[2][2], p[3][2]);
  62. msg::debug(" %6.6f %6.6f %6.6f %6.6f ]\n",
  63. p[0][3], p[1][3], p[2][3], p[3][3]);
  64. }
  65. template<> std::string mat4::tostring() const
  66. {
  67. mat4 const &p = *this;
  68. return format("[ %6.6f %6.6f %6.6f %6.6f\n",
  69. p[0][0], p[1][0], p[2][0], p[3][0]) +
  70. format(" %6.6f %6.6f %6.6f %6.6f\n",
  71. p[0][1], p[1][1], p[2][1], p[3][1]) +
  72. format(" %6.6f %6.6f %6.6f %6.6f\n",
  73. p[0][2], p[1][2], p[2][2], p[3][2]) +
  74. format(" %6.6f %6.6f %6.6f %6.6f ]\n",
  75. p[0][3], p[1][3], p[2][3], p[3][3]);
  76. }
  77. } /* namespace lol */