2
0

LuaCamera.cpp 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. /*
  2. Copyright (c) 2013 Daniele Bartolini, Michele Rossi
  3. Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
  4. Permission is hereby granted, free of charge, to any person
  5. obtaining a copy of this software and associated documentation
  6. files (the "Software"), to deal in the Software without
  7. restriction, including without limitation the rights to use,
  8. copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the
  10. Software is furnished to do so, subject to the following
  11. conditions:
  12. The above copyright notice and this permission notice shall be
  13. included in all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  16. OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  17. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  18. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  19. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  21. OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. #include "Camera.h"
  24. #include "Vector3.h"
  25. #include "Quaternion.h"
  26. #include "Matrix4x4.h"
  27. #include "LuaStack.h"
  28. #include "LuaEnvironment.h"
  29. namespace crown
  30. {
  31. //-----------------------------------------------------------------------------
  32. CE_EXPORT int camera_local_position(lua_State* L)
  33. {
  34. LuaStack stack(L);
  35. Camera* camera = stack.get_camera(1);
  36. stack.push_vector3(camera->local_position());
  37. return 1;
  38. }
  39. //-----------------------------------------------------------------------------
  40. CE_EXPORT int camera_local_rotation(lua_State* L)
  41. {
  42. LuaStack stack(L);
  43. Camera* camera = stack.get_camera(1);
  44. stack.push_quaternion(camera->local_rotation());
  45. return 1;
  46. }
  47. //-----------------------------------------------------------------------------
  48. CE_EXPORT int camera_local_pose(lua_State* L)
  49. {
  50. LuaStack stack(L);
  51. Camera* camera = stack.get_camera(1);
  52. stack.push_matrix4x4(camera->local_pose());
  53. return 1;
  54. }
  55. //-----------------------------------------------------------------------------
  56. CE_EXPORT int camera_world_position(lua_State* L)
  57. {
  58. LuaStack stack(L);
  59. Camera* camera = stack.get_camera(1);
  60. stack.push_vector3(camera->world_position());
  61. return 1;
  62. }
  63. //-----------------------------------------------------------------------------
  64. CE_EXPORT int camera_world_rotation(lua_State* L)
  65. {
  66. LuaStack stack(L);
  67. Camera* camera = stack.get_camera(1);
  68. stack.push_quaternion(camera->world_rotation());
  69. return 1;
  70. }
  71. //-----------------------------------------------------------------------------
  72. CE_EXPORT int camera_world_pose(lua_State* L)
  73. {
  74. LuaStack stack(L);
  75. Camera* camera = stack.get_camera(1);
  76. stack.push_matrix4x4(camera->world_pose());
  77. return 1;
  78. }
  79. //-----------------------------------------------------------------------------
  80. CE_EXPORT int camera_set_local_position(lua_State* L)
  81. {
  82. LuaStack stack(L);
  83. Camera* camera = stack.get_camera(1);
  84. const Vector3 pos = stack.get_vector3(2);
  85. camera->set_local_position(pos);
  86. return 0;
  87. }
  88. //-----------------------------------------------------------------------------
  89. CE_EXPORT int camera_set_local_rotation(lua_State* L)
  90. {
  91. LuaStack stack(L);
  92. Camera* camera = stack.get_camera(1);
  93. const Quaternion rot = stack.get_quaternion(2);
  94. camera->set_local_rotation(rot);
  95. return 0;
  96. }
  97. //-----------------------------------------------------------------------------
  98. CE_EXPORT int camera_set_local_pose(lua_State* L)
  99. {
  100. LuaStack stack(L);
  101. Camera* camera = stack.get_camera(1);
  102. const Matrix4x4 pose = stack.get_matrix4x4(2);
  103. camera->set_local_pose(pose);
  104. return 0;
  105. }
  106. //-----------------------------------------------------------------------------
  107. CE_EXPORT int camera_set_projection_type(lua_State* L)
  108. {
  109. LuaStack stack(L);
  110. Camera* camera = stack.get_camera(1);
  111. ProjectionType::Enum proj_type = (ProjectionType::Enum) stack.get_int(2);
  112. camera->set_projection_type(proj_type);
  113. return 0;
  114. }
  115. //-----------------------------------------------------------------------------
  116. CE_EXPORT int camera_projection_type(lua_State* L)
  117. {
  118. LuaStack stack(L);
  119. Camera* camera = stack.get_camera(1);
  120. stack.push_uint32(camera->projection_type());
  121. return 1;
  122. }
  123. //-----------------------------------------------------------------------------
  124. CE_EXPORT int camera_fov(lua_State* L)
  125. {
  126. LuaStack stack(L);
  127. Camera* camera = stack.get_camera(1);
  128. stack.push_float(camera->fov());
  129. return 1;
  130. }
  131. //-----------------------------------------------------------------------------
  132. CE_EXPORT int camera_set_fov(lua_State* L)
  133. {
  134. LuaStack stack(L);
  135. Camera* camera = stack.get_camera(1);
  136. const float fov = stack.get_float(2);
  137. camera->set_fov(fov);
  138. return 0;
  139. }
  140. //-----------------------------------------------------------------------------
  141. CE_EXPORT int camera_aspect(lua_State* L)
  142. {
  143. LuaStack stack(L);
  144. Camera* camera = stack.get_camera(1);
  145. stack.push_float(camera->aspect());
  146. return 1;
  147. }
  148. //-----------------------------------------------------------------------------
  149. CE_EXPORT int camera_set_aspect(lua_State* L)
  150. {
  151. LuaStack stack(L);
  152. Camera* camera = stack.get_camera(1);
  153. const float aspect = stack.get_float(2);
  154. camera->set_aspect(aspect);
  155. return 0;
  156. }
  157. //-----------------------------------------------------------------------------
  158. CE_EXPORT int camera_near_clip_distance(lua_State* L)
  159. {
  160. LuaStack stack(L);
  161. Camera* camera = stack.get_camera(1);
  162. stack.push_float(camera->near_clip_distance());
  163. return 1;
  164. }
  165. //-----------------------------------------------------------------------------
  166. CE_EXPORT int camera_set_near_clip_distance(lua_State* L)
  167. {
  168. LuaStack stack(L);
  169. Camera* camera = stack.get_camera(1);
  170. const float near = stack.get_float(2);
  171. camera->set_near_clip_distance(near);
  172. return 0;
  173. }
  174. //-----------------------------------------------------------------------------
  175. CE_EXPORT int camera_far_clip_distance(lua_State* L)
  176. {
  177. LuaStack stack(L);
  178. Camera* camera = stack.get_camera(1);
  179. stack.push_float(camera->far_clip_distance());
  180. return 1;
  181. }
  182. //-----------------------------------------------------------------------------
  183. CE_EXPORT int camera_set_far_clip_distance(lua_State* L)
  184. {
  185. LuaStack stack(L);
  186. Camera* camera = stack.get_camera(1);
  187. const float far = stack.get_float(2);
  188. camera->set_far_clip_distance(far);
  189. return 0;
  190. }
  191. //-----------------------------------------------------------------------------
  192. void load_camera(LuaEnvironment& env)
  193. {
  194. env.load_module_function("Camera", "local_position", camera_local_position);
  195. env.load_module_function("Camera", "local_rotation", camera_local_rotation);
  196. env.load_module_function("Camera", "local_pose", camera_local_pose);
  197. env.load_module_function("Camera", "world_position", camera_world_position);
  198. env.load_module_function("Camera", "world_rotation", camera_world_rotation);
  199. env.load_module_function("Camera", "world_pose", camera_world_pose);
  200. env.load_module_function("Camera", "set_local_position", camera_set_local_position);
  201. env.load_module_function("Camera", "set_local_rotation", camera_set_local_rotation);
  202. env.load_module_function("Camera", "set_local_pose", camera_set_local_pose);
  203. env.load_module_function("Camera", "set_projection_type", camera_set_projection_type);
  204. env.load_module_function("Camera", "projection_type", camera_projection_type);
  205. env.load_module_function("Camera", "fov", camera_fov);
  206. env.load_module_function("Camera", "set_fov", camera_set_fov);
  207. env.load_module_function("Camera", "aspect", camera_aspect);
  208. env.load_module_function("Camera", "set_aspect", camera_set_aspect);
  209. env.load_module_function("Camera", "near_clip_distance", camera_near_clip_distance);
  210. env.load_module_function("Camera", "set_near_clip_distance", camera_set_near_clip_distance);
  211. env.load_module_function("Camera", "far_clip_distance", camera_far_clip_distance);
  212. env.load_module_function("Camera", "set_far_clip_distance", camera_set_far_clip_distance);
  213. env.load_module_enum("Camera", "ORTHOGRAPHIC", ProjectionType::ORTHOGRAPHIC);
  214. env.load_module_enum("Camera", "PERSPECTIVE", ProjectionType::PERSPECTIVE);
  215. }
  216. } // namespace crown