lua_Quaternion.cpp 40 KB

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