lua_BoundingSphere.cpp 19 KB

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