MCPcopy Create free account
hub / github.com/TombEngine/TombEngine / GetCollidedObjects

Function GetCollidedObjects

TombEngine/Game/collision/collide_item.cpp:92–221  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

90}
91
92CollidedObjectData 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;

Callers 15

TorchControlFunction · 0.85
IsValidForPlayerFunction · 0.85
ControlExplosionFunction · 0.85
ElectricityWiresControlFunction · 0.85
BurnNearbyItemsFunction · 0.85
ControlSpikyWallFunction · 0.85
HandleProjectileFunction · 0.85
CreateFlareFunction · 0.85
TestLaraObjectCollisionFunction · 0.85
TestLaraPoleCollisionFunction · 0.85

Calls 10

GetExtentsMethod · 0.80
ToBoundingOrientedBoxMethod · 0.80
ActiveMethod · 0.80
IsLaraMethod · 0.80
IntersectsMethod · 0.80
Vector3Function · 0.50
LengthMethod · 0.45
ToVector3Method · 0.45
push_backMethod · 0.45

Tested by 3

TestLaraObjectCollisionFunction · 0.68
TestLaraPoleCollisionFunction · 0.68
TestCollidingObjectsMethod · 0.68