| 251 | } |
| 252 | |
| 253 | void TestForObjectOnLedge(ItemInfo* item, CollisionInfo* coll) |
| 254 | { |
| 255 | auto bbox = GameBoundingBox(item).ToBoundingOrientedBox(item->Pose); |
| 256 | auto height = (bbox.Center - bbox.Extents).y - CLICK(1); |
| 257 | |
| 258 | for (int i = 0; i < 3; i++) |
| 259 | { |
| 260 | auto sinHeading = (i != 1) ? (phd_sin(coll->Setup.ForwardAngle + ANGLE((i * 90.0f) - 90.0f))) : 0; |
| 261 | auto cosHeading = (i != 1) ? (phd_cos(coll->Setup.ForwardAngle + ANGLE((i * 90.0f) - 90.0f))) : 0; |
| 262 | |
| 263 | auto origin = Vector3( |
| 264 | item->Pose.Position.x + (sinHeading * (coll->Setup.Radius)), |
| 265 | height, |
| 266 | item->Pose.Position.z + (cosHeading * (coll->Setup.Radius))); |
| 267 | |
| 268 | auto mxR = Matrix::CreateFromYawPitchRoll(TO_RAD(coll->Setup.ForwardAngle), 0.0f, 0.0f); |
| 269 | auto direction = (Matrix::CreateTranslation(Vector3::UnitZ) * mxR).Translation(); |
| 270 | |
| 271 | // DrawDebugSphere(origin, 16, Vector4::One, RendererDebugPage::CollisionStats); |
| 272 | |
| 273 | for (auto i : g_Level.Rooms[item->RoomNumber].NeighborRoomNumbers) |
| 274 | { |
| 275 | if (!g_Level.Rooms[i].Active()) |
| 276 | continue; |
| 277 | |
| 278 | int itemNumber = g_Level.Rooms[i].itemNumber; |
| 279 | while (itemNumber != NO_VALUE) |
| 280 | { |
| 281 | auto* item2 = &g_Level.Items[itemNumber]; |
| 282 | auto* object = &Objects[item2->ObjectNumber]; |
| 283 | |
| 284 | if (object->isPickup || object->collision == nullptr || !item2->Collidable || item2->Status == ITEM_INVISIBLE) |
| 285 | { |
| 286 | itemNumber = item2->NextItem; |
| 287 | continue; |
| 288 | } |
| 289 | |
| 290 | if (Vector3i::Distance(item->Pose.Position, item2->Pose.Position) < COLLISION_CHECK_DISTANCE) |
| 291 | { |
| 292 | auto box = GameBoundingBox(item2).ToBoundingOrientedBox(item2->Pose); |
| 293 | float distance; |
| 294 | |
| 295 | if (box.Intersects(origin, direction, distance) && distance < (coll->Setup.Radius * 2)) |
| 296 | { |
| 297 | coll->HitStatic = true; |
| 298 | return; |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | itemNumber = item2->NextItem; |
| 303 | } |
| 304 | |
| 305 | for (auto& mesh : g_Level.Rooms[i].mesh) |
| 306 | { |
| 307 | if (!(mesh.Flags & StaticMeshFlags::SM_VISIBLE)) |
| 308 | continue; |
| 309 | |
| 310 | if (Vector3i::Distance(item->Pose.Position, mesh.Pose.Position) < COLLISION_CHECK_DISTANCE) |
no test coverage detected