lua_PhysicsHingeConstraint.cpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. #include "Base.h"
  2. #include "ScriptController.h"
  3. #include "lua_PhysicsHingeConstraint.h"
  4. #include "Base.h"
  5. #include "Game.h"
  6. #include "Node.h"
  7. #include "PhysicsConstraint.h"
  8. #include "PhysicsHingeConstraint.h"
  9. #include "PhysicsRigidBody.h"
  10. namespace gameplay
  11. {
  12. void luaRegister_PhysicsHingeConstraint()
  13. {
  14. const luaL_Reg lua_members[] =
  15. {
  16. {"getBreakingImpulse", lua_PhysicsHingeConstraint_getBreakingImpulse},
  17. {"isEnabled", lua_PhysicsHingeConstraint_isEnabled},
  18. {"setBreakingImpulse", lua_PhysicsHingeConstraint_setBreakingImpulse},
  19. {"setEnabled", lua_PhysicsHingeConstraint_setEnabled},
  20. {"setLimits", lua_PhysicsHingeConstraint_setLimits},
  21. {NULL, NULL}
  22. };
  23. const luaL_Reg lua_statics[] =
  24. {
  25. {"centerOfMassMidpoint", lua_PhysicsHingeConstraint_static_centerOfMassMidpoint},
  26. {"getRotationOffset", lua_PhysicsHingeConstraint_static_getRotationOffset},
  27. {"getTranslationOffset", lua_PhysicsHingeConstraint_static_getTranslationOffset},
  28. {NULL, NULL}
  29. };
  30. std::vector<std::string> scopePath;
  31. ScriptUtil::registerClass("PhysicsHingeConstraint", lua_members, NULL, NULL, lua_statics, scopePath);
  32. }
  33. static PhysicsHingeConstraint* getInstance(lua_State* state)
  34. {
  35. void* userdata = luaL_checkudata(state, 1, "PhysicsHingeConstraint");
  36. luaL_argcheck(state, userdata != NULL, 1, "'PhysicsHingeConstraint' expected.");
  37. return (PhysicsHingeConstraint*)((ScriptUtil::LuaObject*)userdata)->instance;
  38. }
  39. int lua_PhysicsHingeConstraint_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. PhysicsHingeConstraint* 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_PhysicsHingeConstraint_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_PhysicsHingeConstraint_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. PhysicsHingeConstraint* 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_PhysicsHingeConstraint_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_PhysicsHingeConstraint_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. PhysicsHingeConstraint* instance = getInstance(state);
  120. instance->setBreakingImpulse(param1);
  121. return 0;
  122. }
  123. else
  124. {
  125. lua_pushstring(state, "lua_PhysicsHingeConstraint_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_PhysicsHingeConstraint_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 = ScriptUtil::luaCheckBool(state, 2);
  153. PhysicsHingeConstraint* instance = getInstance(state);
  154. instance->setEnabled(param1);
  155. return 0;
  156. }
  157. else
  158. {
  159. lua_pushstring(state, "lua_PhysicsHingeConstraint_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_PhysicsHingeConstraint_setLimits(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 3:
  181. {
  182. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  183. lua_type(state, 2) == LUA_TNUMBER &&
  184. lua_type(state, 3) == LUA_TNUMBER)
  185. {
  186. // Get parameter 1 off the stack.
  187. float param1 = (float)luaL_checknumber(state, 2);
  188. // Get parameter 2 off the stack.
  189. float param2 = (float)luaL_checknumber(state, 3);
  190. PhysicsHingeConstraint* instance = getInstance(state);
  191. instance->setLimits(param1, param2);
  192. return 0;
  193. }
  194. else
  195. {
  196. lua_pushstring(state, "lua_PhysicsHingeConstraint_setLimits - Failed to match the given parameters to a valid function signature.");
  197. lua_error(state);
  198. }
  199. break;
  200. }
  201. case 4:
  202. {
  203. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  204. lua_type(state, 2) == LUA_TNUMBER &&
  205. lua_type(state, 3) == LUA_TNUMBER &&
  206. lua_type(state, 4) == LUA_TNUMBER)
  207. {
  208. // Get parameter 1 off the stack.
  209. float param1 = (float)luaL_checknumber(state, 2);
  210. // Get parameter 2 off the stack.
  211. float param2 = (float)luaL_checknumber(state, 3);
  212. // Get parameter 3 off the stack.
  213. float param3 = (float)luaL_checknumber(state, 4);
  214. PhysicsHingeConstraint* instance = getInstance(state);
  215. instance->setLimits(param1, param2, param3);
  216. return 0;
  217. }
  218. else
  219. {
  220. lua_pushstring(state, "lua_PhysicsHingeConstraint_setLimits - Failed to match the given parameters to a valid function signature.");
  221. lua_error(state);
  222. }
  223. break;
  224. }
  225. default:
  226. {
  227. lua_pushstring(state, "Invalid number of parameters (expected 3 or 4).");
  228. lua_error(state);
  229. break;
  230. }
  231. }
  232. return 0;
  233. }
  234. int lua_PhysicsHingeConstraint_static_centerOfMassMidpoint(lua_State* state)
  235. {
  236. // Get the number of parameters.
  237. int paramCount = lua_gettop(state);
  238. // Attempt to match the parameters to a valid binding.
  239. switch (paramCount)
  240. {
  241. case 2:
  242. {
  243. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TTABLE || lua_type(state, 1) == LUA_TNIL) &&
  244. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL))
  245. {
  246. // Get parameter 1 off the stack.
  247. ScriptUtil::LuaArray<Node> param1 = ScriptUtil::getObjectPointer<Node>(1, "Node", false);
  248. // Get parameter 2 off the stack.
  249. ScriptUtil::LuaArray<Node> param2 = ScriptUtil::getObjectPointer<Node>(2, "Node", false);
  250. void* returnPtr = (void*)new Vector3(PhysicsHingeConstraint::centerOfMassMidpoint(param1, param2));
  251. if (returnPtr)
  252. {
  253. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  254. object->instance = returnPtr;
  255. object->owns = true;
  256. luaL_getmetatable(state, "Vector3");
  257. lua_setmetatable(state, -2);
  258. }
  259. else
  260. {
  261. lua_pushnil(state);
  262. }
  263. return 1;
  264. }
  265. else
  266. {
  267. lua_pushstring(state, "lua_PhysicsHingeConstraint_static_centerOfMassMidpoint - Failed to match the given parameters to a valid function signature.");
  268. lua_error(state);
  269. }
  270. break;
  271. }
  272. default:
  273. {
  274. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  275. lua_error(state);
  276. break;
  277. }
  278. }
  279. return 0;
  280. }
  281. int lua_PhysicsHingeConstraint_static_getRotationOffset(lua_State* state)
  282. {
  283. // Get the number of parameters.
  284. int paramCount = lua_gettop(state);
  285. // Attempt to match the parameters to a valid binding.
  286. switch (paramCount)
  287. {
  288. case 2:
  289. {
  290. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TTABLE || lua_type(state, 1) == LUA_TNIL) &&
  291. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
  292. {
  293. // Get parameter 1 off the stack.
  294. ScriptUtil::LuaArray<Node> param1 = ScriptUtil::getObjectPointer<Node>(1, "Node", false);
  295. // Get parameter 2 off the stack.
  296. ScriptUtil::LuaArray<Vector3> param2 = ScriptUtil::getObjectPointer<Vector3>(2, "Vector3", true);
  297. void* returnPtr = (void*)new Quaternion(PhysicsHingeConstraint::getRotationOffset(param1, *param2));
  298. if (returnPtr)
  299. {
  300. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  301. object->instance = returnPtr;
  302. object->owns = true;
  303. luaL_getmetatable(state, "Quaternion");
  304. lua_setmetatable(state, -2);
  305. }
  306. else
  307. {
  308. lua_pushnil(state);
  309. }
  310. return 1;
  311. }
  312. else
  313. {
  314. lua_pushstring(state, "lua_PhysicsHingeConstraint_static_getRotationOffset - Failed to match the given parameters to a valid function signature.");
  315. lua_error(state);
  316. }
  317. break;
  318. }
  319. default:
  320. {
  321. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  322. lua_error(state);
  323. break;
  324. }
  325. }
  326. return 0;
  327. }
  328. int lua_PhysicsHingeConstraint_static_getTranslationOffset(lua_State* state)
  329. {
  330. // Get the number of parameters.
  331. int paramCount = lua_gettop(state);
  332. // Attempt to match the parameters to a valid binding.
  333. switch (paramCount)
  334. {
  335. case 2:
  336. {
  337. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TTABLE || lua_type(state, 1) == LUA_TNIL) &&
  338. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
  339. {
  340. // Get parameter 1 off the stack.
  341. ScriptUtil::LuaArray<Node> param1 = ScriptUtil::getObjectPointer<Node>(1, "Node", false);
  342. // Get parameter 2 off the stack.
  343. ScriptUtil::LuaArray<Vector3> param2 = ScriptUtil::getObjectPointer<Vector3>(2, "Vector3", true);
  344. void* returnPtr = (void*)new Vector3(PhysicsHingeConstraint::getTranslationOffset(param1, *param2));
  345. if (returnPtr)
  346. {
  347. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  348. object->instance = returnPtr;
  349. object->owns = true;
  350. luaL_getmetatable(state, "Vector3");
  351. lua_setmetatable(state, -2);
  352. }
  353. else
  354. {
  355. lua_pushnil(state);
  356. }
  357. return 1;
  358. }
  359. else
  360. {
  361. lua_pushstring(state, "lua_PhysicsHingeConstraint_static_getTranslationOffset - Failed to match the given parameters to a valid function signature.");
  362. lua_error(state);
  363. }
  364. break;
  365. }
  366. default:
  367. {
  368. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  369. lua_error(state);
  370. break;
  371. }
  372. }
  373. return 0;
  374. }
  375. }