lua_PhysicsConstraint.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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. 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*)((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. else
  55. {
  56. lua_pushstring(state, "lua_PhysicsConstraint_getBreakingImpulse - Failed to match the given parameters to a valid function signature.");
  57. lua_error(state);
  58. }
  59. break;
  60. }
  61. default:
  62. {
  63. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  64. lua_error(state);
  65. break;
  66. }
  67. }
  68. return 0;
  69. }
  70. int lua_PhysicsConstraint_isEnabled(lua_State* state)
  71. {
  72. // Get the number of parameters.
  73. int paramCount = lua_gettop(state);
  74. // Attempt to match the parameters to a valid binding.
  75. switch (paramCount)
  76. {
  77. case 1:
  78. {
  79. if ((lua_type(state, 1) == LUA_TUSERDATA))
  80. {
  81. PhysicsConstraint* instance = getInstance(state);
  82. bool result = instance->isEnabled();
  83. // Push the return value onto the stack.
  84. lua_pushboolean(state, result);
  85. return 1;
  86. }
  87. else
  88. {
  89. lua_pushstring(state, "lua_PhysicsConstraint_isEnabled - Failed to match the given parameters to a valid function signature.");
  90. lua_error(state);
  91. }
  92. break;
  93. }
  94. default:
  95. {
  96. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  97. lua_error(state);
  98. break;
  99. }
  100. }
  101. return 0;
  102. }
  103. int lua_PhysicsConstraint_setBreakingImpulse(lua_State* state)
  104. {
  105. // Get the number of parameters.
  106. int paramCount = lua_gettop(state);
  107. // Attempt to match the parameters to a valid binding.
  108. switch (paramCount)
  109. {
  110. case 2:
  111. {
  112. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  113. lua_type(state, 2) == LUA_TNUMBER)
  114. {
  115. // Get parameter 1 off the stack.
  116. float param1 = (float)luaL_checknumber(state, 2);
  117. PhysicsConstraint* instance = getInstance(state);
  118. instance->setBreakingImpulse(param1);
  119. return 0;
  120. }
  121. else
  122. {
  123. lua_pushstring(state, "lua_PhysicsConstraint_setBreakingImpulse - Failed to match the given parameters to a valid function signature.");
  124. lua_error(state);
  125. }
  126. break;
  127. }
  128. default:
  129. {
  130. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  131. lua_error(state);
  132. break;
  133. }
  134. }
  135. return 0;
  136. }
  137. int lua_PhysicsConstraint_setEnabled(lua_State* state)
  138. {
  139. // Get the number of parameters.
  140. int paramCount = lua_gettop(state);
  141. // Attempt to match the parameters to a valid binding.
  142. switch (paramCount)
  143. {
  144. case 2:
  145. {
  146. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  147. lua_type(state, 2) == LUA_TBOOLEAN)
  148. {
  149. // Get parameter 1 off the stack.
  150. bool param1 = ScriptUtil::luaCheckBool(state, 2);
  151. PhysicsConstraint* instance = getInstance(state);
  152. instance->setEnabled(param1);
  153. return 0;
  154. }
  155. else
  156. {
  157. lua_pushstring(state, "lua_PhysicsConstraint_setEnabled - Failed to match the given parameters to a valid function signature.");
  158. lua_error(state);
  159. }
  160. break;
  161. }
  162. default:
  163. {
  164. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  165. lua_error(state);
  166. break;
  167. }
  168. }
  169. return 0;
  170. }
  171. int lua_PhysicsConstraint_static_centerOfMassMidpoint(lua_State* state)
  172. {
  173. // Get the number of parameters.
  174. int paramCount = lua_gettop(state);
  175. // Attempt to match the parameters to a valid binding.
  176. switch (paramCount)
  177. {
  178. case 2:
  179. {
  180. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TTABLE || lua_type(state, 1) == LUA_TNIL) &&
  181. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL))
  182. {
  183. // Get parameter 1 off the stack.
  184. Node* param1 = ScriptUtil::getObjectPointer<Node>(1, "Node", false);
  185. // Get parameter 2 off the stack.
  186. Node* param2 = ScriptUtil::getObjectPointer<Node>(2, "Node", false);
  187. void* returnPtr = (void*)new Vector3(PhysicsConstraint::centerOfMassMidpoint(param1, param2));
  188. if (returnPtr)
  189. {
  190. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(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. else
  203. {
  204. lua_pushstring(state, "lua_PhysicsConstraint_static_centerOfMassMidpoint - Failed to match the given parameters to a valid function signature.");
  205. lua_error(state);
  206. }
  207. break;
  208. }
  209. default:
  210. {
  211. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  212. lua_error(state);
  213. break;
  214. }
  215. }
  216. return 0;
  217. }
  218. int lua_PhysicsConstraint_static_getRotationOffset(lua_State* state)
  219. {
  220. // Get the number of parameters.
  221. int paramCount = lua_gettop(state);
  222. // Attempt to match the parameters to a valid binding.
  223. switch (paramCount)
  224. {
  225. case 2:
  226. {
  227. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TTABLE || lua_type(state, 1) == LUA_TNIL) &&
  228. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
  229. {
  230. // Get parameter 1 off the stack.
  231. Node* param1 = ScriptUtil::getObjectPointer<Node>(1, "Node", false);
  232. // Get parameter 2 off the stack.
  233. Vector3* param2 = ScriptUtil::getObjectPointer<Vector3>(2, "Vector3", true);
  234. void* returnPtr = (void*)new Quaternion(PhysicsConstraint::getRotationOffset(param1, *param2));
  235. if (returnPtr)
  236. {
  237. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  238. object->instance = returnPtr;
  239. object->owns = true;
  240. luaL_getmetatable(state, "Quaternion");
  241. lua_setmetatable(state, -2);
  242. }
  243. else
  244. {
  245. lua_pushnil(state);
  246. }
  247. return 1;
  248. }
  249. else
  250. {
  251. lua_pushstring(state, "lua_PhysicsConstraint_static_getRotationOffset - Failed to match the given parameters to a valid function signature.");
  252. lua_error(state);
  253. }
  254. break;
  255. }
  256. default:
  257. {
  258. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  259. lua_error(state);
  260. break;
  261. }
  262. }
  263. return 0;
  264. }
  265. int lua_PhysicsConstraint_static_getTranslationOffset(lua_State* state)
  266. {
  267. // Get the number of parameters.
  268. int paramCount = lua_gettop(state);
  269. // Attempt to match the parameters to a valid binding.
  270. switch (paramCount)
  271. {
  272. case 2:
  273. {
  274. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TTABLE || lua_type(state, 1) == LUA_TNIL) &&
  275. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
  276. {
  277. // Get parameter 1 off the stack.
  278. Node* param1 = ScriptUtil::getObjectPointer<Node>(1, "Node", false);
  279. // Get parameter 2 off the stack.
  280. Vector3* param2 = ScriptUtil::getObjectPointer<Vector3>(2, "Vector3", true);
  281. void* returnPtr = (void*)new Vector3(PhysicsConstraint::getTranslationOffset(param1, *param2));
  282. if (returnPtr)
  283. {
  284. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  285. object->instance = returnPtr;
  286. object->owns = true;
  287. luaL_getmetatable(state, "Vector3");
  288. lua_setmetatable(state, -2);
  289. }
  290. else
  291. {
  292. lua_pushnil(state);
  293. }
  294. return 1;
  295. }
  296. else
  297. {
  298. lua_pushstring(state, "lua_PhysicsConstraint_static_getTranslationOffset - Failed to match the given parameters to a valid function signature.");
  299. lua_error(state);
  300. }
  301. break;
  302. }
  303. default:
  304. {
  305. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  306. lua_error(state);
  307. break;
  308. }
  309. }
  310. return 0;
  311. }
  312. }