| 90 | } |
| 91 | |
| 92 | CollidedObjectData GetCollidedObjects(ItemInfo& collidingItem, bool onlyVisible, bool ignorePlayer, float customRadius, ObjectCollectionMode mode) |
| 93 | { |
| 94 | constexpr auto ROUGH_BOX_HEIGHT_MIN = BLOCK(1 / 8.0f); |
| 95 | |
| 96 | auto collObjects = CollidedObjectData{}; |
| 97 | |
| 98 | int itemCount = 0; |
| 99 | int staticCount = 0; |
| 100 | |
| 101 | // Establish parameters of colliding item. |
| 102 | const auto& collidingBounds = GetClosestKeyframe(collidingItem).BoundingBox; |
| 103 | |
| 104 | // Quickly discard collision if colliding item bounds are below tolerance threshold. |
| 105 | if (!customRadius && collidingBounds.GetExtents().Length() <= COLLIDABLE_BOUNDS_THRESHOLD) |
| 106 | return collObjects; |
| 107 | |
| 108 | // Convert bounding box to DX bounds. |
| 109 | auto convertedBounds = collidingBounds.ToBoundingOrientedBox(collidingItem.Pose); |
| 110 | |
| 111 | // Create conservative AABB for rough tests. |
| 112 | auto collidingAabb = collidingBounds.ToConservativeBoundingBox(collidingItem.Pose); |
| 113 | |
| 114 | // Override extents if specified. |
| 115 | if (customRadius > 0.0f) |
| 116 | { |
| 117 | collidingAabb = BoundingBox(collidingItem.Pose.Position.ToVector3(), Vector3(customRadius)); |
| 118 | convertedBounds.Extents = Vector3(customRadius); |
| 119 | } |
| 120 | |
| 121 | // Run through neighboring rooms. |
| 122 | const auto& room = g_Level.Rooms[collidingItem.RoomNumber]; |
| 123 | for (int roomNumber : room.NeighborRoomNumbers) |
| 124 | { |
| 125 | auto& neighborRoom = g_Level.Rooms[roomNumber]; |
| 126 | if (!neighborRoom.Active()) |
| 127 | continue; |
| 128 | |
| 129 | // Collect items. |
| 130 | if (mode == ObjectCollectionMode::All || |
| 131 | mode == ObjectCollectionMode::Items) |
| 132 | { |
| 133 | int itemNumber = neighborRoom.itemNumber; |
| 134 | if (itemNumber != NO_VALUE) |
| 135 | { |
| 136 | do |
| 137 | { |
| 138 | auto& item = g_Level.Items[itemNumber]; |
| 139 | const auto& object = Objects[item.ObjectNumber]; |
| 140 | |
| 141 | itemNumber = item.NextItem; |
| 142 | |
| 143 | // Ignore player (if applicable). |
| 144 | if (ignorePlayer && item.IsLara()) |
| 145 | continue; |
| 146 | |
| 147 | // Ignore invisible item (if applicable). |
| 148 | if (onlyVisible && item.Status == ITEM_INVISIBLE) |
| 149 | continue; |