lua_PhysicsSocketConstraint.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  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. const luaL_Reg lua_members[] =
  15. {
  16. {"getBreakingImpulse", lua_PhysicsSocketConstraint_getBreakingImpulse},
  17. {"isEnabled", lua_PhysicsSocketConstraint_isEnabled},
  18. {"setBreakingImpulse", lua_PhysicsSocketConstraint_setBreakingImpulse},
  19. {"setEnabled", lua_PhysicsSocketConstraint_setEnabled},
  20. {NULL, NULL}
  21. };
  22. const luaL_Reg lua_statics[] =
  23. {
  24. {"centerOfMassMidpoint", lua_PhysicsSocketConstraint_static_centerOfMassMidpoint},
  25. {"getRotationOffset", lua_PhysicsSocketConstraint_static_getRotationOffset},
  26. {"getTranslationOffset", lua_PhysicsSocketConstraint_static_getTranslationOffset},
  27. {NULL, NULL}
  28. };
  29. std::vector<std::string> scopePath;
  30. gameplay::ScriptUtil::registerClass("PhysicsSocketConstraint", lua_members, NULL, NULL, lua_statics, scopePath);
  31. }
  32. static PhysicsSocketConstraint* getInstance(lua_State* state)
  33. {
  34. void* userdata = luaL_checkudata(state, 1, "PhysicsSocketConstraint");
  35. luaL_argcheck(state, userdata != NULL, 1, "'PhysicsSocketConstraint' expected.");
  36. return (PhysicsSocketConstraint*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
  37. }
  38. int lua_PhysicsSocketConstraint_getBreakingImpulse(lua_State* state)
  39. {
  40. // Get the number of parameters.
  41. int paramCount = lua_gettop(state);
  42. // Attempt to match the parameters to a valid binding.
  43. switch (paramCount)
  44. {
  45. case 1:
  46. {
  47. if ((lua_type(state, 1) == LUA_TUSERDATA))
  48. {
  49. PhysicsSocketConstraint* instance = getInstance(state);
  50. float result = instance->getBreakingImpulse();
  51. // Push the return value onto the stack.
  52. lua_pushnumber(state, result);
  53. return 1;
  54. }
  55. lua_pushstring(state, "lua_PhysicsSocketConstraint_getBreakingImpulse - Failed to match the given parameters to a valid function signature.");
  56. lua_error(state);
  57. break;
  58. }
  59. default:
  60. {
  61. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  62. lua_error(state);
  63. break;
  64. }
  65. }
  66. return 0;
  67. }
  68. int lua_PhysicsSocketConstraint_isEnabled(lua_State* state)
  69. {
  70. // Get the number of parameters.
  71. int paramCount = lua_gettop(state);
  72. // Attempt to match the parameters to a valid binding.
  73. switch (paramCount)
  74. {
  75. case 1:
  76. {
  77. if ((lua_type(state, 1) == LUA_TUSERDATA))
  78. {
  79. PhysicsSocketConstraint* instance = getInstance(state);
  80. bool result = instance->isEnabled();
  81. // Push the return value onto the stack.
  82. lua_pushboolean(state, result);
  83. return 1;
  84. }
  85. lua_pushstring(state, "lua_PhysicsSocketConstraint_isEnabled - Failed to match the given parameters to a valid function signature.");
  86. lua_error(state);
  87. break;
  88. }
  89. default:
  90. {
  91. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  92. lua_error(state);
  93. break;
  94. }
  95. }
  96. return 0;
  97. }
  98. int lua_PhysicsSocketConstraint_setBreakingImpulse(lua_State* state)
  99. {
  100. // Get the number of parameters.
  101. int paramCount = lua_gettop(state);
  102. // Attempt to match the parameters to a valid binding.
  103. switch (paramCount)
  104. {
  105. case 2:
  106. {
  107. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  108. lua_type(state, 2) == LUA_TNUMBER)
  109. {
  110. // Get parameter 1 off the stack.
  111. float param1 = (float)luaL_checknumber(state, 2);
  112. PhysicsSocketConstraint* instance = getInstance(state);
  113. instance->setBreakingImpulse(param1);
  114. return 0;
  115. }
  116. lua_pushstring(state, "lua_PhysicsSocketConstraint_setBreakingImpulse - Failed to match the given parameters to a valid function signature.");
  117. lua_error(state);
  118. break;
  119. }
  120. default:
  121. {
  122. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  123. lua_error(state);
  124. break;
  125. }
  126. }
  127. return 0;
  128. }
  129. int lua_PhysicsSocketConstraint_setEnabled(lua_State* state)
  130. {
  131. // Get the number of parameters.
  132. int paramCount = lua_gettop(state);
  133. // Attempt to match the parameters to a valid binding.
  134. switch (paramCount)
  135. {
  136. case 2:
  137. {
  138. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  139. lua_type(state, 2) == LUA_TBOOLEAN)
  140. {
  141. // Get parameter 1 off the stack.
  142. bool param1 = gameplay::ScriptUtil::luaCheckBool(state, 2);
  143. PhysicsSocketConstraint* instance = getInstance(state);
  144. instance->setEnabled(param1);
  145. return 0;
  146. }
  147. lua_pushstring(state, "lua_PhysicsSocketConstraint_setEnabled - Failed to match the given parameters to a valid function signature.");
  148. lua_error(state);
  149. break;
  150. }
  151. default:
  152. {
  153. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  154. lua_error(state);
  155. break;
  156. }
  157. }
  158. return 0;
  159. }
  160. int lua_PhysicsSocketConstraint_static_centerOfMassMidpoint(lua_State* state)
  161. {
  162. // Get the number of parameters.
  163. int paramCount = lua_gettop(state);
  164. // Attempt to match the parameters to a valid binding.
  165. switch (paramCount)
  166. {
  167. case 2:
  168. {
  169. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TTABLE || lua_type(state, 1) == LUA_TNIL) &&
  170. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL))
  171. {
  172. // Get parameter 1 off the stack.
  173. bool param1Valid;
  174. gameplay::ScriptUtil::LuaArray<Node> param1 = gameplay::ScriptUtil::getObjectPointer<Node>(1, "Node", false, &param1Valid);
  175. if (!param1Valid)
  176. {
  177. lua_pushstring(state, "Failed to convert parameter 1 to type 'Node'.");
  178. lua_error(state);
  179. }
  180. // Get parameter 2 off the stack.
  181. bool param2Valid;
  182. gameplay::ScriptUtil::LuaArray<Node> param2 = gameplay::ScriptUtil::getObjectPointer<Node>(2, "Node", false, &param2Valid);
  183. if (!param2Valid)
  184. {
  185. lua_pushstring(state, "Failed to convert parameter 2 to type 'Node'.");
  186. lua_error(state);
  187. }
  188. void* returnPtr = (void*)new Vector3(PhysicsSocketConstraint::centerOfMassMidpoint(param1, param2));
  189. if (returnPtr)
  190. {
  191. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  192. object->instance = returnPtr;
  193. object->owns = true;
  194. luaL_getmetatable(state, "Vector3");
  195. lua_setmetatable(state, -2);
  196. }
  197. else
  198. {
  199. lua_pushnil(state);
  200. }
  201. return 1;
  202. }
  203. lua_pushstring(state, "lua_PhysicsSocketConstraint_static_centerOfMassMidpoint - 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 2).");
  210. lua_error(state);
  211. break;
  212. }
  213. }
  214. return 0;
  215. }
  216. int lua_PhysicsSocketConstraint_static_getRotationOffset(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_TNIL))
  227. {
  228. // Get parameter 1 off the stack.
  229. bool param1Valid;
  230. gameplay::ScriptUtil::LuaArray<Node> param1 = gameplay::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. gameplay::ScriptUtil::LuaArray<Vector3> param2 = gameplay::ScriptUtil::getObjectPointer<Vector3>(2, "Vector3", true, &param2Valid);
  239. if (!param2Valid)
  240. {
  241. lua_pushstring(state, "Failed to convert parameter 2 to type 'Vector3'.");
  242. lua_error(state);
  243. }
  244. void* returnPtr = (void*)new Quaternion(PhysicsSocketConstraint::getRotationOffset(param1, *param2));
  245. if (returnPtr)
  246. {
  247. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  248. object->instance = returnPtr;
  249. object->owns = true;
  250. luaL_getmetatable(state, "Quaternion");
  251. lua_setmetatable(state, -2);
  252. }
  253. else
  254. {
  255. lua_pushnil(state);
  256. }
  257. return 1;
  258. }
  259. lua_pushstring(state, "lua_PhysicsSocketConstraint_static_getRotationOffset - 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_PhysicsSocketConstraint_static_getTranslationOffset(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. gameplay::ScriptUtil::LuaArray<Node> param1 = gameplay::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. gameplay::ScriptUtil::LuaArray<Vector3> param2 = gameplay::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 Vector3(PhysicsSocketConstraint::getTranslationOffset(param1, *param2));
  301. if (returnPtr)
  302. {
  303. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  304. object->instance = returnPtr;
  305. object->owns = true;
  306. luaL_getmetatable(state, "Vector3");
  307. lua_setmetatable(state, -2);
  308. }
  309. else
  310. {
  311. lua_pushnil(state);
  312. }
  313. return 1;
  314. }
  315. lua_pushstring(state, "lua_PhysicsSocketConstraint_static_getTranslationOffset - 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. }