MCPcopy Create free account
hub / github.com/OpenApoc/OpenApoc / getVoxelCentrePosition

Method getVoxelCentrePosition

game/state/tilemap/tileobject_battleunit.cpp:367–402  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

365}
366
367Vec3<float> TileObjectBattleUnit::getVoxelCentrePosition() const
368{
369 // We could do all the following, but since we always aim at voxelmap's center,
370 // regardless of which bits are filled or not (only accounting for height)
371 // it is enough to just offset center according to voxelmap's height
372 // Leaving the code here though as it may be useful later
373 /*
374 auto u = this->getUnit();
375 auto size = u->agent->type->bodyType->size.at(u->current_body_state).at(u->facing);
376
377 Vec3<int> voxelCentre = {0, 0, 0};
378 for (int x = 0; x < size.x; x++)
379 {
380 for (int y = 0; y < size.y; y++)
381 {
382 for (int z = 0; z < size.z; z++)
383 {
384 voxelCentre += getVoxelMap({x, y, z})->centre;
385 }
386 }
387 }
388 voxelCentre /= size.x * size.y * size.z;
389
390 auto objPos = this->getCenter();
391 objPos -= this->getVoxelOffset();
392 return Vec3<float>(objPos.x + (float)voxelCentre.x / map.voxelMapSize.x,
393 objPos.y + (float)voxelCentre.y / map.voxelMapSize.y,
394 objPos.z + (float)voxelCentre.z / map.voxelMapSize.z);
395 */
396
397 // Simple version:
398 auto objPos = this->getCenter();
399 return Vec3<float>(objPos.x, objPos.y,
400 objPos.z - getVoxelOffset().z +
401 (float)getUnit()->getCurrentHeight() / 2.0f / 40.0f);
402}
403
404sp<VoxelMap> TileObjectBattleUnit::getVoxelMap(Vec3<int> mapIndex, bool) const
405{

Callers

nothing calls this directly

Calls 2

getCenterMethod · 0.80
getCurrentHeightMethod · 0.80

Tested by

no test coverage detected