0x004B103C
| 221 | |
| 222 | // 0x004B103C |
| 223 | static void paintBody(PaintSession& session, VehicleBody* body) |
| 224 | { |
| 225 | auto* vehObject = ObjectManager::get<VehicleObject>(body->objectId); |
| 226 | if (body->objectSpriteType == SpriteIndex::null) |
| 227 | { |
| 228 | return; |
| 229 | } |
| 230 | |
| 231 | auto& sprite = vehObject->bodySprites[body->objectSpriteType]; |
| 232 | uint8_t yaw = (body->spriteYaw + (session.getRotation() << 4)) & 0x3F; |
| 233 | auto originalYaw = yaw; // edi |
| 234 | auto pitch = body->spritePitch; |
| 235 | |
| 236 | if (body->has38Flags(Flags38::isReversed)) |
| 237 | { |
| 238 | yaw ^= (1 << 5); |
| 239 | pitch = kReversePitch[static_cast<uint8_t>(body->spritePitch)]; |
| 240 | } |
| 241 | |
| 242 | uint32_t bodyImageIndex = getBodyImageIndex(sprite, pitch, yaw, body->animationFrame, body->cargoFrame); |
| 243 | |
| 244 | std::optional<uint32_t> brakingImageIndex = {}; |
| 245 | if (sprite.hasFlags(BodySpriteFlags::hasBrakingLights)) |
| 246 | { |
| 247 | brakingImageIndex = getBrakingImageIndex(sprite, pitch, yaw); |
| 248 | } |
| 249 | |
| 250 | World::Pos3 offsets = { 0, 0, body->position.z }; |
| 251 | World::Pos3 boundBoxOffsets; |
| 252 | World::Pos3 boundBoxSize; |
| 253 | if ((body->getTransportMode() == TransportMode::air) || (body->getTransportMode() == TransportMode::water)) |
| 254 | { |
| 255 | boundBoxOffsets = { -8, -8, static_cast<int16_t>(body->position.z + 11) }; |
| 256 | boundBoxSize = { 48, 48, 15 }; |
| 257 | } |
| 258 | else |
| 259 | { |
| 260 | auto& componentObject = vehObject->carComponents[body->bodyIndex]; |
| 261 | auto overhangLength = componentObject.frontBogiePosition - componentObject.backBogiePosition; |
| 262 | if (body->has38Flags(Flags38::isReversed)) |
| 263 | { |
| 264 | overhangLength = -overhangLength; |
| 265 | } |
| 266 | |
| 267 | if (componentObject.bodySpriteInd & SpriteIndex::isReversed) |
| 268 | { |
| 269 | overhangLength = -overhangLength; |
| 270 | } |
| 271 | |
| 272 | const auto overhangOffset = Math::Trigonometry::computeXYVector(overhangLength, originalYaw) / 8; |
| 273 | boundBoxOffsets.x = overhangOffset.x; |
| 274 | boundBoxOffsets.y = overhangOffset.y; |
| 275 | const auto bodyLength = sprite.halfLength * 2 - 4; |
| 276 | originalYaw &= 0x1F; |
| 277 | const auto& bboxFactors = kBoundingBoxFactorsByYaw[originalYaw]; |
| 278 | boundBoxOffsets.x += (bboxFactors.xOffsetFactor * bodyLength) >> 8; |
| 279 | boundBoxOffsets.y += (bboxFactors.yOffsetFactor * bodyLength) >> 8; |
| 280 | boundBoxOffsets.z = body->position.z + 11; |
no test coverage detected