lua_PhysicsHingeConstraint.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  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. lua_pushstring(state, "lua_PhysicsHingeConstraint_getBreakingImpulse - Failed to match the given parameters to a valid function signature.");
  57. lua_error(state);
  58. break;
  59. }
  60. default:
  61. {
  62. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  63. lua_error(state);
  64. break;
  65. }
  66. }
  67. return 0;
  68. }
  69. int lua_PhysicsHingeConstraint_isEnabled(lua_State* state)
  70. {
  71. // Get the number of parameters.
  72. int paramCount = lua_gettop(state);
  73. // Attempt to match the parameters to a valid binding.
  74. switch (paramCount)
  75. {
  76. case 1:
  77. {
  78. if ((lua_type(state, 1) == LUA_TUSERDATA))
  79. {
  80. PhysicsHingeConstraint* instance = getInstance(state);
  81. bool result = instance->isEnabled();
  82. // Push the return value onto the stack.
  83. lua_pushboolean(state, result);
  84. return 1;
  85. }
  86. lua_pushstring(state, "lua_PhysicsHingeConstraint_isEnabled - Failed to match the given parameters to a valid function signature.");
  87. lua_error(state);
  88. break;
  89. }
  90. default:
  91. {
  92. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  93. lua_error(state);
  94. break;
  95. }
  96. }
  97. return 0;
  98. }
  99. int lua_PhysicsHingeConstraint_setBreakingImpulse(lua_State* state)
  100. {
  101. // Get the number of parameters.
  102. int paramCount = lua_gettop(state);
  103. // Attempt to match the parameters to a valid binding.
  104. switch (paramCount)
  105. {
  106. case 2:
  107. {
  108. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  109. lua_type(state, 2) == LUA_TNUMBER)
  110. {
  111. // Get parameter 1 off the stack.
  112. float param1 = (float)luaL_checknumber(state, 2);
  113. PhysicsHingeConstraint* instance = getInstance(state);
  114. instance->setBreakingImpulse(param1);
  115. return 0;
  116. }
  117. lua_pushstring(state, "lua_PhysicsHingeConstraint_setBreakingImpulse - Failed to match the given parameters to a valid function signature.");
  118. lua_error(state);
  119. break;
  120. }
  121. default:
  122. {
  123. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  124. lua_error(state);
  125. break;
  126. }
  127. }
  128. return 0;
  129. }
  130. int lua_PhysicsHingeConstraint_setEnabled(lua_State* state)
  131. {
  132. // Get the number of parameters.
  133. int paramCount = lua_gettop(state);
  134. // Attempt to match the parameters to a valid binding.
  135. switch (paramCount)
  136. {
  137. case 2:
  138. {
  139. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  140. lua_type(state, 2) == LUA_TBOOLEAN)
  141. {
  142. // Get parameter 1 off the stack.
  143. bool param1 = ScriptUtil::luaCheckBool(state, 2);
  144. PhysicsHingeConstraint* instance = getInstance(state);
  145. instance->setEnabled(param1);
  146. return 0;
  147. }
  148. lua_pushstring(state, "lua_PhysicsHingeConstraint_setEnabled - Failed to match the given parameters to a valid function signature.");
  149. lua_error(state);
  150. break;
  151. }
  152. default:
  153. {
  154. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  155. lua_error(state);
  156. break;
  157. }
  158. }
  159. return 0;
  160. }
  161. int lua_PhysicsHingeConstraint_setLimits(lua_State* state)
  162. {
  163. // Get the number of parameters.
  164. int paramCount = lua_gettop(state);
  165. // Attempt to match the parameters to a valid binding.
  166. switch (paramCount)
  167. {
  168. case 3:
  169. {
  170. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  171. lua_type(state, 2) == LUA_TNUMBER &&
  172. lua_type(state, 3) == LUA_TNUMBER)
  173. {
  174. // Get parameter 1 off the stack.
  175. float param1 = (float)luaL_checknumber(state, 2);
  176. // Get parameter 2 off the stack.
  177. float param2 = (float)luaL_checknumber(state, 3);
  178. PhysicsHingeConstraint* instance = getInstance(state);
  179. instance->setLimits(param1, param2);
  180. return 0;
  181. }
  182. lua_pushstring(state, "lua_PhysicsHingeConstraint_setLimits - Failed to match the given parameters to a valid function signature.");
  183. lua_error(state);
  184. break;
  185. }
  186. case 4:
  187. {
  188. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  189. lua_type(state, 2) == LUA_TNUMBER &&
  190. lua_type(state, 3) == LUA_TNUMBER &&
  191. lua_type(state, 4) == LUA_TNUMBER)
  192. {
  193. // Get parameter 1 off the stack.
  194. float param1 = (float)luaL_checknumber(state, 2);
  195. // Get parameter 2 off the stack.
  196. float param2 = (float)luaL_checknumber(state, 3);
  197. // Get parameter 3 off the stack.
  198. float param3 = (float)luaL_checknumber(state, 4);
  199. PhysicsHingeConstraint* instance = getInstance(state);
  200. instance->setLimits(param1, param2, param3);
  201. return 0;
  202. }
  203. lua_pushstring(state, "lua_PhysicsHingeConstraint_setLimits - Failed to match the given parameters to a valid function signature.");
  204. lua_error(state);
  205. break;
  206. }
  207. default:
  208. {
  209. lua_pushstring(state, "Invalid number of parameters (expected 3 or 4).");
  210. lua_error(state);
  211. break;
  212. }
  213. }
  214. return 0;
  215. }
  216. int lua_PhysicsHingeConstraint_static_centerOfMassMidpoint(lua_State* state)
  217. {
  218. // Get the number of parameters.
  219. int paramCount = lua_gettop(state);
  220. // Attempt to match the parameters to a valid binding.
  221. switch (paramCount)
  222. {
  223. case 2:
  224. {
  225. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TTABLE || lua_type(state, 1) == LUA_TNIL) &&
  226. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL))
  227. {
  228. // Get parameter 1 off the stack.
  229. bool param1Valid;
  230. ScriptUtil::LuaArray<Node> param1 = ScriptUtil::getObjectPointer<Node>(1, "Node", false, &param1Valid);
  231. if (!param1Valid)
  232. {
  233. lua_pushstring(state, "Failed to convert parameter 1 to type 'Node'.");
  234. lua_error(state);
  235. }
  236. // Get parameter 2 off the stack.
  237. bool param2Valid;
  238. ScriptUtil::LuaArray<Node> param2 = ScriptUtil::getObjectPointer<Node>(2, "Node", false, &param2Valid);
  239. if (!param2Valid)
  240. {
  241. lua_pushstring(state, "Failed to convert parameter 2 to type 'Node'.");
  242. lua_error(state);
  243. }
  244. void* returnPtr = (void*)new Vector3(PhysicsHingeConstraint::centerOfMassMidpoint(param1, param2));
  245. if (returnPtr)
  246. {
  247. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  248. object->instance = returnPtr;
  249. object->owns = true;
  250. luaL_getmetatable(state, "Vector3");
  251. lua_setmetatable(state, -2);
  252. }
  253. else
  254. {
  255. lua_pushnil(state);
  256. }
  257. return 1;
  258. }
  259. lua_pushstring(state, "lua_PhysicsHingeConstraint_static_centerOfMassMidpoint - Failed to match the given parameters to a valid function signature.");
  260. lua_error(state);
  261. break;
  262. }
  263. default:
  264. {
  265. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  266. lua_error(state);
  267. break;
  268. }
  269. }
  270. return 0;
  271. }
  272. int lua_PhysicsHingeConstraint_static_getRotationOffset(lua_State* state)
  273. {
  274. // Get the number of parameters.
  275. int paramCount = lua_gettop(state);
  276. // Attempt to match the parameters to a valid binding.
  277. switch (paramCount)
  278. {
  279. case 2:
  280. {
  281. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TTABLE || lua_type(state, 1) == LUA_TNIL) &&
  282. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
  283. {
  284. // Get parameter 1 off the stack.
  285. bool param1Valid;
  286. ScriptUtil::LuaArray<Node> param1 = ScriptUtil::getObjectPointer<Node>(1, "Node", false, &param1Valid);
  287. if (!param1Valid)
  288. {
  289. lua_pushstring(state, "Failed to convert parameter 1 to type 'Node'.");
  290. lua_error(state);
  291. }
  292. // Get parameter 2 off the stack.
  293. bool param2Valid;
  294. ScriptUtil::LuaArray<Vector3> param2 = ScriptUtil::getObjectPointer<Vector3>(2, "Vector3", true, &param2Valid);
  295. if (!param2Valid)
  296. {
  297. lua_pushstring(state, "Failed to convert parameter 2 to type 'Vector3'.");
  298. lua_error(state);
  299. }
  300. void* returnPtr = (void*)new Quaternion(PhysicsHingeConstraint::getRotationOffset(param1, *param2));
  301. if (returnPtr)
  302. {
  303. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  304. object->instance = returnPtr;
  305. object->owns = true;
  306. luaL_getmetatable(state, "Quaternion");
  307. lua_setmetatable(state, -2);
  308. }
  309. else
  310. {
  311. lua_pushnil(state);
  312. }
  313. return 1;
  314. }
  315. lua_pushstring(state, "lua_PhysicsHingeConstraint_static_getRotationOffset - Failed to match the given parameters to a valid function signature.");
  316. lua_error(state);
  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. bool param1Valid;
  342. ScriptUtil::LuaArray<Node> param1 = ScriptUtil::getObjectPointer<Node>(1, "Node", false, &param1Valid);
  343. if (!param1Valid)
  344. {
  345. lua_pushstring(state, "Failed to convert parameter 1 to type 'Node'.");
  346. lua_error(state);
  347. }
  348. // Get parameter 2 off the stack.
  349. bool param2Valid;
  350. ScriptUtil::LuaArray<Vector3> param2 = ScriptUtil::getObjectPointer<Vector3>(2, "Vector3", true, &param2Valid);
  351. if (!param2Valid)
  352. {
  353. lua_pushstring(state, "Failed to convert parameter 2 to type 'Vector3'.");
  354. lua_error(state);
  355. }
  356. void* returnPtr = (void*)new Vector3(PhysicsHingeConstraint::getTranslationOffset(param1, *param2));
  357. if (returnPtr)
  358. {
  359. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  360. object->instance = returnPtr;
  361. object->owns = true;
  362. luaL_getmetatable(state, "Vector3");
  363. lua_setmetatable(state, -2);
  364. }
  365. else
  366. {
  367. lua_pushnil(state);
  368. }
  369. return 1;
  370. }
  371. lua_pushstring(state, "lua_PhysicsHingeConstraint_static_getTranslationOffset - Failed to match the given parameters to a valid function signature.");
  372. lua_error(state);
  373. break;
  374. }
  375. default:
  376. {
  377. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  378. lua_error(state);
  379. break;
  380. }
  381. }
  382. return 0;
  383. }
  384. }