lua_PhysicsSocketConstraint.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. #include "Base.h"
  2. #include "ScriptController.h"
  3. #include "lua_PhysicsSocketConstraint.h"
  4. #include "Base.h"
  5. #include "Game.h"
  6. #include "Node.h"
  7. #include "PhysicsConstraint.h"
  8. #include "PhysicsRigidBody.h"
  9. #include "PhysicsSocketConstraint.h"
  10. namespace gameplay
  11. {
  12. void luaRegister_PhysicsSocketConstraint()
  13. {
  14. ScriptController* sc = ScriptController::getInstance();
  15. const luaL_Reg lua_members[] =
  16. {
  17. {"getBreakingImpulse", lua_PhysicsSocketConstraint_getBreakingImpulse},
  18. {"isEnabled", lua_PhysicsSocketConstraint_isEnabled},
  19. {"setBreakingImpulse", lua_PhysicsSocketConstraint_setBreakingImpulse},
  20. {"setEnabled", lua_PhysicsSocketConstraint_setEnabled},
  21. {NULL, NULL}
  22. };
  23. const luaL_Reg lua_statics[] =
  24. {
  25. {"centerOfMassMidpoint", lua_PhysicsSocketConstraint_static_centerOfMassMidpoint},
  26. {"getRotationOffset", lua_PhysicsSocketConstraint_static_getRotationOffset},
  27. {"getTranslationOffset", lua_PhysicsSocketConstraint_static_getTranslationOffset},
  28. {NULL, NULL}
  29. };
  30. std::vector<std::string> scopePath;
  31. sc->registerClass("PhysicsSocketConstraint", lua_members, NULL, NULL, lua_statics, scopePath);
  32. }
  33. static PhysicsSocketConstraint* getInstance(lua_State* state)
  34. {
  35. void* userdata = luaL_checkudata(state, 1, "PhysicsSocketConstraint");
  36. luaL_argcheck(state, userdata != NULL, 1, "'PhysicsSocketConstraint' expected.");
  37. return (PhysicsSocketConstraint*)((ScriptController::LuaObject*)userdata)->instance;
  38. }
  39. int lua_PhysicsSocketConstraint_getBreakingImpulse(lua_State* state)
  40. {
  41. // Get the number of parameters.
  42. int paramCount = lua_gettop(state);
  43. // Attempt to match the parameters to a valid binding.
  44. switch (paramCount)
  45. {
  46. case 1:
  47. {
  48. if ((lua_type(state, 1) == LUA_TUSERDATA))
  49. {
  50. PhysicsSocketConstraint* instance = getInstance(state);
  51. float result = instance->getBreakingImpulse();
  52. // Push the return value onto the stack.
  53. lua_pushnumber(state, result);
  54. return 1;
  55. }
  56. else
  57. {
  58. lua_pushstring(state, "lua_PhysicsSocketConstraint_getBreakingImpulse - Failed to match the given parameters to a valid function signature.");
  59. lua_error(state);
  60. }
  61. break;
  62. }
  63. default:
  64. {
  65. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  66. lua_error(state);
  67. break;
  68. }
  69. }
  70. return 0;
  71. }
  72. int lua_PhysicsSocketConstraint_isEnabled(lua_State* state)
  73. {
  74. // Get the number of parameters.
  75. int paramCount = lua_gettop(state);
  76. // Attempt to match the parameters to a valid binding.
  77. switch (paramCount)
  78. {
  79. case 1:
  80. {
  81. if ((lua_type(state, 1) == LUA_TUSERDATA))
  82. {
  83. PhysicsSocketConstraint* instance = getInstance(state);
  84. bool result = instance->isEnabled();
  85. // Push the return value onto the stack.
  86. lua_pushboolean(state, result);
  87. return 1;
  88. }
  89. else
  90. {
  91. lua_pushstring(state, "lua_PhysicsSocketConstraint_isEnabled - Failed to match the given parameters to a valid function signature.");
  92. lua_error(state);
  93. }
  94. break;
  95. }
  96. default:
  97. {
  98. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  99. lua_error(state);
  100. break;
  101. }
  102. }
  103. return 0;
  104. }
  105. int lua_PhysicsSocketConstraint_setBreakingImpulse(lua_State* state)
  106. {
  107. // Get the number of parameters.
  108. int paramCount = lua_gettop(state);
  109. // Attempt to match the parameters to a valid binding.
  110. switch (paramCount)
  111. {
  112. case 2:
  113. {
  114. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  115. lua_type(state, 2) == LUA_TNUMBER)
  116. {
  117. // Get parameter 1 off the stack.
  118. float param1 = (float)luaL_checknumber(state, 2);
  119. PhysicsSocketConstraint* instance = getInstance(state);
  120. instance->setBreakingImpulse(param1);
  121. return 0;
  122. }
  123. else
  124. {
  125. lua_pushstring(state, "lua_PhysicsSocketConstraint_setBreakingImpulse - Failed to match the given parameters to a valid function signature.");
  126. lua_error(state);
  127. }
  128. break;
  129. }
  130. default:
  131. {
  132. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  133. lua_error(state);
  134. break;
  135. }
  136. }
  137. return 0;
  138. }
  139. int lua_PhysicsSocketConstraint_setEnabled(lua_State* state)
  140. {
  141. // Get the number of parameters.
  142. int paramCount = lua_gettop(state);
  143. // Attempt to match the parameters to a valid binding.
  144. switch (paramCount)
  145. {
  146. case 2:
  147. {
  148. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  149. lua_type(state, 2) == LUA_TBOOLEAN)
  150. {
  151. // Get parameter 1 off the stack.
  152. bool param1 = ScriptController::luaCheckBool(state, 2);
  153. PhysicsSocketConstraint* instance = getInstance(state);
  154. instance->setEnabled(param1);
  155. return 0;
  156. }
  157. else
  158. {
  159. lua_pushstring(state, "lua_PhysicsSocketConstraint_setEnabled - Failed to match the given parameters to a valid function signature.");
  160. lua_error(state);
  161. }
  162. break;
  163. }
  164. default:
  165. {
  166. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  167. lua_error(state);
  168. break;
  169. }
  170. }
  171. return 0;
  172. }
  173. int lua_PhysicsSocketConstraint_static_centerOfMassMidpoint(lua_State* state)
  174. {
  175. // Get the number of parameters.
  176. int paramCount = lua_gettop(state);
  177. // Attempt to match the parameters to a valid binding.
  178. switch (paramCount)
  179. {
  180. case 2:
  181. {
  182. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TTABLE || lua_type(state, 1) == LUA_TNIL) &&
  183. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL))
  184. {
  185. // Get parameter 1 off the stack.
  186. Node* param1 = ScriptController::getInstance()->getObjectPointer<Node>(1, "Node", false);
  187. // Get parameter 2 off the stack.
  188. Node* param2 = ScriptController::getInstance()->getObjectPointer<Node>(2, "Node", false);
  189. void* returnPtr = (void*)new Vector3(PhysicsSocketConstraint::centerOfMassMidpoint(param1, param2));
  190. if (returnPtr)
  191. {
  192. ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
  193. object->instance = returnPtr;
  194. object->owns = true;
  195. luaL_getmetatable(state, "Vector3");
  196. lua_setmetatable(state, -2);
  197. }
  198. else
  199. {
  200. lua_pushnil(state);
  201. }
  202. return 1;
  203. }
  204. else
  205. {
  206. lua_pushstring(state, "lua_PhysicsSocketConstraint_static_centerOfMassMidpoint - Failed to match the given parameters to a valid function signature.");
  207. lua_error(state);
  208. }
  209. break;
  210. }
  211. default:
  212. {
  213. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  214. lua_error(state);
  215. break;
  216. }
  217. }
  218. return 0;
  219. }
  220. int lua_PhysicsSocketConstraint_static_getRotationOffset(lua_State* state)
  221. {
  222. // Get the number of parameters.
  223. int paramCount = lua_gettop(state);
  224. // Attempt to match the parameters to a valid binding.
  225. switch (paramCount)
  226. {
  227. case 2:
  228. {
  229. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TTABLE || lua_type(state, 1) == LUA_TNIL) &&
  230. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
  231. {
  232. // Get parameter 1 off the stack.
  233. Node* param1 = ScriptController::getInstance()->getObjectPointer<Node>(1, "Node", false);
  234. // Get parameter 2 off the stack.
  235. Vector3* param2 = ScriptController::getInstance()->getObjectPointer<Vector3>(2, "Vector3", true);
  236. void* returnPtr = (void*)new Quaternion(PhysicsSocketConstraint::getRotationOffset(param1, *param2));
  237. if (returnPtr)
  238. {
  239. ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
  240. object->instance = returnPtr;
  241. object->owns = true;
  242. luaL_getmetatable(state, "Quaternion");
  243. lua_setmetatable(state, -2);
  244. }
  245. else
  246. {
  247. lua_pushnil(state);
  248. }
  249. return 1;
  250. }
  251. else
  252. {
  253. lua_pushstring(state, "lua_PhysicsSocketConstraint_static_getRotationOffset - Failed to match the given parameters to a valid function signature.");
  254. lua_error(state);
  255. }
  256. break;
  257. }
  258. default:
  259. {
  260. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  261. lua_error(state);
  262. break;
  263. }
  264. }
  265. return 0;
  266. }
  267. int lua_PhysicsSocketConstraint_static_getTranslationOffset(lua_State* state)
  268. {
  269. // Get the number of parameters.
  270. int paramCount = lua_gettop(state);
  271. // Attempt to match the parameters to a valid binding.
  272. switch (paramCount)
  273. {
  274. case 2:
  275. {
  276. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TTABLE || lua_type(state, 1) == LUA_TNIL) &&
  277. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
  278. {
  279. // Get parameter 1 off the stack.
  280. Node* param1 = ScriptController::getInstance()->getObjectPointer<Node>(1, "Node", false);
  281. // Get parameter 2 off the stack.
  282. Vector3* param2 = ScriptController::getInstance()->getObjectPointer<Vector3>(2, "Vector3", true);
  283. void* returnPtr = (void*)new Vector3(PhysicsSocketConstraint::getTranslationOffset(param1, *param2));
  284. if (returnPtr)
  285. {
  286. ScriptController::LuaObject* object = (ScriptController::LuaObject*)lua_newuserdata(state, sizeof(ScriptController::LuaObject));
  287. object->instance = returnPtr;
  288. object->owns = true;
  289. luaL_getmetatable(state, "Vector3");
  290. lua_setmetatable(state, -2);
  291. }
  292. else
  293. {
  294. lua_pushnil(state);
  295. }
  296. return 1;
  297. }
  298. else
  299. {
  300. lua_pushstring(state, "lua_PhysicsSocketConstraint_static_getTranslationOffset - Failed to match the given parameters to a valid function signature.");
  301. lua_error(state);
  302. }
  303. break;
  304. }
  305. default:
  306. {
  307. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  308. lua_error(state);
  309. break;
  310. }
  311. }
  312. return 0;
  313. }
  314. }