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

Function ItemPushStatic

TombEngine/Game/collision/collide_item.cpp:795–867  ·  view source on GitHub ↗

NOTE: Previously ItemPushLaraStatic().

Source from the content-addressed store, hash-verified

793
794// NOTE: Previously ItemPushLaraStatic().
795bool ItemPushStatic(ItemInfo* item, const StaticMesh& mesh, CollisionInfo* coll)
796{
797 const auto& bounds = GetBoundsAccurate(mesh, false);
798
799 float sinY = phd_sin(mesh.Pose.Orientation.y);
800 float cosY = phd_cos(mesh.Pose.Orientation.y);
801
802 auto direction = item->Pose.Position - mesh.Pose.Position;
803 auto dz = item->Pose.Position.z - mesh.Pose.Position.z;
804 auto rx = (direction.x * cosY) - (direction.z * sinY);
805 auto rz = (direction.z * cosY) + (direction.x * sinY);
806 auto minX = bounds.X1 - coll->Setup.Radius;
807 auto maxX = bounds.X2 + coll->Setup.Radius;
808 auto minZ = bounds.Z1 - coll->Setup.Radius;
809 auto maxZ = bounds.Z2 + coll->Setup.Radius;
810
811 if (abs(direction.x) > BLOCK(4.5f) || abs(direction.z) > BLOCK(4.5f) ||
812 rx <= minX || rx >= maxX ||
813 rz <= minZ || rz >= maxZ)
814 {
815 return false;
816 }
817
818 auto left = rx - minX;
819 auto top = maxZ - rz;
820 auto bottom = rz - minZ;
821 auto right = maxX - rx;
822
823 if (right <= left && right <= top && right <= bottom)
824 rx += right;
825 else if (left <= right && left <= top && left <= bottom)
826 rx -= left;
827 else if (top <= left && top <= right && top <= bottom)
828 rz += top;
829 else
830 rz -= bottom;
831
832 item->Pose.Position.x = mesh.Pose.Position.x + cosY * rx + sinY * rz;
833 item->Pose.Position.z = mesh.Pose.Position.z + cosY * rz - sinY * rx;
834
835 coll->Setup.LowerFloorBound = NO_LOWER_BOUND;
836 coll->Setup.UpperFloorBound = -STEPUP_HEIGHT;
837 coll->Setup.LowerCeilingBound = 0;
838
839 auto prevHeadingAngle = coll->Setup.ForwardAngle;
840 coll->Setup.ForwardAngle = phd_atan(item->Pose.Position.z - coll->Setup.PrevPosition.z, item->Pose.Position.x - coll->Setup.PrevPosition.x);
841
842 GetCollisionInfo(coll, item);
843
844 coll->Setup.ForwardAngle = prevHeadingAngle;
845
846 if (coll->CollisionType == CollisionType::None)
847 {
848 coll->Setup.PrevPosition = item->Pose.Position;
849 if (item->IsLara())
850 UpdateLaraRoom(item, -coll->Setup.Height / 2);
851 }
852 else

Callers 2

TorchControlFunction · 0.85
DoObjectCollisionFunction · 0.85

Calls 6

phd_sinFunction · 0.85
phd_cosFunction · 0.85
phd_atanFunction · 0.85
GetCollisionInfoFunction · 0.85
UpdateLaraRoomFunction · 0.85
IsLaraMethod · 0.80

Tested by

no test coverage detected