lua_PhysicsConstraint.cpp 13 KB

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