lua_camera.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * Copyright (c) 2012-2015 Daniele Bartolini and individual contributors.
  3. * License: https://github.com/taylor001/crown/blob/master/LICENSE
  4. */
  5. #include "camera.h"
  6. #include "vector3.h"
  7. #include "quaternion.h"
  8. #include "matrix4x4.h"
  9. #include "lua_stack.h"
  10. #include "lua_environment.h"
  11. namespace crown
  12. {
  13. static int camera_set_projection_type(lua_State* L)
  14. {
  15. LuaStack stack(L);
  16. stack.get_camera(1)->set_projection_type((ProjectionType::Enum) stack.get_int(2));
  17. return 0;
  18. }
  19. static int camera_projection_type(lua_State* L)
  20. {
  21. LuaStack stack(L);
  22. stack.push_uint32(stack.get_camera(1)->projection_type());
  23. return 1;
  24. }
  25. static int camera_fov(lua_State* L)
  26. {
  27. LuaStack stack(L);
  28. stack.push_float(stack.get_camera(1)->fov());
  29. return 1;
  30. }
  31. static int camera_set_fov(lua_State* L)
  32. {
  33. LuaStack stack(L);
  34. stack.get_camera(1)->set_fov(stack.get_float(2));
  35. return 0;
  36. }
  37. static int camera_aspect(lua_State* L)
  38. {
  39. LuaStack stack(L);
  40. stack.push_float(stack.get_camera(1)->aspect());
  41. return 1;
  42. }
  43. static int camera_set_aspect(lua_State* L)
  44. {
  45. LuaStack stack(L);
  46. stack.get_camera(1)->set_aspect(stack.get_float(2));
  47. return 0;
  48. }
  49. static int camera_near_clip_distance(lua_State* L)
  50. {
  51. LuaStack stack(L);
  52. stack.push_float(stack.get_camera(1)->near_clip_distance());
  53. return 1;
  54. }
  55. static int camera_set_near_clip_distance(lua_State* L)
  56. {
  57. LuaStack stack(L);
  58. stack.get_camera(1)->set_near_clip_distance(stack.get_float(2));
  59. return 0;
  60. }
  61. static int camera_far_clip_distance(lua_State* L)
  62. {
  63. LuaStack stack(L);
  64. stack.push_float(stack.get_camera(1)->far_clip_distance());
  65. return 1;
  66. }
  67. static int camera_set_far_clip_distance(lua_State* L)
  68. {
  69. LuaStack stack(L);
  70. stack.get_camera(1)->set_far_clip_distance(stack.get_float(2));
  71. return 0;
  72. }
  73. static int camera_set_orthographic_metrics(lua_State* L)
  74. {
  75. LuaStack stack(L);
  76. stack.get_camera(1)->set_orthographic_metrics(stack.get_float(2), stack.get_float(3),
  77. stack.get_float(4), stack.get_float(5));
  78. return 0;
  79. }
  80. static int camera_set_viewport_metrics(lua_State* L)
  81. {
  82. LuaStack stack(L);
  83. stack.get_camera(1)->set_viewport_metrics(stack.get_int(2), stack.get_int(3),
  84. stack.get_int(4), stack.get_int(5));
  85. return 0;
  86. }
  87. static int camera_screen_to_world(lua_State* L)
  88. {
  89. LuaStack stack(L);
  90. stack.push_vector3(stack.get_camera(1)->screen_to_world(stack.get_vector3(2)));
  91. return 1;
  92. }
  93. static int camera_world_to_screen(lua_State* L)
  94. {
  95. LuaStack stack(L);
  96. stack.push_vector3(stack.get_camera(1)->world_to_screen(stack.get_vector3(2)));
  97. return 1;
  98. }
  99. void load_camera(LuaEnvironment& env)
  100. {
  101. env.load_module_function("Camera", "set_projection_type", camera_set_projection_type);
  102. env.load_module_function("Camera", "projection_type", camera_projection_type);
  103. env.load_module_function("Camera", "fov", camera_fov);
  104. env.load_module_function("Camera", "set_fov", camera_set_fov);
  105. env.load_module_function("Camera", "aspect", camera_aspect);
  106. env.load_module_function("Camera", "set_aspect", camera_set_aspect);
  107. env.load_module_function("Camera", "near_clip_distance", camera_near_clip_distance);
  108. env.load_module_function("Camera", "set_near_clip_distance", camera_set_near_clip_distance);
  109. env.load_module_function("Camera", "far_clip_distance", camera_far_clip_distance);
  110. env.load_module_function("Camera", "set_far_clip_distance", camera_set_far_clip_distance);
  111. env.load_module_function("Camera", "set_orthographic_metrics", camera_set_orthographic_metrics);
  112. env.load_module_function("Camera", "set_viewport_metrics", camera_set_viewport_metrics);
  113. env.load_module_function("Camera", "screen_to_world", camera_screen_to_world);
  114. env.load_module_function("Camera", "world_to_screen", camera_world_to_screen);
  115. env.load_module_enum("Camera", "ORTHOGRAPHIC", ProjectionType::ORTHOGRAPHIC);
  116. env.load_module_enum("Camera", "PERSPECTIVE", ProjectionType::PERSPECTIVE);
  117. }
  118. } // namespace crown