MCPcopy Create free account
hub / github.com/BZFlag-Dev/bzflag / GetObstaclesInBox

Method GetObstaclesInBox

src/lua/LuaObstacle.cpp:1316–1354  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1314//============================================================================//
1315
1316int LuaObstacle::GetObstaclesInBox(lua_State* L) {
1317 const fvec3 pos = luaL_checkfvec3(L, 2);
1318 const fvec3 size = luaL_checkfvec3(L, 5);
1319 const float radians = luaL_optfloat(L, 8, 0.0f);
1320
1321 Extents exts;
1322 if (radians == 0.0f) {
1323 exts.mins = pos - fvec3(size.x, size.y, 0.0f);
1324 exts.maxs = pos + fvec3(size.x, size.y, size.z);
1325 }
1326 else {
1327 fvec2 pv(+size.x, +size.y);
1328 fvec2 nv(+size.x, -size.y);
1329 pv.rotate(radians);
1330 nv.rotate(radians);
1331 pv = fvec2(fabsf(pv.x), fabsf(pv.y));
1332 nv = fvec2(fabsf(nv.x), fabsf(nv.y));
1333 const float sx = (pv.x > nv.x) ? pv.x : nv.x;
1334 const float sy = (pv.y > nv.y) ? pv.y : nv.y;
1335 exts.mins = fvec3(pos.x - sx, pos.y - sy, pos.z),
1336 exts.maxs = fvec3(pos.x + sx, pos.y + sy, pos.z + size.z);
1337 }
1338
1339 const ObsList* obsList = COLLISIONMGR.axisBoxTest(exts);
1340 const int listCount = obsList->count;
1341
1342 lua_createtable(L, listCount, 0);
1343 int index = 0;
1344 for (int i = 0; i < listCount; i++) {
1345 const Obstacle* obs = obsList->list[i];
1346 if (obs->inBox(pos, radians, size.x, size.y, size.z)) {
1347 index++;
1348 PushObstacleGUID(L, obs->getGUID());
1349 lua_rawseti(L, -2, index);
1350 }
1351 }
1352
1353 return 1;
1354}
1355
1356
1357int LuaObstacle::ObstacleBoxTest(lua_State* L) {

Callers

nothing calls this directly

Calls 9

luaL_checkfvec3Function · 0.85
luaL_optfloatFunction · 0.85
PushObstacleGUIDFunction · 0.85
axisBoxTestMethod · 0.80
getGUIDMethod · 0.80
lua_createtableFunction · 0.50
lua_rawsetiFunction · 0.50
rotateMethod · 0.45
inBoxMethod · 0.45

Tested by

no test coverage detected