2
0

lua_PhysicsRigidBodyParameters.cpp 21 KB

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