lua_debug_line.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Copyright (c) 2012-2015 Daniele Bartolini and individual contributors.
  3. * License: https://github.com/taylor001/crown/blob/master/LICENSE
  4. */
  5. #include "lua_stack.h"
  6. #include "lua_environment.h"
  7. #include "debug_line.h"
  8. namespace crown
  9. {
  10. static int debug_line_add_line(lua_State* L)
  11. {
  12. LuaStack stack(L);
  13. stack.get_debug_line(1)->add_line(stack.get_vector3(2)
  14. , stack.get_vector3(3)
  15. , stack.get_color4(4)
  16. );
  17. return 0;
  18. }
  19. static int debug_line_add_axes(lua_State* L)
  20. {
  21. LuaStack stack(L);
  22. const float length = stack.num_args() == 3 ? stack.get_float(3) : 1.0f;
  23. stack.get_debug_line(1)->add_axes(stack.get_matrix4x4(2), length);
  24. return 0;
  25. }
  26. static int debug_line_add_circle(lua_State* L)
  27. {
  28. LuaStack stack(L);
  29. const uint32_t segments = stack.num_args() >= 6 ? stack.get_int(6) : 36;
  30. stack.get_debug_line(1)->add_circle(stack.get_vector3(2)
  31. , stack.get_float(3)
  32. , stack.get_vector3(4)
  33. , stack.get_color4(5)
  34. , segments
  35. );
  36. return 0;
  37. }
  38. static int debug_line_add_cone(lua_State* L)
  39. {
  40. LuaStack stack(L);
  41. const uint32_t segments = stack.num_args() >= 6 ? stack.get_int(6) : 36;
  42. stack.get_debug_line(1)->add_cone(stack.get_vector3(2)
  43. , stack.get_vector3(3)
  44. , stack.get_float(4)
  45. , stack.get_color4(5)
  46. , segments
  47. );
  48. return 0;
  49. }
  50. static int debug_line_add_sphere(lua_State* L)
  51. {
  52. LuaStack stack(L);
  53. const uint32_t segments = stack.num_args() >= 5 ? stack.get_int(5) : 36;
  54. stack.get_debug_line(1)->add_sphere(stack.get_vector3(2)
  55. , stack.get_float(3)
  56. , stack.get_color4(4)
  57. , segments
  58. );
  59. return 0;
  60. }
  61. static int debug_line_add_obb(lua_State* L)
  62. {
  63. LuaStack stack(L);
  64. stack.get_debug_line(1)->add_obb(stack.get_matrix4x4(2)
  65. , stack.get_vector3(3)
  66. , stack.get_color4(4)
  67. );
  68. return 0;
  69. }
  70. static int debug_line_reset(lua_State* L)
  71. {
  72. LuaStack stack(L);
  73. stack.get_debug_line(1)->reset();
  74. return 0;
  75. }
  76. static int debug_line_submit(lua_State* L)
  77. {
  78. LuaStack stack(L);
  79. stack.get_debug_line(1)->submit();
  80. return 0;
  81. }
  82. static int debug_line_tostring(lua_State* L)
  83. {
  84. LuaStack stack(L);
  85. stack.push_fstring("DebugLine (%p)", stack.get_debug_line(1));
  86. return 1;
  87. }
  88. void load_debug_line(LuaEnvironment& env)
  89. {
  90. env.load_module_function("DebugLine", "add_line", debug_line_add_line);
  91. env.load_module_function("DebugLine", "add_axes", debug_line_add_axes);
  92. env.load_module_function("DebugLine", "add_circle", debug_line_add_circle);
  93. env.load_module_function("DebugLine", "add_cone", debug_line_add_cone);
  94. env.load_module_function("DebugLine", "add_sphere", debug_line_add_sphere);
  95. env.load_module_function("DebugLine", "add_obb", debug_line_add_obb);
  96. env.load_module_function("DebugLine", "reset", debug_line_reset);
  97. env.load_module_function("DebugLine", "submit", debug_line_submit);
  98. env.load_module_function("DebugLine", "__index", "DebugLine");
  99. env.load_module_function("DebugLine", "__tostring", debug_line_tostring);
  100. }
  101. } // namespace crown