lua_BoundingSphere.cpp 22 KB

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