lua_PhysicsRigidBodyParameters.cpp 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833
  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. {"angularFactor", lua_PhysicsRigidBodyParameters_angularFactor},
  29. {"anisotropicFriction", lua_PhysicsRigidBodyParameters_anisotropicFriction},
  30. {"friction", lua_PhysicsRigidBodyParameters_friction},
  31. {"kinematic", lua_PhysicsRigidBodyParameters_kinematic},
  32. {"linearDamping", lua_PhysicsRigidBodyParameters_linearDamping},
  33. {"linearFactor", lua_PhysicsRigidBodyParameters_linearFactor},
  34. {"mass", lua_PhysicsRigidBodyParameters_mass},
  35. {"restitution", lua_PhysicsRigidBodyParameters_restitution},
  36. {NULL, NULL}
  37. };
  38. const luaL_Reg* lua_statics = NULL;
  39. std::vector<std::string> scopePath;
  40. scopePath.push_back("PhysicsRigidBody");
  41. ScriptUtil::registerClass("PhysicsRigidBodyParameters", lua_members, lua_PhysicsRigidBodyParameters__init, lua_PhysicsRigidBodyParameters__gc, lua_statics, scopePath);
  42. }
  43. static PhysicsRigidBody::Parameters* getInstance(lua_State* state)
  44. {
  45. void* userdata = luaL_checkudata(state, 1, "PhysicsRigidBodyParameters");
  46. luaL_argcheck(state, userdata != NULL, 1, "'PhysicsRigidBodyParameters' expected.");
  47. return (PhysicsRigidBody::Parameters*)((ScriptUtil::LuaObject*)userdata)->instance;
  48. }
  49. int lua_PhysicsRigidBodyParameters__gc(lua_State* state)
  50. {
  51. // Get the number of parameters.
  52. int paramCount = lua_gettop(state);
  53. // Attempt to match the parameters to a valid binding.
  54. switch (paramCount)
  55. {
  56. case 1:
  57. {
  58. if ((lua_type(state, 1) == LUA_TUSERDATA))
  59. {
  60. void* userdata = luaL_checkudata(state, 1, "PhysicsRigidBodyParameters");
  61. luaL_argcheck(state, userdata != NULL, 1, "'PhysicsRigidBodyParameters' expected.");
  62. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)userdata;
  63. if (object->owns)
  64. {
  65. PhysicsRigidBody::Parameters* instance = (PhysicsRigidBody::Parameters*)object->instance;
  66. SAFE_DELETE(instance);
  67. }
  68. return 0;
  69. }
  70. else
  71. {
  72. lua_pushstring(state, "lua_PhysicsRigidBodyParameters__gc - Failed to match the given parameters to a valid function signature.");
  73. lua_error(state);
  74. }
  75. break;
  76. }
  77. default:
  78. {
  79. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  80. lua_error(state);
  81. break;
  82. }
  83. }
  84. return 0;
  85. }
  86. int lua_PhysicsRigidBodyParameters__init(lua_State* state)
  87. {
  88. // Get the number of parameters.
  89. int paramCount = lua_gettop(state);
  90. // Attempt to match the parameters to a valid binding.
  91. switch (paramCount)
  92. {
  93. case 0:
  94. {
  95. void* returnPtr = (void*)new PhysicsRigidBody::Parameters();
  96. if (returnPtr)
  97. {
  98. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  99. object->instance = returnPtr;
  100. object->owns = true;
  101. luaL_getmetatable(state, "PhysicsRigidBodyParameters");
  102. lua_setmetatable(state, -2);
  103. }
  104. else
  105. {
  106. lua_pushnil(state);
  107. }
  108. return 1;
  109. break;
  110. }
  111. case 1:
  112. {
  113. if (lua_type(state, 1) == LUA_TNUMBER)
  114. {
  115. // Get parameter 1 off the stack.
  116. float param1 = (float)luaL_checknumber(state, 1);
  117. void* returnPtr = (void*)new PhysicsRigidBody::Parameters(param1);
  118. if (returnPtr)
  119. {
  120. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  121. object->instance = returnPtr;
  122. object->owns = true;
  123. luaL_getmetatable(state, "PhysicsRigidBodyParameters");
  124. lua_setmetatable(state, -2);
  125. }
  126. else
  127. {
  128. lua_pushnil(state);
  129. }
  130. return 1;
  131. }
  132. else
  133. {
  134. lua_pushstring(state, "lua_PhysicsRigidBodyParameters__init - Failed to match the given parameters to a valid function signature.");
  135. lua_error(state);
  136. }
  137. break;
  138. }
  139. case 2:
  140. {
  141. if (lua_type(state, 1) == LUA_TNUMBER &&
  142. lua_type(state, 2) == LUA_TNUMBER)
  143. {
  144. // Get parameter 1 off the stack.
  145. float param1 = (float)luaL_checknumber(state, 1);
  146. // Get parameter 2 off the stack.
  147. float param2 = (float)luaL_checknumber(state, 2);
  148. void* returnPtr = (void*)new PhysicsRigidBody::Parameters(param1, param2);
  149. if (returnPtr)
  150. {
  151. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  152. object->instance = returnPtr;
  153. object->owns = true;
  154. luaL_getmetatable(state, "PhysicsRigidBodyParameters");
  155. lua_setmetatable(state, -2);
  156. }
  157. else
  158. {
  159. lua_pushnil(state);
  160. }
  161. return 1;
  162. }
  163. else
  164. {
  165. lua_pushstring(state, "lua_PhysicsRigidBodyParameters__init - Failed to match the given parameters to a valid function signature.");
  166. lua_error(state);
  167. }
  168. break;
  169. }
  170. case 3:
  171. {
  172. if (lua_type(state, 1) == LUA_TNUMBER &&
  173. lua_type(state, 2) == LUA_TNUMBER &&
  174. lua_type(state, 3) == LUA_TNUMBER)
  175. {
  176. // Get parameter 1 off the stack.
  177. float param1 = (float)luaL_checknumber(state, 1);
  178. // Get parameter 2 off the stack.
  179. float param2 = (float)luaL_checknumber(state, 2);
  180. // Get parameter 3 off the stack.
  181. float param3 = (float)luaL_checknumber(state, 3);
  182. void* returnPtr = (void*)new PhysicsRigidBody::Parameters(param1, param2, param3);
  183. if (returnPtr)
  184. {
  185. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  186. object->instance = returnPtr;
  187. object->owns = true;
  188. luaL_getmetatable(state, "PhysicsRigidBodyParameters");
  189. lua_setmetatable(state, -2);
  190. }
  191. else
  192. {
  193. lua_pushnil(state);
  194. }
  195. return 1;
  196. }
  197. else
  198. {
  199. lua_pushstring(state, "lua_PhysicsRigidBodyParameters__init - Failed to match the given parameters to a valid function signature.");
  200. lua_error(state);
  201. }
  202. break;
  203. }
  204. case 4:
  205. {
  206. if (lua_type(state, 1) == LUA_TNUMBER &&
  207. lua_type(state, 2) == LUA_TNUMBER &&
  208. lua_type(state, 3) == LUA_TNUMBER &&
  209. lua_type(state, 4) == LUA_TNUMBER)
  210. {
  211. // Get parameter 1 off the stack.
  212. float param1 = (float)luaL_checknumber(state, 1);
  213. // Get parameter 2 off the stack.
  214. float param2 = (float)luaL_checknumber(state, 2);
  215. // Get parameter 3 off the stack.
  216. float param3 = (float)luaL_checknumber(state, 3);
  217. // Get parameter 4 off the stack.
  218. float param4 = (float)luaL_checknumber(state, 4);
  219. void* returnPtr = (void*)new PhysicsRigidBody::Parameters(param1, param2, param3, param4);
  220. if (returnPtr)
  221. {
  222. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  223. object->instance = returnPtr;
  224. object->owns = true;
  225. luaL_getmetatable(state, "PhysicsRigidBodyParameters");
  226. lua_setmetatable(state, -2);
  227. }
  228. else
  229. {
  230. lua_pushnil(state);
  231. }
  232. return 1;
  233. }
  234. else
  235. {
  236. lua_pushstring(state, "lua_PhysicsRigidBodyParameters__init - Failed to match the given parameters to a valid function signature.");
  237. lua_error(state);
  238. }
  239. break;
  240. }
  241. case 5:
  242. {
  243. if (lua_type(state, 1) == LUA_TNUMBER &&
  244. lua_type(state, 2) == LUA_TNUMBER &&
  245. lua_type(state, 3) == LUA_TNUMBER &&
  246. lua_type(state, 4) == LUA_TNUMBER &&
  247. lua_type(state, 5) == LUA_TNUMBER)
  248. {
  249. // Get parameter 1 off the stack.
  250. float param1 = (float)luaL_checknumber(state, 1);
  251. // Get parameter 2 off the stack.
  252. float param2 = (float)luaL_checknumber(state, 2);
  253. // Get parameter 3 off the stack.
  254. float param3 = (float)luaL_checknumber(state, 3);
  255. // Get parameter 4 off the stack.
  256. float param4 = (float)luaL_checknumber(state, 4);
  257. // Get parameter 5 off the stack.
  258. float param5 = (float)luaL_checknumber(state, 5);
  259. void* returnPtr = (void*)new PhysicsRigidBody::Parameters(param1, param2, param3, param4, param5);
  260. if (returnPtr)
  261. {
  262. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  263. object->instance = returnPtr;
  264. object->owns = true;
  265. luaL_getmetatable(state, "PhysicsRigidBodyParameters");
  266. lua_setmetatable(state, -2);
  267. }
  268. else
  269. {
  270. lua_pushnil(state);
  271. }
  272. return 1;
  273. }
  274. else
  275. {
  276. lua_pushstring(state, "lua_PhysicsRigidBodyParameters__init - Failed to match the given parameters to a valid function signature.");
  277. lua_error(state);
  278. }
  279. break;
  280. }
  281. case 6:
  282. {
  283. if (lua_type(state, 1) == LUA_TNUMBER &&
  284. lua_type(state, 2) == LUA_TNUMBER &&
  285. lua_type(state, 3) == LUA_TNUMBER &&
  286. lua_type(state, 4) == LUA_TNUMBER &&
  287. lua_type(state, 5) == LUA_TNUMBER &&
  288. lua_type(state, 6) == LUA_TBOOLEAN)
  289. {
  290. // Get parameter 1 off the stack.
  291. float param1 = (float)luaL_checknumber(state, 1);
  292. // Get parameter 2 off the stack.
  293. float param2 = (float)luaL_checknumber(state, 2);
  294. // Get parameter 3 off the stack.
  295. float param3 = (float)luaL_checknumber(state, 3);
  296. // Get parameter 4 off the stack.
  297. float param4 = (float)luaL_checknumber(state, 4);
  298. // Get parameter 5 off the stack.
  299. float param5 = (float)luaL_checknumber(state, 5);
  300. // Get parameter 6 off the stack.
  301. bool param6 = ScriptUtil::luaCheckBool(state, 6);
  302. void* returnPtr = (void*)new PhysicsRigidBody::Parameters(param1, param2, param3, param4, param5, param6);
  303. if (returnPtr)
  304. {
  305. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  306. object->instance = returnPtr;
  307. object->owns = true;
  308. luaL_getmetatable(state, "PhysicsRigidBodyParameters");
  309. lua_setmetatable(state, -2);
  310. }
  311. else
  312. {
  313. lua_pushnil(state);
  314. }
  315. return 1;
  316. }
  317. else
  318. {
  319. lua_pushstring(state, "lua_PhysicsRigidBodyParameters__init - Failed to match the given parameters to a valid function signature.");
  320. lua_error(state);
  321. }
  322. break;
  323. }
  324. case 7:
  325. {
  326. if (lua_type(state, 1) == LUA_TNUMBER &&
  327. lua_type(state, 2) == LUA_TNUMBER &&
  328. lua_type(state, 3) == LUA_TNUMBER &&
  329. lua_type(state, 4) == LUA_TNUMBER &&
  330. lua_type(state, 5) == LUA_TNUMBER &&
  331. lua_type(state, 6) == LUA_TBOOLEAN &&
  332. (lua_type(state, 7) == LUA_TUSERDATA || lua_type(state, 7) == LUA_TNIL))
  333. {
  334. // Get parameter 1 off the stack.
  335. float param1 = (float)luaL_checknumber(state, 1);
  336. // Get parameter 2 off the stack.
  337. float param2 = (float)luaL_checknumber(state, 2);
  338. // Get parameter 3 off the stack.
  339. float param3 = (float)luaL_checknumber(state, 3);
  340. // Get parameter 4 off the stack.
  341. float param4 = (float)luaL_checknumber(state, 4);
  342. // Get parameter 5 off the stack.
  343. float param5 = (float)luaL_checknumber(state, 5);
  344. // Get parameter 6 off the stack.
  345. bool param6 = ScriptUtil::luaCheckBool(state, 6);
  346. // Get parameter 7 off the stack.
  347. ScriptUtil::LuaArray<Vector3> param7 = ScriptUtil::getObjectPointer<Vector3>(7, "Vector3", true);
  348. void* returnPtr = (void*)new PhysicsRigidBody::Parameters(param1, param2, param3, param4, param5, param6, *param7);
  349. if (returnPtr)
  350. {
  351. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  352. object->instance = returnPtr;
  353. object->owns = true;
  354. luaL_getmetatable(state, "PhysicsRigidBodyParameters");
  355. lua_setmetatable(state, -2);
  356. }
  357. else
  358. {
  359. lua_pushnil(state);
  360. }
  361. return 1;
  362. }
  363. else
  364. {
  365. lua_pushstring(state, "lua_PhysicsRigidBodyParameters__init - Failed to match the given parameters to a valid function signature.");
  366. lua_error(state);
  367. }
  368. break;
  369. }
  370. case 8:
  371. {
  372. if (lua_type(state, 1) == LUA_TNUMBER &&
  373. lua_type(state, 2) == LUA_TNUMBER &&
  374. lua_type(state, 3) == LUA_TNUMBER &&
  375. lua_type(state, 4) == LUA_TNUMBER &&
  376. lua_type(state, 5) == LUA_TNUMBER &&
  377. lua_type(state, 6) == LUA_TBOOLEAN &&
  378. (lua_type(state, 7) == LUA_TUSERDATA || lua_type(state, 7) == LUA_TNIL) &&
  379. (lua_type(state, 8) == LUA_TUSERDATA || lua_type(state, 8) == LUA_TNIL))
  380. {
  381. // Get parameter 1 off the stack.
  382. float param1 = (float)luaL_checknumber(state, 1);
  383. // Get parameter 2 off the stack.
  384. float param2 = (float)luaL_checknumber(state, 2);
  385. // Get parameter 3 off the stack.
  386. float param3 = (float)luaL_checknumber(state, 3);
  387. // Get parameter 4 off the stack.
  388. float param4 = (float)luaL_checknumber(state, 4);
  389. // Get parameter 5 off the stack.
  390. float param5 = (float)luaL_checknumber(state, 5);
  391. // Get parameter 6 off the stack.
  392. bool param6 = ScriptUtil::luaCheckBool(state, 6);
  393. // Get parameter 7 off the stack.
  394. ScriptUtil::LuaArray<Vector3> param7 = ScriptUtil::getObjectPointer<Vector3>(7, "Vector3", true);
  395. // Get parameter 8 off the stack.
  396. ScriptUtil::LuaArray<Vector3> param8 = ScriptUtil::getObjectPointer<Vector3>(8, "Vector3", true);
  397. void* returnPtr = (void*)new PhysicsRigidBody::Parameters(param1, param2, param3, param4, param5, param6, *param7, *param8);
  398. if (returnPtr)
  399. {
  400. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  401. object->instance = returnPtr;
  402. object->owns = true;
  403. luaL_getmetatable(state, "PhysicsRigidBodyParameters");
  404. lua_setmetatable(state, -2);
  405. }
  406. else
  407. {
  408. lua_pushnil(state);
  409. }
  410. return 1;
  411. }
  412. else
  413. {
  414. lua_pushstring(state, "lua_PhysicsRigidBodyParameters__init - Failed to match the given parameters to a valid function signature.");
  415. lua_error(state);
  416. }
  417. break;
  418. }
  419. case 9:
  420. {
  421. if (lua_type(state, 1) == LUA_TNUMBER &&
  422. lua_type(state, 2) == LUA_TNUMBER &&
  423. lua_type(state, 3) == LUA_TNUMBER &&
  424. lua_type(state, 4) == LUA_TNUMBER &&
  425. lua_type(state, 5) == LUA_TNUMBER &&
  426. lua_type(state, 6) == LUA_TBOOLEAN &&
  427. (lua_type(state, 7) == LUA_TUSERDATA || lua_type(state, 7) == LUA_TNIL) &&
  428. (lua_type(state, 8) == LUA_TUSERDATA || lua_type(state, 8) == LUA_TNIL) &&
  429. (lua_type(state, 9) == LUA_TUSERDATA || lua_type(state, 9) == LUA_TNIL))
  430. {
  431. // Get parameter 1 off the stack.
  432. float param1 = (float)luaL_checknumber(state, 1);
  433. // Get parameter 2 off the stack.
  434. float param2 = (float)luaL_checknumber(state, 2);
  435. // Get parameter 3 off the stack.
  436. float param3 = (float)luaL_checknumber(state, 3);
  437. // Get parameter 4 off the stack.
  438. float param4 = (float)luaL_checknumber(state, 4);
  439. // Get parameter 5 off the stack.
  440. float param5 = (float)luaL_checknumber(state, 5);
  441. // Get parameter 6 off the stack.
  442. bool param6 = ScriptUtil::luaCheckBool(state, 6);
  443. // Get parameter 7 off the stack.
  444. ScriptUtil::LuaArray<Vector3> param7 = ScriptUtil::getObjectPointer<Vector3>(7, "Vector3", true);
  445. // Get parameter 8 off the stack.
  446. ScriptUtil::LuaArray<Vector3> param8 = ScriptUtil::getObjectPointer<Vector3>(8, "Vector3", true);
  447. // Get parameter 9 off the stack.
  448. ScriptUtil::LuaArray<Vector3> param9 = ScriptUtil::getObjectPointer<Vector3>(9, "Vector3", true);
  449. void* returnPtr = (void*)new PhysicsRigidBody::Parameters(param1, param2, param3, param4, param5, param6, *param7, *param8, *param9);
  450. if (returnPtr)
  451. {
  452. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  453. object->instance = returnPtr;
  454. object->owns = true;
  455. luaL_getmetatable(state, "PhysicsRigidBodyParameters");
  456. lua_setmetatable(state, -2);
  457. }
  458. else
  459. {
  460. lua_pushnil(state);
  461. }
  462. return 1;
  463. }
  464. else
  465. {
  466. lua_pushstring(state, "lua_PhysicsRigidBodyParameters__init - Failed to match the given parameters to a valid function signature.");
  467. lua_error(state);
  468. }
  469. break;
  470. }
  471. default:
  472. {
  473. lua_pushstring(state, "Invalid number of parameters (expected 0, 1, 2, 3, 4, 5, 6, 7, 8 or 9).");
  474. lua_error(state);
  475. break;
  476. }
  477. }
  478. return 0;
  479. }
  480. int lua_PhysicsRigidBodyParameters_angularDamping(lua_State* state)
  481. {
  482. // Validate the number of parameters.
  483. if (lua_gettop(state) > 2)
  484. {
  485. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  486. lua_error(state);
  487. }
  488. PhysicsRigidBody::Parameters* instance = getInstance(state);
  489. if (lua_gettop(state) == 2)
  490. {
  491. // Get parameter 2 off the stack.
  492. float param2 = (float)luaL_checknumber(state, 2);
  493. instance->angularDamping = param2;
  494. return 0;
  495. }
  496. else
  497. {
  498. float result = instance->angularDamping;
  499. // Push the return value onto the stack.
  500. lua_pushnumber(state, result);
  501. return 1;
  502. }
  503. }
  504. int lua_PhysicsRigidBodyParameters_angularFactor(lua_State* state)
  505. {
  506. // Validate the number of parameters.
  507. if (lua_gettop(state) > 2)
  508. {
  509. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  510. lua_error(state);
  511. }
  512. PhysicsRigidBody::Parameters* instance = getInstance(state);
  513. if (lua_gettop(state) == 2)
  514. {
  515. // Get parameter 2 off the stack.
  516. ScriptUtil::LuaArray<Vector3> param2 = ScriptUtil::getObjectPointer<Vector3>(2, "Vector3", true);
  517. instance->angularFactor = *param2;
  518. return 0;
  519. }
  520. else
  521. {
  522. void* returnPtr = (void*)new Vector3(instance->angularFactor);
  523. if (returnPtr)
  524. {
  525. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  526. object->instance = returnPtr;
  527. object->owns = true;
  528. luaL_getmetatable(state, "Vector3");
  529. lua_setmetatable(state, -2);
  530. }
  531. else
  532. {
  533. lua_pushnil(state);
  534. }
  535. return 1;
  536. }
  537. }
  538. int lua_PhysicsRigidBodyParameters_anisotropicFriction(lua_State* state)
  539. {
  540. // Validate the number of parameters.
  541. if (lua_gettop(state) > 2)
  542. {
  543. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  544. lua_error(state);
  545. }
  546. PhysicsRigidBody::Parameters* instance = getInstance(state);
  547. if (lua_gettop(state) == 2)
  548. {
  549. // Get parameter 2 off the stack.
  550. ScriptUtil::LuaArray<Vector3> param2 = ScriptUtil::getObjectPointer<Vector3>(2, "Vector3", true);
  551. instance->anisotropicFriction = *param2;
  552. return 0;
  553. }
  554. else
  555. {
  556. void* returnPtr = (void*)new Vector3(instance->anisotropicFriction);
  557. if (returnPtr)
  558. {
  559. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  560. object->instance = returnPtr;
  561. object->owns = true;
  562. luaL_getmetatable(state, "Vector3");
  563. lua_setmetatable(state, -2);
  564. }
  565. else
  566. {
  567. lua_pushnil(state);
  568. }
  569. return 1;
  570. }
  571. }
  572. int lua_PhysicsRigidBodyParameters_friction(lua_State* state)
  573. {
  574. // Validate the number of parameters.
  575. if (lua_gettop(state) > 2)
  576. {
  577. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  578. lua_error(state);
  579. }
  580. PhysicsRigidBody::Parameters* instance = getInstance(state);
  581. if (lua_gettop(state) == 2)
  582. {
  583. // Get parameter 2 off the stack.
  584. float param2 = (float)luaL_checknumber(state, 2);
  585. instance->friction = param2;
  586. return 0;
  587. }
  588. else
  589. {
  590. float result = instance->friction;
  591. // Push the return value onto the stack.
  592. lua_pushnumber(state, result);
  593. return 1;
  594. }
  595. }
  596. int lua_PhysicsRigidBodyParameters_kinematic(lua_State* state)
  597. {
  598. // Validate the number of parameters.
  599. if (lua_gettop(state) > 2)
  600. {
  601. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  602. lua_error(state);
  603. }
  604. PhysicsRigidBody::Parameters* instance = getInstance(state);
  605. if (lua_gettop(state) == 2)
  606. {
  607. // Get parameter 2 off the stack.
  608. bool param2 = ScriptUtil::luaCheckBool(state, 2);
  609. instance->kinematic = param2;
  610. return 0;
  611. }
  612. else
  613. {
  614. bool result = instance->kinematic;
  615. // Push the return value onto the stack.
  616. lua_pushboolean(state, result);
  617. return 1;
  618. }
  619. }
  620. int lua_PhysicsRigidBodyParameters_linearDamping(lua_State* state)
  621. {
  622. // Validate the number of parameters.
  623. if (lua_gettop(state) > 2)
  624. {
  625. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  626. lua_error(state);
  627. }
  628. PhysicsRigidBody::Parameters* instance = getInstance(state);
  629. if (lua_gettop(state) == 2)
  630. {
  631. // Get parameter 2 off the stack.
  632. float param2 = (float)luaL_checknumber(state, 2);
  633. instance->linearDamping = param2;
  634. return 0;
  635. }
  636. else
  637. {
  638. float result = instance->linearDamping;
  639. // Push the return value onto the stack.
  640. lua_pushnumber(state, result);
  641. return 1;
  642. }
  643. }
  644. int lua_PhysicsRigidBodyParameters_linearFactor(lua_State* state)
  645. {
  646. // Validate the number of parameters.
  647. if (lua_gettop(state) > 2)
  648. {
  649. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  650. lua_error(state);
  651. }
  652. PhysicsRigidBody::Parameters* instance = getInstance(state);
  653. if (lua_gettop(state) == 2)
  654. {
  655. // Get parameter 2 off the stack.
  656. ScriptUtil::LuaArray<Vector3> param2 = ScriptUtil::getObjectPointer<Vector3>(2, "Vector3", true);
  657. instance->linearFactor = *param2;
  658. return 0;
  659. }
  660. else
  661. {
  662. void* returnPtr = (void*)new Vector3(instance->linearFactor);
  663. if (returnPtr)
  664. {
  665. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  666. object->instance = returnPtr;
  667. object->owns = true;
  668. luaL_getmetatable(state, "Vector3");
  669. lua_setmetatable(state, -2);
  670. }
  671. else
  672. {
  673. lua_pushnil(state);
  674. }
  675. return 1;
  676. }
  677. }
  678. int lua_PhysicsRigidBodyParameters_mass(lua_State* state)
  679. {
  680. // Validate the number of parameters.
  681. if (lua_gettop(state) > 2)
  682. {
  683. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  684. lua_error(state);
  685. }
  686. PhysicsRigidBody::Parameters* instance = getInstance(state);
  687. if (lua_gettop(state) == 2)
  688. {
  689. // Get parameter 2 off the stack.
  690. float param2 = (float)luaL_checknumber(state, 2);
  691. instance->mass = param2;
  692. return 0;
  693. }
  694. else
  695. {
  696. float result = instance->mass;
  697. // Push the return value onto the stack.
  698. lua_pushnumber(state, result);
  699. return 1;
  700. }
  701. }
  702. int lua_PhysicsRigidBodyParameters_restitution(lua_State* state)
  703. {
  704. // Validate the number of parameters.
  705. if (lua_gettop(state) > 2)
  706. {
  707. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  708. lua_error(state);
  709. }
  710. PhysicsRigidBody::Parameters* instance = getInstance(state);
  711. if (lua_gettop(state) == 2)
  712. {
  713. // Get parameter 2 off the stack.
  714. float param2 = (float)luaL_checknumber(state, 2);
  715. instance->restitution = param2;
  716. return 0;
  717. }
  718. else
  719. {
  720. float result = instance->restitution;
  721. // Push the return value onto the stack.
  722. lua_pushnumber(state, result);
  723. return 1;
  724. }
  725. }
  726. }