2
0

lua_BoundingSphere.cpp 19 KB

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