lua_Frustum.cpp 22 KB

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