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

Commit afc5272

Browse files
authored
Merge pull request #205 from cortex-command-community/all-penetrating
Penetrating atoms actually do something
2 parents 5280ac5 + 394e02e commit afc5272

File tree

1 file changed

+41
-74
lines changed

1 file changed

+41
-74
lines changed

Entities/AtomGroup.cpp

Lines changed: 41 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,17 +1192,10 @@ float AtomGroup::Travel(Vector &position,
11921192
// Special case of being at rest
11931193
if (stepCount == 0 && stepsOnSeg == 1)
11941194
{
1195-
segProgress = 0.0F;
11961195
halted = true;
11971196
// m_pOwnerMO->SetToSettle(true);
1198-
}
1199-
// Normal travel
1200-
else if (stepCount == 0) {
1201-
// Hit on first atom, but has farther to go
1202-
segProgress = 0.75F / static_cast<float>(stepsOnSeg);
1203-
} else {
1204-
segProgress = static_cast<float>(stepCount) / static_cast<float>(stepsOnSeg);
12051197
}
1198+
segProgress = static_cast<float>(stepCount) / static_cast<float>(stepsOnSeg);
12061199

12071200
// Move position forward to the hit position.
12081201
preHitPos = position;
@@ -1291,80 +1284,54 @@ float AtomGroup::Travel(Vector &position,
12911284
}
12921285
}
12931286
// 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());
1321-
1322-
// Calc and store the collision response effects.
1323-
for (Atom *penetratingAtom : penetratingAtoms)
1324-
{
1325-
1287+
// Handle terrain penetration effects.
1288+
if (!penetratingAtoms.empty()) {
1289+
hitFactor = 1.0F / static_cast<float>(penetratingAtoms.size());
13261290

1327-
// This gets re-set later according to the ortho pixel edges hit.
1291+
// Calc and store the collision response effects.
1292+
for (Atom *penetratingAtom : penetratingAtoms)
1293+
{
1294+
// This gets re-set later according to the ortho pixel edges hit.
13281295
// hitData.BitmapNormal = -(hitData.HitVel[HITOR].GetNormalized());
13291296
// hitData.SquaredMIHandle[HITOR] = hitData.HitRadius[HITOR].GetPerpendicular()/*.Dot(hitData.BitmapNormal)*/;
13301297
// hitData.SquaredMIHandle[HITOR] *= hitData.SquaredMIHandle[HITOR];
13311298
// hitData.HitDenominator = (1.0 / distMass) + (hitData.SquaredMIHandle[HITOR] / distMI);
13321299
// hitData.PreImpulse[HITOR] = hitData.HitVel[HITOR] / hitData.HitDenominator;
13331300

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-
{
1301+
// Get the hitdata so far gathered for this Atom.
1302+
hitData = penetratingAtom->GetHitData();
13451303

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-
}
1304+
if (g_SceneMan.TryPenetrate(penetratingAtom->GetCurrentPos().GetFloorIntX(),
1305+
penetratingAtom->GetCurrentPos().GetFloorIntY(),
1306+
hitData.PreImpulse[HITOR],
1307+
hitData.HitVel[HITOR],
1308+
retardation,
1309+
1.0F,
1310+
1/*(*penetratingAtom)->GetNumPenetrations()*/))
1311+
{
1312+
1313+
// Recalc these here without the distributed mass and MI.
1314+
radMag = hitData.HitRadius[HITOR].GetMagnitude();
1315+
hitData.HitDenominator = (1.0F / mass) + ((radMag * radMag) / m_MomInertia);
1316+
hitData.PreImpulse[HITOR] = hitData.HitVel[HITOR] / hitData.HitDenominator;
1317+
hitData.TotalMass[HITOR] = mass;
1318+
hitData.MomInertia[HITOR] = m_MomInertia;
1319+
hitData.ImpulseFactor[HITOR] = hitFactor;
1320+
// Finally calculate the hit response impulse.
1321+
hitData.ResImpulse[HITOR] = ((hitData.HitVel[HITOR] * retardation) /
1322+
hitData.HitDenominator) * hitFactor;
1323+
1324+
// Call the call-on-sink function, if requested.
1325+
if (callOnSink)
1326+
halted = halted || m_pOwnerMO->OnSink(hitData);
1327+
1328+
// Copy back the new hit data with all the info we have so far.
1329+
penetratingAtom->SetHitData(hitData);
1330+
// Save the atom for later application of its hit data to the body.
1331+
hitResponseAtoms.push_back(penetratingAtom);
1332+
}
1333+
}
1334+
}
13681335

13691336
// MOVABLEOBJECT COLLISION RESPONSE ///////////////////////////////////////////////
13701337
///////////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)