lua_Quaternion.cpp 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219
  1. #include "Base.h"
  2. #include "ScriptController.h"
  3. #include "lua_Quaternion.h"
  4. #include "Base.h"
  5. #include "Quaternion.h"
  6. namespace gameplay
  7. {
  8. void luaRegister_Quaternion()
  9. {
  10. const luaL_Reg lua_members[] =
  11. {
  12. {"conjugate", lua_Quaternion_conjugate},
  13. {"inverse", lua_Quaternion_inverse},
  14. {"isIdentity", lua_Quaternion_isIdentity},
  15. {"isZero", lua_Quaternion_isZero},
  16. {"multiply", lua_Quaternion_multiply},
  17. {"normalize", lua_Quaternion_normalize},
  18. {"set", lua_Quaternion_set},
  19. {"setIdentity", lua_Quaternion_setIdentity},
  20. {"toAxisAngle", lua_Quaternion_toAxisAngle},
  21. {"w", lua_Quaternion_w},
  22. {"x", lua_Quaternion_x},
  23. {"y", lua_Quaternion_y},
  24. {"z", lua_Quaternion_z},
  25. {NULL, NULL}
  26. };
  27. const luaL_Reg lua_statics[] =
  28. {
  29. {"createFromAxisAngle", lua_Quaternion_static_createFromAxisAngle},
  30. {"createFromRotationMatrix", lua_Quaternion_static_createFromRotationMatrix},
  31. {"identity", lua_Quaternion_static_identity},
  32. {"lerp", lua_Quaternion_static_lerp},
  33. {"multiply", lua_Quaternion_static_multiply},
  34. {"slerp", lua_Quaternion_static_slerp},
  35. {"squad", lua_Quaternion_static_squad},
  36. {"zero", lua_Quaternion_static_zero},
  37. {NULL, NULL}
  38. };
  39. std::vector<std::string> scopePath;
  40. ScriptUtil::registerClass("Quaternion", lua_members, lua_Quaternion__init, lua_Quaternion__gc, lua_statics, scopePath);
  41. }
  42. static Quaternion* getInstance(lua_State* state)
  43. {
  44. void* userdata = luaL_checkudata(state, 1, "Quaternion");
  45. luaL_argcheck(state, userdata != NULL, 1, "'Quaternion' expected.");
  46. return (Quaternion*)((ScriptUtil::LuaObject*)userdata)->instance;
  47. }
  48. int lua_Quaternion__gc(lua_State* state)
  49. {
  50. // Get the number of parameters.
  51. int paramCount = lua_gettop(state);
  52. // Attempt to match the parameters to a valid binding.
  53. switch (paramCount)
  54. {
  55. case 1:
  56. {
  57. if ((lua_type(state, 1) == LUA_TUSERDATA))
  58. {
  59. void* userdata = luaL_checkudata(state, 1, "Quaternion");
  60. luaL_argcheck(state, userdata != NULL, 1, "'Quaternion' expected.");
  61. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)userdata;
  62. if (object->owns)
  63. {
  64. Quaternion* instance = (Quaternion*)object->instance;
  65. SAFE_DELETE(instance);
  66. }
  67. return 0;
  68. }
  69. else
  70. {
  71. lua_pushstring(state, "lua_Quaternion__gc - Failed to match the given parameters to a valid function signature.");
  72. lua_error(state);
  73. }
  74. break;
  75. }
  76. default:
  77. {
  78. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  79. lua_error(state);
  80. break;
  81. }
  82. }
  83. return 0;
  84. }
  85. int lua_Quaternion__init(lua_State* state)
  86. {
  87. // Get the number of parameters.
  88. int paramCount = lua_gettop(state);
  89. // Attempt to match the parameters to a valid binding.
  90. switch (paramCount)
  91. {
  92. case 0:
  93. {
  94. void* returnPtr = (void*)new Quaternion();
  95. if (returnPtr)
  96. {
  97. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  98. object->instance = returnPtr;
  99. object->owns = true;
  100. luaL_getmetatable(state, "Quaternion");
  101. lua_setmetatable(state, -2);
  102. }
  103. else
  104. {
  105. lua_pushnil(state);
  106. }
  107. return 1;
  108. break;
  109. }
  110. case 1:
  111. {
  112. if ((lua_type(state, 1) == LUA_TTABLE || lua_type(state, 1) == LUA_TLIGHTUSERDATA))
  113. {
  114. // Get parameter 1 off the stack.
  115. ScriptUtil::LuaArray<float> param1 = ScriptUtil::getFloatPointer(1);
  116. void* returnPtr = (void*)new Quaternion(param1);
  117. if (returnPtr)
  118. {
  119. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  120. object->instance = returnPtr;
  121. object->owns = true;
  122. luaL_getmetatable(state, "Quaternion");
  123. lua_setmetatable(state, -2);
  124. }
  125. else
  126. {
  127. lua_pushnil(state);
  128. }
  129. return 1;
  130. }
  131. else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
  132. {
  133. // Get parameter 1 off the stack.
  134. ScriptUtil::LuaArray<Matrix> param1 = ScriptUtil::getObjectPointer<Matrix>(1, "Matrix", true);
  135. void* returnPtr = (void*)new Quaternion(*param1);
  136. if (returnPtr)
  137. {
  138. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  139. object->instance = returnPtr;
  140. object->owns = true;
  141. luaL_getmetatable(state, "Quaternion");
  142. lua_setmetatable(state, -2);
  143. }
  144. else
  145. {
  146. lua_pushnil(state);
  147. }
  148. return 1;
  149. }
  150. else if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL))
  151. {
  152. // Get parameter 1 off the stack.
  153. ScriptUtil::LuaArray<Quaternion> param1 = ScriptUtil::getObjectPointer<Quaternion>(1, "Quaternion", true);
  154. void* returnPtr = (void*)new Quaternion(*param1);
  155. if (returnPtr)
  156. {
  157. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  158. object->instance = returnPtr;
  159. object->owns = true;
  160. luaL_getmetatable(state, "Quaternion");
  161. lua_setmetatable(state, -2);
  162. }
  163. else
  164. {
  165. lua_pushnil(state);
  166. }
  167. return 1;
  168. }
  169. else
  170. {
  171. lua_pushstring(state, "lua_Quaternion__init - Failed to match the given parameters to a valid function signature.");
  172. lua_error(state);
  173. }
  174. break;
  175. }
  176. case 2:
  177. {
  178. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  179. lua_type(state, 2) == LUA_TNUMBER)
  180. {
  181. // Get parameter 1 off the stack.
  182. ScriptUtil::LuaArray<Vector3> param1 = ScriptUtil::getObjectPointer<Vector3>(1, "Vector3", true);
  183. // Get parameter 2 off the stack.
  184. float param2 = (float)luaL_checknumber(state, 2);
  185. void* returnPtr = (void*)new Quaternion(*param1, param2);
  186. if (returnPtr)
  187. {
  188. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  189. object->instance = returnPtr;
  190. object->owns = true;
  191. luaL_getmetatable(state, "Quaternion");
  192. lua_setmetatable(state, -2);
  193. }
  194. else
  195. {
  196. lua_pushnil(state);
  197. }
  198. return 1;
  199. }
  200. else
  201. {
  202. lua_pushstring(state, "lua_Quaternion__init - Failed to match the given parameters to a valid function signature.");
  203. lua_error(state);
  204. }
  205. break;
  206. }
  207. case 4:
  208. {
  209. if (lua_type(state, 1) == LUA_TNUMBER &&
  210. lua_type(state, 2) == LUA_TNUMBER &&
  211. lua_type(state, 3) == LUA_TNUMBER &&
  212. lua_type(state, 4) == LUA_TNUMBER)
  213. {
  214. // Get parameter 1 off the stack.
  215. float param1 = (float)luaL_checknumber(state, 1);
  216. // Get parameter 2 off the stack.
  217. float param2 = (float)luaL_checknumber(state, 2);
  218. // Get parameter 3 off the stack.
  219. float param3 = (float)luaL_checknumber(state, 3);
  220. // Get parameter 4 off the stack.
  221. float param4 = (float)luaL_checknumber(state, 4);
  222. void* returnPtr = (void*)new Quaternion(param1, param2, param3, param4);
  223. if (returnPtr)
  224. {
  225. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  226. object->instance = returnPtr;
  227. object->owns = true;
  228. luaL_getmetatable(state, "Quaternion");
  229. lua_setmetatable(state, -2);
  230. }
  231. else
  232. {
  233. lua_pushnil(state);
  234. }
  235. return 1;
  236. }
  237. else
  238. {
  239. lua_pushstring(state, "lua_Quaternion__init - Failed to match the given parameters to a valid function signature.");
  240. lua_error(state);
  241. }
  242. break;
  243. }
  244. default:
  245. {
  246. lua_pushstring(state, "Invalid number of parameters (expected 0, 1, 2 or 4).");
  247. lua_error(state);
  248. break;
  249. }
  250. }
  251. return 0;
  252. }
  253. int lua_Quaternion_conjugate(lua_State* state)
  254. {
  255. // Get the number of parameters.
  256. int paramCount = lua_gettop(state);
  257. // Attempt to match the parameters to a valid binding.
  258. switch (paramCount)
  259. {
  260. case 1:
  261. {
  262. if ((lua_type(state, 1) == LUA_TUSERDATA))
  263. {
  264. Quaternion* instance = getInstance(state);
  265. instance->conjugate();
  266. return 0;
  267. }
  268. else
  269. {
  270. lua_pushstring(state, "lua_Quaternion_conjugate - Failed to match the given parameters to a valid function signature.");
  271. lua_error(state);
  272. }
  273. break;
  274. }
  275. case 2:
  276. {
  277. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  278. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL))
  279. {
  280. // Get parameter 1 off the stack.
  281. ScriptUtil::LuaArray<Quaternion> param1 = ScriptUtil::getObjectPointer<Quaternion>(2, "Quaternion", false);
  282. Quaternion* instance = getInstance(state);
  283. instance->conjugate(param1);
  284. return 0;
  285. }
  286. else
  287. {
  288. lua_pushstring(state, "lua_Quaternion_conjugate - Failed to match the given parameters to a valid function signature.");
  289. lua_error(state);
  290. }
  291. break;
  292. }
  293. default:
  294. {
  295. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  296. lua_error(state);
  297. break;
  298. }
  299. }
  300. return 0;
  301. }
  302. int lua_Quaternion_inverse(lua_State* state)
  303. {
  304. // Get the number of parameters.
  305. int paramCount = lua_gettop(state);
  306. // Attempt to match the parameters to a valid binding.
  307. switch (paramCount)
  308. {
  309. case 1:
  310. {
  311. if ((lua_type(state, 1) == LUA_TUSERDATA))
  312. {
  313. Quaternion* instance = getInstance(state);
  314. bool result = instance->inverse();
  315. // Push the return value onto the stack.
  316. lua_pushboolean(state, result);
  317. return 1;
  318. }
  319. else
  320. {
  321. lua_pushstring(state, "lua_Quaternion_inverse - Failed to match the given parameters to a valid function signature.");
  322. lua_error(state);
  323. }
  324. break;
  325. }
  326. case 2:
  327. {
  328. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  329. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL))
  330. {
  331. // Get parameter 1 off the stack.
  332. ScriptUtil::LuaArray<Quaternion> param1 = ScriptUtil::getObjectPointer<Quaternion>(2, "Quaternion", false);
  333. Quaternion* instance = getInstance(state);
  334. bool result = instance->inverse(param1);
  335. // Push the return value onto the stack.
  336. lua_pushboolean(state, result);
  337. return 1;
  338. }
  339. else
  340. {
  341. lua_pushstring(state, "lua_Quaternion_inverse - Failed to match the given parameters to a valid function signature.");
  342. lua_error(state);
  343. }
  344. break;
  345. }
  346. default:
  347. {
  348. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  349. lua_error(state);
  350. break;
  351. }
  352. }
  353. return 0;
  354. }
  355. int lua_Quaternion_isIdentity(lua_State* state)
  356. {
  357. // Get the number of parameters.
  358. int paramCount = lua_gettop(state);
  359. // Attempt to match the parameters to a valid binding.
  360. switch (paramCount)
  361. {
  362. case 1:
  363. {
  364. if ((lua_type(state, 1) == LUA_TUSERDATA))
  365. {
  366. Quaternion* instance = getInstance(state);
  367. bool result = instance->isIdentity();
  368. // Push the return value onto the stack.
  369. lua_pushboolean(state, result);
  370. return 1;
  371. }
  372. else
  373. {
  374. lua_pushstring(state, "lua_Quaternion_isIdentity - Failed to match the given parameters to a valid function signature.");
  375. lua_error(state);
  376. }
  377. break;
  378. }
  379. default:
  380. {
  381. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  382. lua_error(state);
  383. break;
  384. }
  385. }
  386. return 0;
  387. }
  388. int lua_Quaternion_isZero(lua_State* state)
  389. {
  390. // Get the number of parameters.
  391. int paramCount = lua_gettop(state);
  392. // Attempt to match the parameters to a valid binding.
  393. switch (paramCount)
  394. {
  395. case 1:
  396. {
  397. if ((lua_type(state, 1) == LUA_TUSERDATA))
  398. {
  399. Quaternion* instance = getInstance(state);
  400. bool result = instance->isZero();
  401. // Push the return value onto the stack.
  402. lua_pushboolean(state, result);
  403. return 1;
  404. }
  405. else
  406. {
  407. lua_pushstring(state, "lua_Quaternion_isZero - Failed to match the given parameters to a valid function signature.");
  408. lua_error(state);
  409. }
  410. break;
  411. }
  412. default:
  413. {
  414. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  415. lua_error(state);
  416. break;
  417. }
  418. }
  419. return 0;
  420. }
  421. int lua_Quaternion_multiply(lua_State* state)
  422. {
  423. // Get the number of parameters.
  424. int paramCount = lua_gettop(state);
  425. // Attempt to match the parameters to a valid binding.
  426. switch (paramCount)
  427. {
  428. case 2:
  429. {
  430. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  431. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
  432. {
  433. // Get parameter 1 off the stack.
  434. ScriptUtil::LuaArray<Quaternion> param1 = ScriptUtil::getObjectPointer<Quaternion>(2, "Quaternion", true);
  435. Quaternion* instance = getInstance(state);
  436. instance->multiply(*param1);
  437. return 0;
  438. }
  439. else
  440. {
  441. lua_pushstring(state, "lua_Quaternion_multiply - Failed to match the given parameters to a valid function signature.");
  442. lua_error(state);
  443. }
  444. break;
  445. }
  446. default:
  447. {
  448. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  449. lua_error(state);
  450. break;
  451. }
  452. }
  453. return 0;
  454. }
  455. int lua_Quaternion_normalize(lua_State* state)
  456. {
  457. // Get the number of parameters.
  458. int paramCount = lua_gettop(state);
  459. // Attempt to match the parameters to a valid binding.
  460. switch (paramCount)
  461. {
  462. case 1:
  463. {
  464. if ((lua_type(state, 1) == LUA_TUSERDATA))
  465. {
  466. Quaternion* instance = getInstance(state);
  467. instance->normalize();
  468. return 0;
  469. }
  470. else
  471. {
  472. lua_pushstring(state, "lua_Quaternion_normalize - Failed to match the given parameters to a valid function signature.");
  473. lua_error(state);
  474. }
  475. break;
  476. }
  477. case 2:
  478. {
  479. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  480. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL))
  481. {
  482. // Get parameter 1 off the stack.
  483. ScriptUtil::LuaArray<Quaternion> param1 = ScriptUtil::getObjectPointer<Quaternion>(2, "Quaternion", false);
  484. Quaternion* instance = getInstance(state);
  485. instance->normalize(param1);
  486. return 0;
  487. }
  488. else
  489. {
  490. lua_pushstring(state, "lua_Quaternion_normalize - Failed to match the given parameters to a valid function signature.");
  491. lua_error(state);
  492. }
  493. break;
  494. }
  495. default:
  496. {
  497. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  498. lua_error(state);
  499. break;
  500. }
  501. }
  502. return 0;
  503. }
  504. int lua_Quaternion_set(lua_State* state)
  505. {
  506. // Get the number of parameters.
  507. int paramCount = lua_gettop(state);
  508. // Attempt to match the parameters to a valid binding.
  509. switch (paramCount)
  510. {
  511. case 2:
  512. {
  513. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  514. (lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TLIGHTUSERDATA))
  515. {
  516. // Get parameter 1 off the stack.
  517. ScriptUtil::LuaArray<float> param1 = ScriptUtil::getFloatPointer(2);
  518. Quaternion* instance = getInstance(state);
  519. instance->set(param1);
  520. return 0;
  521. }
  522. else if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  523. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
  524. {
  525. // Get parameter 1 off the stack.
  526. ScriptUtil::LuaArray<Matrix> param1 = ScriptUtil::getObjectPointer<Matrix>(2, "Matrix", true);
  527. Quaternion* instance = getInstance(state);
  528. instance->set(*param1);
  529. return 0;
  530. }
  531. else if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  532. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL))
  533. {
  534. // Get parameter 1 off the stack.
  535. ScriptUtil::LuaArray<Quaternion> param1 = ScriptUtil::getObjectPointer<Quaternion>(2, "Quaternion", true);
  536. Quaternion* instance = getInstance(state);
  537. instance->set(*param1);
  538. return 0;
  539. }
  540. else
  541. {
  542. lua_pushstring(state, "lua_Quaternion_set - Failed to match the given parameters to a valid function signature.");
  543. lua_error(state);
  544. }
  545. break;
  546. }
  547. case 3:
  548. {
  549. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  550. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
  551. lua_type(state, 3) == LUA_TNUMBER)
  552. {
  553. // Get parameter 1 off the stack.
  554. ScriptUtil::LuaArray<Vector3> param1 = ScriptUtil::getObjectPointer<Vector3>(2, "Vector3", true);
  555. // Get parameter 2 off the stack.
  556. float param2 = (float)luaL_checknumber(state, 3);
  557. Quaternion* instance = getInstance(state);
  558. instance->set(*param1, param2);
  559. return 0;
  560. }
  561. else
  562. {
  563. lua_pushstring(state, "lua_Quaternion_set - Failed to match the given parameters to a valid function signature.");
  564. lua_error(state);
  565. }
  566. break;
  567. }
  568. case 5:
  569. {
  570. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  571. lua_type(state, 2) == LUA_TNUMBER &&
  572. lua_type(state, 3) == LUA_TNUMBER &&
  573. lua_type(state, 4) == LUA_TNUMBER &&
  574. lua_type(state, 5) == LUA_TNUMBER)
  575. {
  576. // Get parameter 1 off the stack.
  577. float param1 = (float)luaL_checknumber(state, 2);
  578. // Get parameter 2 off the stack.
  579. float param2 = (float)luaL_checknumber(state, 3);
  580. // Get parameter 3 off the stack.
  581. float param3 = (float)luaL_checknumber(state, 4);
  582. // Get parameter 4 off the stack.
  583. float param4 = (float)luaL_checknumber(state, 5);
  584. Quaternion* instance = getInstance(state);
  585. instance->set(param1, param2, param3, param4);
  586. return 0;
  587. }
  588. else
  589. {
  590. lua_pushstring(state, "lua_Quaternion_set - Failed to match the given parameters to a valid function signature.");
  591. lua_error(state);
  592. }
  593. break;
  594. }
  595. default:
  596. {
  597. lua_pushstring(state, "Invalid number of parameters (expected 2, 3 or 5).");
  598. lua_error(state);
  599. break;
  600. }
  601. }
  602. return 0;
  603. }
  604. int lua_Quaternion_setIdentity(lua_State* state)
  605. {
  606. // Get the number of parameters.
  607. int paramCount = lua_gettop(state);
  608. // Attempt to match the parameters to a valid binding.
  609. switch (paramCount)
  610. {
  611. case 1:
  612. {
  613. if ((lua_type(state, 1) == LUA_TUSERDATA))
  614. {
  615. Quaternion* instance = getInstance(state);
  616. instance->setIdentity();
  617. return 0;
  618. }
  619. else
  620. {
  621. lua_pushstring(state, "lua_Quaternion_setIdentity - Failed to match the given parameters to a valid function signature.");
  622. lua_error(state);
  623. }
  624. break;
  625. }
  626. default:
  627. {
  628. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  629. lua_error(state);
  630. break;
  631. }
  632. }
  633. return 0;
  634. }
  635. int lua_Quaternion_static_createFromAxisAngle(lua_State* state)
  636. {
  637. // Get the number of parameters.
  638. int paramCount = lua_gettop(state);
  639. // Attempt to match the parameters to a valid binding.
  640. switch (paramCount)
  641. {
  642. case 3:
  643. {
  644. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  645. lua_type(state, 2) == LUA_TNUMBER &&
  646. (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TTABLE || lua_type(state, 3) == LUA_TNIL))
  647. {
  648. // Get parameter 1 off the stack.
  649. ScriptUtil::LuaArray<Vector3> param1 = ScriptUtil::getObjectPointer<Vector3>(1, "Vector3", true);
  650. // Get parameter 2 off the stack.
  651. float param2 = (float)luaL_checknumber(state, 2);
  652. // Get parameter 3 off the stack.
  653. ScriptUtil::LuaArray<Quaternion> param3 = ScriptUtil::getObjectPointer<Quaternion>(3, "Quaternion", false);
  654. Quaternion::createFromAxisAngle(*param1, param2, param3);
  655. return 0;
  656. }
  657. else
  658. {
  659. lua_pushstring(state, "lua_Quaternion_static_createFromAxisAngle - Failed to match the given parameters to a valid function signature.");
  660. lua_error(state);
  661. }
  662. break;
  663. }
  664. default:
  665. {
  666. lua_pushstring(state, "Invalid number of parameters (expected 3).");
  667. lua_error(state);
  668. break;
  669. }
  670. }
  671. return 0;
  672. }
  673. int lua_Quaternion_static_createFromRotationMatrix(lua_State* state)
  674. {
  675. // Get the number of parameters.
  676. int paramCount = lua_gettop(state);
  677. // Attempt to match the parameters to a valid binding.
  678. switch (paramCount)
  679. {
  680. case 2:
  681. {
  682. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  683. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL))
  684. {
  685. // Get parameter 1 off the stack.
  686. ScriptUtil::LuaArray<Matrix> param1 = ScriptUtil::getObjectPointer<Matrix>(1, "Matrix", true);
  687. // Get parameter 2 off the stack.
  688. ScriptUtil::LuaArray<Quaternion> param2 = ScriptUtil::getObjectPointer<Quaternion>(2, "Quaternion", false);
  689. Quaternion::createFromRotationMatrix(*param1, param2);
  690. return 0;
  691. }
  692. else
  693. {
  694. lua_pushstring(state, "lua_Quaternion_static_createFromRotationMatrix - Failed to match the given parameters to a valid function signature.");
  695. lua_error(state);
  696. }
  697. break;
  698. }
  699. default:
  700. {
  701. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  702. lua_error(state);
  703. break;
  704. }
  705. }
  706. return 0;
  707. }
  708. int lua_Quaternion_static_identity(lua_State* state)
  709. {
  710. // Get the number of parameters.
  711. int paramCount = lua_gettop(state);
  712. // Attempt to match the parameters to a valid binding.
  713. switch (paramCount)
  714. {
  715. case 0:
  716. {
  717. void* returnPtr = (void*)&(Quaternion::identity());
  718. if (returnPtr)
  719. {
  720. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  721. object->instance = returnPtr;
  722. object->owns = false;
  723. luaL_getmetatable(state, "Quaternion");
  724. lua_setmetatable(state, -2);
  725. }
  726. else
  727. {
  728. lua_pushnil(state);
  729. }
  730. return 1;
  731. break;
  732. }
  733. default:
  734. {
  735. lua_pushstring(state, "Invalid number of parameters (expected 0).");
  736. lua_error(state);
  737. break;
  738. }
  739. }
  740. return 0;
  741. }
  742. int lua_Quaternion_static_lerp(lua_State* state)
  743. {
  744. // Get the number of parameters.
  745. int paramCount = lua_gettop(state);
  746. // Attempt to match the parameters to a valid binding.
  747. switch (paramCount)
  748. {
  749. case 4:
  750. {
  751. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  752. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
  753. lua_type(state, 3) == LUA_TNUMBER &&
  754. (lua_type(state, 4) == LUA_TUSERDATA || lua_type(state, 4) == LUA_TTABLE || lua_type(state, 4) == LUA_TNIL))
  755. {
  756. // Get parameter 1 off the stack.
  757. ScriptUtil::LuaArray<Quaternion> param1 = ScriptUtil::getObjectPointer<Quaternion>(1, "Quaternion", true);
  758. // Get parameter 2 off the stack.
  759. ScriptUtil::LuaArray<Quaternion> param2 = ScriptUtil::getObjectPointer<Quaternion>(2, "Quaternion", true);
  760. // Get parameter 3 off the stack.
  761. float param3 = (float)luaL_checknumber(state, 3);
  762. // Get parameter 4 off the stack.
  763. ScriptUtil::LuaArray<Quaternion> param4 = ScriptUtil::getObjectPointer<Quaternion>(4, "Quaternion", false);
  764. Quaternion::lerp(*param1, *param2, param3, param4);
  765. return 0;
  766. }
  767. else
  768. {
  769. lua_pushstring(state, "lua_Quaternion_static_lerp - Failed to match the given parameters to a valid function signature.");
  770. lua_error(state);
  771. }
  772. break;
  773. }
  774. default:
  775. {
  776. lua_pushstring(state, "Invalid number of parameters (expected 4).");
  777. lua_error(state);
  778. break;
  779. }
  780. }
  781. return 0;
  782. }
  783. int lua_Quaternion_static_multiply(lua_State* state)
  784. {
  785. // Get the number of parameters.
  786. int paramCount = lua_gettop(state);
  787. // Attempt to match the parameters to a valid binding.
  788. switch (paramCount)
  789. {
  790. case 3:
  791. {
  792. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  793. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
  794. (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TTABLE || lua_type(state, 3) == LUA_TNIL))
  795. {
  796. // Get parameter 1 off the stack.
  797. ScriptUtil::LuaArray<Quaternion> param1 = ScriptUtil::getObjectPointer<Quaternion>(1, "Quaternion", true);
  798. // Get parameter 2 off the stack.
  799. ScriptUtil::LuaArray<Quaternion> param2 = ScriptUtil::getObjectPointer<Quaternion>(2, "Quaternion", true);
  800. // Get parameter 3 off the stack.
  801. ScriptUtil::LuaArray<Quaternion> param3 = ScriptUtil::getObjectPointer<Quaternion>(3, "Quaternion", false);
  802. Quaternion::multiply(*param1, *param2, param3);
  803. return 0;
  804. }
  805. else
  806. {
  807. lua_pushstring(state, "lua_Quaternion_static_multiply - Failed to match the given parameters to a valid function signature.");
  808. lua_error(state);
  809. }
  810. break;
  811. }
  812. default:
  813. {
  814. lua_pushstring(state, "Invalid number of parameters (expected 3).");
  815. lua_error(state);
  816. break;
  817. }
  818. }
  819. return 0;
  820. }
  821. int lua_Quaternion_static_slerp(lua_State* state)
  822. {
  823. // Get the number of parameters.
  824. int paramCount = lua_gettop(state);
  825. // Attempt to match the parameters to a valid binding.
  826. switch (paramCount)
  827. {
  828. case 4:
  829. {
  830. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  831. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
  832. lua_type(state, 3) == LUA_TNUMBER &&
  833. (lua_type(state, 4) == LUA_TUSERDATA || lua_type(state, 4) == LUA_TTABLE || lua_type(state, 4) == LUA_TNIL))
  834. {
  835. // Get parameter 1 off the stack.
  836. ScriptUtil::LuaArray<Quaternion> param1 = ScriptUtil::getObjectPointer<Quaternion>(1, "Quaternion", true);
  837. // Get parameter 2 off the stack.
  838. ScriptUtil::LuaArray<Quaternion> param2 = ScriptUtil::getObjectPointer<Quaternion>(2, "Quaternion", true);
  839. // Get parameter 3 off the stack.
  840. float param3 = (float)luaL_checknumber(state, 3);
  841. // Get parameter 4 off the stack.
  842. ScriptUtil::LuaArray<Quaternion> param4 = ScriptUtil::getObjectPointer<Quaternion>(4, "Quaternion", false);
  843. Quaternion::slerp(*param1, *param2, param3, param4);
  844. return 0;
  845. }
  846. else
  847. {
  848. lua_pushstring(state, "lua_Quaternion_static_slerp - Failed to match the given parameters to a valid function signature.");
  849. lua_error(state);
  850. }
  851. break;
  852. }
  853. default:
  854. {
  855. lua_pushstring(state, "Invalid number of parameters (expected 4).");
  856. lua_error(state);
  857. break;
  858. }
  859. }
  860. return 0;
  861. }
  862. int lua_Quaternion_static_squad(lua_State* state)
  863. {
  864. // Get the number of parameters.
  865. int paramCount = lua_gettop(state);
  866. // Attempt to match the parameters to a valid binding.
  867. switch (paramCount)
  868. {
  869. case 6:
  870. {
  871. if ((lua_type(state, 1) == LUA_TUSERDATA || lua_type(state, 1) == LUA_TNIL) &&
  872. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TNIL) &&
  873. (lua_type(state, 3) == LUA_TUSERDATA || lua_type(state, 3) == LUA_TNIL) &&
  874. (lua_type(state, 4) == LUA_TUSERDATA || lua_type(state, 4) == LUA_TNIL) &&
  875. lua_type(state, 5) == LUA_TNUMBER &&
  876. (lua_type(state, 6) == LUA_TUSERDATA || lua_type(state, 6) == LUA_TTABLE || lua_type(state, 6) == LUA_TNIL))
  877. {
  878. // Get parameter 1 off the stack.
  879. ScriptUtil::LuaArray<Quaternion> param1 = ScriptUtil::getObjectPointer<Quaternion>(1, "Quaternion", true);
  880. // Get parameter 2 off the stack.
  881. ScriptUtil::LuaArray<Quaternion> param2 = ScriptUtil::getObjectPointer<Quaternion>(2, "Quaternion", true);
  882. // Get parameter 3 off the stack.
  883. ScriptUtil::LuaArray<Quaternion> param3 = ScriptUtil::getObjectPointer<Quaternion>(3, "Quaternion", true);
  884. // Get parameter 4 off the stack.
  885. ScriptUtil::LuaArray<Quaternion> param4 = ScriptUtil::getObjectPointer<Quaternion>(4, "Quaternion", true);
  886. // Get parameter 5 off the stack.
  887. float param5 = (float)luaL_checknumber(state, 5);
  888. // Get parameter 6 off the stack.
  889. ScriptUtil::LuaArray<Quaternion> param6 = ScriptUtil::getObjectPointer<Quaternion>(6, "Quaternion", false);
  890. Quaternion::squad(*param1, *param2, *param3, *param4, param5, param6);
  891. return 0;
  892. }
  893. else
  894. {
  895. lua_pushstring(state, "lua_Quaternion_static_squad - Failed to match the given parameters to a valid function signature.");
  896. lua_error(state);
  897. }
  898. break;
  899. }
  900. default:
  901. {
  902. lua_pushstring(state, "Invalid number of parameters (expected 6).");
  903. lua_error(state);
  904. break;
  905. }
  906. }
  907. return 0;
  908. }
  909. int lua_Quaternion_static_zero(lua_State* state)
  910. {
  911. // Get the number of parameters.
  912. int paramCount = lua_gettop(state);
  913. // Attempt to match the parameters to a valid binding.
  914. switch (paramCount)
  915. {
  916. case 0:
  917. {
  918. void* returnPtr = (void*)&(Quaternion::zero());
  919. if (returnPtr)
  920. {
  921. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(ScriptUtil::LuaObject));
  922. object->instance = returnPtr;
  923. object->owns = false;
  924. luaL_getmetatable(state, "Quaternion");
  925. lua_setmetatable(state, -2);
  926. }
  927. else
  928. {
  929. lua_pushnil(state);
  930. }
  931. return 1;
  932. break;
  933. }
  934. default:
  935. {
  936. lua_pushstring(state, "Invalid number of parameters (expected 0).");
  937. lua_error(state);
  938. break;
  939. }
  940. }
  941. return 0;
  942. }
  943. int lua_Quaternion_toAxisAngle(lua_State* state)
  944. {
  945. // Get the number of parameters.
  946. int paramCount = lua_gettop(state);
  947. // Attempt to match the parameters to a valid binding.
  948. switch (paramCount)
  949. {
  950. case 2:
  951. {
  952. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  953. (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL))
  954. {
  955. // Get parameter 1 off the stack.
  956. ScriptUtil::LuaArray<Vector3> param1 = ScriptUtil::getObjectPointer<Vector3>(2, "Vector3", false);
  957. Quaternion* instance = getInstance(state);
  958. float result = instance->toAxisAngle(param1);
  959. // Push the return value onto the stack.
  960. lua_pushnumber(state, result);
  961. return 1;
  962. }
  963. else
  964. {
  965. lua_pushstring(state, "lua_Quaternion_toAxisAngle - Failed to match the given parameters to a valid function signature.");
  966. lua_error(state);
  967. }
  968. break;
  969. }
  970. default:
  971. {
  972. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  973. lua_error(state);
  974. break;
  975. }
  976. }
  977. return 0;
  978. }
  979. int lua_Quaternion_w(lua_State* state)
  980. {
  981. // Validate the number of parameters.
  982. if (lua_gettop(state) > 2)
  983. {
  984. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  985. lua_error(state);
  986. }
  987. Quaternion* instance = getInstance(state);
  988. if (lua_gettop(state) == 2)
  989. {
  990. // Get parameter 2 off the stack.
  991. float param2 = (float)luaL_checknumber(state, 2);
  992. instance->w = param2;
  993. return 0;
  994. }
  995. else
  996. {
  997. float result = instance->w;
  998. // Push the return value onto the stack.
  999. lua_pushnumber(state, result);
  1000. return 1;
  1001. }
  1002. }
  1003. int lua_Quaternion_x(lua_State* state)
  1004. {
  1005. // Validate the number of parameters.
  1006. if (lua_gettop(state) > 2)
  1007. {
  1008. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  1009. lua_error(state);
  1010. }
  1011. Quaternion* instance = getInstance(state);
  1012. if (lua_gettop(state) == 2)
  1013. {
  1014. // Get parameter 2 off the stack.
  1015. float param2 = (float)luaL_checknumber(state, 2);
  1016. instance->x = param2;
  1017. return 0;
  1018. }
  1019. else
  1020. {
  1021. float result = instance->x;
  1022. // Push the return value onto the stack.
  1023. lua_pushnumber(state, result);
  1024. return 1;
  1025. }
  1026. }
  1027. int lua_Quaternion_y(lua_State* state)
  1028. {
  1029. // Validate the number of parameters.
  1030. if (lua_gettop(state) > 2)
  1031. {
  1032. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  1033. lua_error(state);
  1034. }
  1035. Quaternion* instance = getInstance(state);
  1036. if (lua_gettop(state) == 2)
  1037. {
  1038. // Get parameter 2 off the stack.
  1039. float param2 = (float)luaL_checknumber(state, 2);
  1040. instance->y = param2;
  1041. return 0;
  1042. }
  1043. else
  1044. {
  1045. float result = instance->y;
  1046. // Push the return value onto the stack.
  1047. lua_pushnumber(state, result);
  1048. return 1;
  1049. }
  1050. }
  1051. int lua_Quaternion_z(lua_State* state)
  1052. {
  1053. // Validate the number of parameters.
  1054. if (lua_gettop(state) > 2)
  1055. {
  1056. lua_pushstring(state, "Invalid number of parameters (expected 1 or 2).");
  1057. lua_error(state);
  1058. }
  1059. Quaternion* instance = getInstance(state);
  1060. if (lua_gettop(state) == 2)
  1061. {
  1062. // Get parameter 2 off the stack.
  1063. float param2 = (float)luaL_checknumber(state, 2);
  1064. instance->z = param2;
  1065. return 0;
  1066. }
  1067. else
  1068. {
  1069. float result = instance->z;
  1070. // Push the return value onto the stack.
  1071. lua_pushnumber(state, result);
  1072. return 1;
  1073. }
  1074. }
  1075. }