Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit 8b583f6

Browse files
committed
Rework how penetrating atoms behave
Even if not all the hitting atoms penetrated, then atoms that did penetrate will affect the terrain and will have hit response applied to the body. Penetration will not cause body movement on its own.
1 parent 5280ac5 commit 8b583f6

File tree

1 file changed

+40
-64
lines changed

1 file changed

+40
-64
lines changed

Entities/AtomGroup.cpp

Lines changed: 40 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,80 +1291,56 @@ float AtomGroup::Travel(Vector &position,
12911291
}
12921292
}
12931293
// TERRAIN SINK ////////////////////////////////////////////////////////////////
1294-
// Else all Atom:s must have penetrated and therefore the entire group has
1295-
// sunken into the terrain. Get the penetration resistance results and
1296-
// apply them to the owner.
1297-
else if (!penetratingAtoms.empty())
1298-
{
1299-
// Re-calculate the progress made on this segment before hitting something.
1300-
// We do this because the hitting step made resulted in a terrain sink,
1301-
// which means the segment progressed another step, and the segmentProgress
1302-
// should reflect this.
1303-
segProgress = static_cast<float>(stepCount + 1) / static_cast<float>(stepsOnSeg);
1304-
1305-
// TODO: Wrapping detection here may be screwed up on very special cases.")
1306-
// Move position forward to the sink hit position.
1307-
position = preHitPos + linSegTraj * segProgress;
1308-
// Wrap position, if necessary.
1309-
didWrap = g_SceneMan.WrapPosition(position) || didWrap;
1310-
// Move rotation forward according to the progress made on the segment, incl sink.
1311-
rotation = preHitRot + rotDelta * segProgress;
1312-
/*
1313-
// Adjust the radius etc to account for the sinking into the terrain.
1314-
(*aItr)->SetHitRadius((*aItr)->GetOffset().RadRotate(rotation));
1315-
// Figure out the pre-collision velocity of the
1316-
// hitting atom due to body translation and rotation.
1317-
(*aItr)->SetHitVel(velocity + (*aItr)->GetOffset().RadRotate(rotation + c_HalfPI) *
1318-
c_MPP * angVel);
1319-
*/
1320-
hitFactor = 1.0F / static_cast<float>(penetratingAtoms.size());
1294+
// Handle terrain penetration effects.
1295+
if (!penetratingAtoms.empty()) {
1296+
hitFactor = 1.0F / static_cast<float>(penetratingAtoms.size());
13211297

1322-
// Calc and store the collision response effects.
1323-
for (Atom *penetratingAtom : penetratingAtoms)
1324-
{
1298+
// Calc and store the collision response effects.
1299+
for (Atom *penetratingAtom : penetratingAtoms)
1300+
{
13251301

13261302

1327-
// This gets re-set later according to the ortho pixel edges hit.
1303+
// This gets re-set later according to the ortho pixel edges hit.
13281304
// hitData.BitmapNormal = -(hitData.HitVel[HITOR].GetNormalized());
13291305
// hitData.SquaredMIHandle[HITOR] = hitData.HitRadius[HITOR].GetPerpendicular()/*.Dot(hitData.BitmapNormal)*/;
13301306
// hitData.SquaredMIHandle[HITOR] *= hitData.SquaredMIHandle[HITOR];
13311307
// hitData.HitDenominator = (1.0 / distMass) + (hitData.SquaredMIHandle[HITOR] / distMI);
13321308
// hitData.PreImpulse[HITOR] = hitData.HitVel[HITOR] / hitData.HitDenominator;
13331309

1334-
// Get the hitdata so far gathered for this Atom.
1335-
hitData = penetratingAtom->GetHitData();
1336-
1337-
if (g_SceneMan.TryPenetrate(penetratingAtom->GetCurrentPos().GetFloorIntX(),
1338-
penetratingAtom->GetCurrentPos().GetFloorIntY(),
1339-
hitData.PreImpulse[HITOR],
1340-
hitData.HitVel[HITOR],
1341-
retardation,
1342-
1.0F,
1343-
1/*(*penetratingAtom)->GetNumPenetrations()*/))
1344-
{
1310+
// Get the hitdata so far gathered for this Atom.
1311+
hitData = penetratingAtom->GetHitData();
13451312

1346-
// Recalc these here without the distributed mass and MI.
1347-
radMag = hitData.HitRadius[HITOR].GetMagnitude();
1348-
hitData.HitDenominator = (1.0F / mass) + ((radMag * radMag) / m_MomInertia);
1349-
hitData.PreImpulse[HITOR] = hitData.HitVel[HITOR] / hitData.HitDenominator;
1350-
hitData.TotalMass[HITOR] = mass;
1351-
hitData.MomInertia[HITOR] = m_MomInertia;
1352-
hitData.ImpulseFactor[HITOR] = hitFactor;
1353-
// Finally calculate the hit response impulse.
1354-
hitData.ResImpulse[HITOR] = ((hitData.HitVel[HITOR] * retardation) /
1355-
hitData.HitDenominator) * hitFactor;
1356-
1357-
// Call the call-on-sink function, if requested.
1358-
if (callOnSink)
1359-
halted = halted || m_pOwnerMO->OnSink(hitData);
1360-
1361-
// Copy back the new hit data with all the info we have so far.
1362-
penetratingAtom->SetHitData(hitData);
1363-
// Save the atom for later application of its hit data to the body.
1364-
hitResponseAtoms.push_back(penetratingAtom);
1365-
}
1366-
}
1367-
}
1313+
if (g_SceneMan.TryPenetrate(penetratingAtom->GetCurrentPos().GetFloorIntX(),
1314+
penetratingAtom->GetCurrentPos().GetFloorIntY(),
1315+
hitData.PreImpulse[HITOR],
1316+
hitData.HitVel[HITOR],
1317+
retardation,
1318+
1.0F,
1319+
1/*(*penetratingAtom)->GetNumPenetrations()*/))
1320+
{
1321+
1322+
// Recalc these here without the distributed mass and MI.
1323+
radMag = hitData.HitRadius[HITOR].GetMagnitude();
1324+
hitData.HitDenominator = (1.0F / mass) + ((radMag * radMag) / m_MomInertia);
1325+
hitData.PreImpulse[HITOR] = hitData.HitVel[HITOR] / hitData.HitDenominator;
1326+
hitData.TotalMass[HITOR] = mass;
1327+
hitData.MomInertia[HITOR] = m_MomInertia;
1328+
hitData.ImpulseFactor[HITOR] = hitFactor;
1329+
// Finally calculate the hit response impulse.
1330+
hitData.ResImpulse[HITOR] = ((hitData.HitVel[HITOR] * retardation) /
1331+
hitData.HitDenominator) * hitFactor;
1332+
1333+
// Call the call-on-sink function, if requested.
1334+
if (callOnSink)
1335+
halted = halted || m_pOwnerMO->OnSink(hitData);
1336+
1337+
// Copy back the new hit data with all the info we have so far.
1338+
penetratingAtom->SetHitData(hitData);
1339+
// Save the atom for later application of its hit data to the body.
1340+
hitResponseAtoms.push_back(penetratingAtom);
1341+
}
1342+
}
1343+
}
13681344

13691345
// MOVABLEOBJECT COLLISION RESPONSE ///////////////////////////////////////////////
13701346
///////////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)