lua_PhysicsRigidBodyParameters.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. #include "Base.h"
  2. #include "ScriptController.h"
  3. #include "lua_PhysicsRigidBodyParameters.h"
  4. #include "Animation.h"
  5. #include "AnimationTarget.h"
  6. #include "Base.h"
  7. #include "Game.h"
  8. #include "Image.h"
  9. #include "MeshPart.h"
  10. #include "Node.h"
  11. #include "PhysicsCollisionObject.h"
  12. #include "PhysicsController.h"
  13. #include "PhysicsRigidBody.h"
  14. #include "ScriptListener.h"
  15. #include "Transform.h"
  16. #include "lua_CurveInterpolationType.h"
  17. #include "lua_PhysicsCollisionObjectCollisionListenerEventType.h"
  18. #include "lua_PhysicsCollisionObjectType.h"
  19. #include "lua_PhysicsCollisionShapeType.h"
  20. namespace gameplay
  21. {
  22. void luaRegister_PhysicsRigidBodyParameters()
  23. {
  24. const luaL_Reg lua_members[] =
  25. {
  26. {"angularDamping", lua_PhysicsRigidBodyParameters_angularDamping},
  27. {"anisotropicFriction", lua_PhysicsRigidBodyParameters_anisotropicFriction},
  28. {"friction", lua_PhysicsRigidBodyParameters_friction},
  29. {"kinematic", lua_PhysicsRigidBodyParameters_kinematic},
  30. {"linearDamping", lua_PhysicsRigidBodyParameters_linearDamping},
  31. {"mass", lua_PhysicsRigidBodyParameters_mass},
  32. {"restitution", lua_PhysicsRigidBodyParameters_restitution},
  33. {NULL, NULL}
  34. };
  35. const luaL_Reg* lua_statics = NULL;
  36. std::vector<std::string> scopePath;
  37. scopePath.push_back("PhysicsRigidBody");
  38. ScriptUtil::registerClass("PhysicsRigidBodyParameters", lua_members, lua_PhysicsRigidBodyParameters__init, lua_PhysicsRigidBodyParameters__gc, lua_statics, scopePath);
  39. }
  40. static PhysicsRigidBody::Parameters* getInstance(lua_State* state)
  41. {
  42. void* userdata = luaL_checkudata(state, 1, "PhysicsRigidBodyParameters");
  43. luaL_argcheck(state, userdata != NULL, 1, "'PhysicsRigidBodyParameters' expected.");
  44. return (PhysicsRigidBody::Parameters*)((ScriptUtil::LuaObject*)userdata)->instance;
  45. }
  46. int lua_PhysicsRigidBodyParameters__gc(lua_State* state)
  47. {
  48. // Get the number of parameters.
  49. int paramCount = lua_gettop(state);
  50. // Attempt to match the parameters to a valid binding.
  51. switch (paramCount)
  52. {
  53. case 1:
  54. {
  55. if ((lua_type(state, 1) == LUA_TUSERDATA))
  56. {
  57. void* userdata = luaL_checkudata(state, 1, "PhysicsRigidBodyParameters");
  58. luaL_argcheck(state, userdata != NULL, 1, "'PhysicsRigidBodyParameters' expected.");
  59. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)userdata;
  60. if (object->owns)
  61. {
  62. PhysicsRigidBody::Parameters* instance = (PhysicsRigidBody::Parameters*)object->instance;
  63. SAFE_DELETE(instance);
  64. }
  65. return 0;
  66. }
  67. else
  68. {
  69. lua_pushstring(state, "lua_PhysicsRigidBodyParameters__gc - Failed to match the given parameters to a valid function signature.");
  70. lua_error(state);
  71. }
  72. break;
  73. }
  74. default:
  75. {
  76. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  77. lua_error(state);
  78. break;
  79. }
  80. }
  81. return 0;
  82. }
  83. int lua_PhysicsRigidBodyParameters__init(lua_State* state)
  84. {
  85. // Get the number of parameters.
  86. int paramCount = lua_gettop(state);
  87. // Attempt to match the parameters to a valid binding.
  88. switch (paramCount)
  89. {
  90. case 0:
  91. {
  92. void* returnPtr = (void*)new PhysicsRigidBody::Parameters();
  93. if (returnPtr)
  94. {
  95. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  96. object->instance = returnPtr;
  97. object->owns = true;
  98. luaL_getmetatable(state, "PhysicsRigidBodyParameters");
  99. lua_setmetatable(state, -2);
  100. }
  101. else
  102. {
  103. lua_pushnil(state);
  104. }
  105. return 1;
  106. break;
  107. }
  108. case 1:
  109. {
  110. if (lua_type(state, 1) == LUA_TNUMBER)
  111. {
  112. // Get parameter 1 off the stack.
  113. float param1 = (float)luaL_checknumber(state, 1);
  114. void* returnPtr = (void*)new PhysicsRigidBody::Parameters(param1);
  115. if (returnPtr)
  116. {
  117. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  118. object->instance = returnPtr;
  119. object->owns = true;
  120. luaL_getmetatable(state, "PhysicsRigidBodyParameters");
  121. lua_setmetatable(state, -2);
  122. }
  123. else
  124. {
  125. lua_pushnil(state);
  126. }
  127. return 1;
  128. }
  129. else
  130. {
  131. lua_pushstring(state, "lua_PhysicsRigidBodyParameters__init - Failed to match the given parameters to a valid function signature.");
  132. lua_error(state);
  133. }
  134. break;
  135. }
  136. case 2:
  137. {
  138. if (lua_type(state, 1) == LUA_TNUMBER &&
  139. lua_type(state, 2) == LUA_TNUMBER)
  140. {
  141. // Get parameter 1 off the stack.
  142. float param1 = (float)luaL_checknumber(state, 1);
  143. // Get parameter 2 off the stack.
  144. float param2 = (float)luaL_checknumber(state, 2);
  145. void* returnPtr = (void*)new PhysicsRigidBody::Parameters(param1, param2);
  146. if (returnPtr)
  147. {
  148. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  149. object->instance = returnPtr;
  150. object->owns = true;
  151. luaL_getmetatable(state, "PhysicsRigidBodyParameters");
  152. lua_setmetatable(state, -2);
  153. }
  154. else
  155. {
  156. lua_pushnil(state);
  157. }
  158. return 1;
  159. }
  160. else
  161. {
  162. lua_pushstring(state, "lua_PhysicsRigidBodyParameters__init - Failed to match the given parameters to a valid function signature.");
  163. lua_error(state);
  164. }
  165. break;
  166. }
  167. case 3:
  168. {
  169. if (lua_type(state, 1) == LUA_TNUMBER &&
  170. lua_type(state, 2) == LUA_TNUMBER &&
  171. lua_type(state, 3) == LUA_TNUMBER)
  172. {
  173. // Get parameter 1 off the stack.
  174. float param1 = (float)luaL_checknumber(state, 1);
  175. // Get parameter 2 off the stack.
  176. float param2 = (float)luaL_checknumber(state, 2);
  177. // Get parameter 3 off the stack.
  178. float param3 = (float)luaL_checknumber(state, 3);
  179. void* returnPtr = (void*)new PhysicsRigidBody::Parameters(param1, param2, param3);
  180. if (returnPtr)
  181. {
  182. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  183. object->instance = returnPtr;
  184. object->owns = true;
  185. luaL_getmetatable(state, "PhysicsRigidBodyParameters");
  186. lua_setmetatable(state, -2);
  187. }
  188. else
  189. {
  190. lua_pushnil(state);
  191. }
  192. return 1;
  193. }
  194. else
  195. {
  196. lua_pushstring(state, "lua_PhysicsRigidBodyParameters__init - 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_TNUMBER &&
  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, 1);
  210. // Get parameter 2 off the stack.
  211. float param2 = (float)luaL_checknumber(state, 2);
  212. // Get parameter 3 off the stack.
  213. float param3 = (float)luaL_checknumber(state, 3);
  214. // Get parameter 4 off the stack.
  215. float param4 = (float)luaL_checknumber(state, 4);
  216. void* returnPtr = (void*)new PhysicsRigidBody::Parameters(param1, param2, param3, param4);
  217. if (returnPtr)
  218. {
  219. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  220. object->instance = returnPtr;
  221. object->owns = true;
  222. luaL_getmetatable(state, "PhysicsRigidBodyParameters");
  223. lua_setmetatable(state, -2);
  224. }
  225. else
  226. {
  227. lua_pushnil(state);
  228. }
  229. return 1;
  230. }
  231. else
  232. {
  233. lua_pushstring(state, "lua_PhysicsRigidBodyParameters__init - Failed to match the given parameters to a valid function signature.");
  234. lua_error(state);
  235. }
  236. break;
  237. }
  238. case 5:
  239. {
  240. if (lua_type(state, 1) == LUA_TNUMBER &&
  241. lua_type(state, 2) == LUA_TNUMBER &&
  242. lua_type(state, 3) == LUA_TNUMBER &&
  243. lua_type(state, 4) == LUA_TNUMBER &&
  244. lua_type(state, 5) == LUA_TNUMBER)
  245. {
  246. // Get parameter 1 off the stack.
  247. float param1 = (float)luaL_checknumber(state, 1);
  248. // Get parameter 2 off the stack.
  249. float param2 = (float)luaL_checknumber(state, 2);
  250. // Get parameter 3 off the stack.
  251. float param3 = (float)luaL_checknumber(state, 3);
  252. // Get parameter 4 off the stack.
  253. float param4 = (float)luaL_checknumber(state, 4);
  254. // Get parameter 5 off the stack.
  255. float param5 = (float)luaL_checknumber(state, 5);
  256. void* returnPtr = (void*)new PhysicsRigidBody::Parameters(param1, param2, param3, param4, param5);
  257. if (returnPtr)
  258. {
  259. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  260. object->instance = returnPtr;
  261. object->owns = true;
  262. luaL_getmetatable(state, "PhysicsRigidBodyParameters");
  263. lua_setmetatable(state, -2);
  264. }
  265. else
  266. {
  267. lua_pushnil(state);
  268. }
  269. return 1;
  270. }
  271. else
  272. {
  273. lua_pushstring(state, "lua_PhysicsRigidBodyParameters__init - Failed to match the given parameters to a valid function signature.");
  274. lua_error(state);
  275. }
  276. break;
  277. }
  278. case 6:
  279. {
  280. if (lua_type(state, 1) == LUA_TNUMBER &&
  281. lua_type(state, 2) == LUA_TNUMBER &&
  282. lua_type(state, 3) == LUA_TNUMBER &&
  283. lua_type(state, 4) == LUA_TNUMBER &&
  284. lua_type(state, 5) == LUA_TNUMBER &&
  285. lua_type(state, 6) == LUA_TBOOLEAN)
  286. {
  287. // Get parameter 1 off the stack.
  288. float param1 = (float)luaL_checknumber(state, 1);
  289. // Get parameter 2 off the stack.
  290. float param2 = (float)luaL_checknumber(state, 2);
  291. // Get parameter 3 off the stack.
  292. float param3 = (float)luaL_checknumber(state, 3);
  293. // Get parameter 4 off the stack.
  294. float param4 = (float)luaL_checknumber(state, 4);
  295. // Get parameter 5 off the stack.
  296. float param5 = (float)luaL_checknumber(state, 5);
  297. // Get parameter 6 off the stack.
  298. bool param6 = ScriptUtil::luaCheckBool(state, 6);
  299. void* returnPtr = (void*)new PhysicsRigidBody::Parameters(param1, param2, param3, param4, param5, param6);
  300. if (returnPtr)
  301. {
  302. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  303. object->instance = returnPtr;
  304. object->owns = true;
  305. luaL_getmetatable(state, "PhysicsRigidBodyParameters");
  306. lua_setmetatable(state, -2);
  307. }
  308. else
  309. {
  310. lua_pushnil(state);
  311. }
  312. return 1;
  313. }
  314. else
  315. {
  316. lua_pushstring(state, "lua_PhysicsRigidBodyParameters__init - Failed to match the given parameters to a valid function signature.");
  317. lua_error(state);
  318. }
  319. break;
  320. }
  321. case 7:
  322. {
  323. if (lua_type(state, 1) == LUA_TNUMBER &&
  324. lua_type(state, 2) == LUA_TNUMBER &&
  325. lua_type(state, 3) == LUA_TNUMBER &&
  326. lua_type(state, 4) == LUA_TNUMBER &&
  327. lua_type(state, 5) == LUA_TNUMBER &&
  328. lua_type(state, 6) == LUA_TBOOLEAN &&
  329. (lua_type(state, 7) == LUA_TUSERDATA || lua_type(state, 7) == LUA_TNIL))
  330. {
  331. // Get parameter 1 off the stack.
  332. float param1 = (float)luaL_checknumber(state, 1);
  333. // Get parameter 2 off the stack.
  334. float param2 = (float)luaL_checknumber(state, 2);
  335. // Get parameter 3 off the stack.
  336. float param3 = (float)luaL_checknumber(state, 3);
  337. // Get parameter 4 off the stack.
  338. float param4 = (float)luaL_checknumber(state, 4);
  339. // Get parameter 5 off the stack.
  340. float param5 = (float)luaL_checknumber(state, 5);
  341. // Get parameter 6 off the stack.
  342. bool param6 = ScriptUtil::luaCheckBool(state, 6);
  343. // Get parameter 7 off the stack.
  344. Vector3* param7 = ScriptUtil::getObjectPointer<Vector3>(7, "Vector3", true);
  345. void* returnPtr = (void*)new PhysicsRigidBody::Parameters(param1, param2, param3, param4, param5, param6, *param7);
  346. if (returnPtr)
  347. {
  348. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  349. object->instance = returnPtr;
  350. object->owns = true;
  351. luaL_getmetatable(state, "PhysicsRigidBodyParameters");
  352. lua_setmetatable(state, -2);
  353. }
  354. else
  355. {
  356. lua_pushnil(state);
  357. }
  358. return 1;
  359. }
  360. else
  361. {
  362. lua_pushstring(state, "lua_PhysicsRigidBodyParameters__init - Failed to match the given parameters to a valid function signature.");
  363. lua_error(state);
  364. }
  365. break;
  366. }
  367. default:
  368. {
  369. lua_pushstring(state, "Invalid number of parameters (expected 0, 1, 2, 3, 4, 5, 6 or 7).");
  370. lua_error(state);
  371. break;
  372. }
  373. }
  374. return 0;
  375. }
  376. int lua_PhysicsRigidBodyParameters_angularDamping(lua_State* state)
  377. {
  378. // Validate the number of parameters.
  379. if (lua_gettop(state) > 2)
  380. {
  381. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  382. lua_error(state);
  383. }
  384. PhysicsRigidBody::Parameters* instance = getInstance(state);
  385. if (lua_gettop(state) == 2)
  386. {
  387. // Get parameter 2 off the stack.
  388. float param2 = (float)luaL_checknumber(state, 2);
  389. instance->angularDamping = param2;
  390. return 0;
  391. }
  392. else
  393. {
  394. float result = instance->angularDamping;
  395. // Push the return value onto the stack.
  396. lua_pushnumber(state, result);
  397. return 1;
  398. }
  399. }
  400. int lua_PhysicsRigidBodyParameters_anisotropicFriction(lua_State* state)
  401. {
  402. // Validate the number of parameters.
  403. if (lua_gettop(state) > 2)
  404. {
  405. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  406. lua_error(state);
  407. }
  408. PhysicsRigidBody::Parameters* instance = getInstance(state);
  409. if (lua_gettop(state) == 2)
  410. {
  411. // Get parameter 2 off the stack.
  412. Vector3* param2 = ScriptUtil::getObjectPointer<Vector3>(2, "Vector3", true);
  413. instance->anisotropicFriction = *param2;
  414. return 0;
  415. }
  416. else
  417. {
  418. void* returnPtr = (void*)new Vector3(instance->anisotropicFriction);
  419. if (returnPtr)
  420. {
  421. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  422. object->instance = returnPtr;
  423. object->owns = true;
  424. luaL_getmetatable(state, "Vector3");
  425. lua_setmetatable(state, -2);
  426. }
  427. else
  428. {
  429. lua_pushnil(state);
  430. }
  431. return 1;
  432. }
  433. }
  434. int lua_PhysicsRigidBodyParameters_friction(lua_State* state)
  435. {
  436. // Validate the number of parameters.
  437. if (lua_gettop(state) > 2)
  438. {
  439. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  440. lua_error(state);
  441. }
  442. PhysicsRigidBody::Parameters* instance = getInstance(state);
  443. if (lua_gettop(state) == 2)
  444. {
  445. // Get parameter 2 off the stack.
  446. float param2 = (float)luaL_checknumber(state, 2);
  447. instance->friction = param2;
  448. return 0;
  449. }
  450. else
  451. {
  452. float result = instance->friction;
  453. // Push the return value onto the stack.
  454. lua_pushnumber(state, result);
  455. return 1;
  456. }
  457. }
  458. int lua_PhysicsRigidBodyParameters_kinematic(lua_State* state)
  459. {
  460. // Validate the number of parameters.
  461. if (lua_gettop(state) > 2)
  462. {
  463. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  464. lua_error(state);
  465. }
  466. PhysicsRigidBody::Parameters* instance = getInstance(state);
  467. if (lua_gettop(state) == 2)
  468. {
  469. // Get parameter 2 off the stack.
  470. bool param2 = ScriptUtil::luaCheckBool(state, 2);
  471. instance->kinematic = param2;
  472. return 0;
  473. }
  474. else
  475. {
  476. bool result = instance->kinematic;
  477. // Push the return value onto the stack.
  478. lua_pushboolean(state, result);
  479. return 1;
  480. }
  481. }
  482. int lua_PhysicsRigidBodyParameters_linearDamping(lua_State* state)
  483. {
  484. // Validate the number of parameters.
  485. if (lua_gettop(state) > 2)
  486. {
  487. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  488. lua_error(state);
  489. }
  490. PhysicsRigidBody::Parameters* instance = getInstance(state);
  491. if (lua_gettop(state) == 2)
  492. {
  493. // Get parameter 2 off the stack.
  494. float param2 = (float)luaL_checknumber(state, 2);
  495. instance->linearDamping = param2;
  496. return 0;
  497. }
  498. else
  499. {
  500. float result = instance->linearDamping;
  501. // Push the return value onto the stack.
  502. lua_pushnumber(state, result);
  503. return 1;
  504. }
  505. }
  506. int lua_PhysicsRigidBodyParameters_mass(lua_State* state)
  507. {
  508. // Validate the number of parameters.
  509. if (lua_gettop(state) > 2)
  510. {
  511. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  512. lua_error(state);
  513. }
  514. PhysicsRigidBody::Parameters* instance = getInstance(state);
  515. if (lua_gettop(state) == 2)
  516. {
  517. // Get parameter 2 off the stack.
  518. float param2 = (float)luaL_checknumber(state, 2);
  519. instance->mass = param2;
  520. return 0;
  521. }
  522. else
  523. {
  524. float result = instance->mass;
  525. // Push the return value onto the stack.
  526. lua_pushnumber(state, result);
  527. return 1;
  528. }
  529. }
  530. int lua_PhysicsRigidBodyParameters_restitution(lua_State* state)
  531. {
  532. // Validate the number of parameters.
  533. if (lua_gettop(state) > 2)
  534. {
  535. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  536. lua_error(state);
  537. }
  538. PhysicsRigidBody::Parameters* instance = getInstance(state);
  539. if (lua_gettop(state) == 2)
  540. {
  541. // Get parameter 2 off the stack.
  542. float param2 = (float)luaL_checknumber(state, 2);
  543. instance->restitution = param2;
  544. return 0;
  545. }
  546. else
  547. {
  548. float result = instance->restitution;
  549. // Push the return value onto the stack.
  550. lua_pushnumber(state, result);
  551. return 1;
  552. }
  553. }
  554. }