| 161 | } |
| 162 | |
| 163 | Vec3<float> TileObjectVehicle::getVoxelCentrePosition() const |
| 164 | { |
| 165 | // We could do all the following, but since we always aim at voxelmap's center, |
| 166 | // regardless of which bits are filled or not (only accounting for height) |
| 167 | // it is enough to just offset center according to voxelmap's height |
| 168 | // Leaving the code here though as it may be useful later |
| 169 | /* |
| 170 | auto vtype = this->getVehicle()->type; |
| 171 | auto facing = vtype->getVoxelMapFacing(getDirection()); |
| 172 | auto size = vtype->size.at(facing); |
| 173 | |
| 174 | Vec3<int> voxelCentre = {0, 0, 0}; |
| 175 | for (int x = 0; x < size.x; x++) |
| 176 | { |
| 177 | for (int y = 0; y < size.y; y++) |
| 178 | { |
| 179 | for (int z = 0; z < size.z; z++) |
| 180 | { |
| 181 | voxelCentre += getVoxelMap({x, y, z})->centre; |
| 182 | } |
| 183 | } |
| 184 | } |
| 185 | voxelCentre /= size.x * size.y * size.z; |
| 186 | |
| 187 | auto objPos = this->getCenter(); |
| 188 | objPos -= this->getVoxelOffset(); |
| 189 | return Vec3<float>(objPos.x + (float)voxelCentre.x / map.voxelMapSize.x, |
| 190 | objPos.y + (float)voxelCentre.y / map.voxelMapSize.y, |
| 191 | objPos.z + (float)voxelCentre.z / map.voxelMapSize.z); |
| 192 | */ |
| 193 | |
| 194 | // Simple version: |
| 195 | auto objPos = this->getCenter(); |
| 196 | auto v = getVehicle(); |
| 197 | // Fire at crashed's top or ground's centre |
| 198 | if (v->crashed || v->type->isGround()) |
| 199 | { |
| 200 | return Vec3<float>(objPos.x, objPos.y, objPos.z + (float)v->type->height / 2.0f / 16.0f); |
| 201 | } |
| 202 | // Fire at flyer's centre |
| 203 | else |
| 204 | { |
| 205 | return Vec3<float>(objPos.x, objPos.y, objPos.z); |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | sp<VoxelMap> TileObjectVehicle::getVoxelMap(Vec3<int> mapIndex, bool los) const |
| 210 | { |