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

Commit c48b0f8

Browse files
committed
Revert "Fix atoms missing from terrain hit list"
This reverts commit 631078f.
1 parent 631078f commit c48b0f8

File tree

1 file changed

+38
-43
lines changed

1 file changed

+38
-43
lines changed

Entities/AtomGroup.cpp

Lines changed: 38 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,43 +1220,40 @@ float AtomGroup::Travel(Vector &position,
12201220
{
12211221
somethingPenetrated = false;
12221222

1223-
distMass = mass / static_cast<float>((hitTerrAtoms.size() - penetratingAtoms.size()) * (m_Resolution ? m_Resolution : 1));
1224-
distMI = m_MomInertia / static_cast<float>((hitTerrAtoms.size() - penetratingAtoms.size()) * (m_Resolution ? m_Resolution : 1));
1223+
distMass = mass / static_cast<float>(hitTerrAtoms.size() * (m_Resolution ? m_Resolution : 1));
1224+
distMI = m_MomInertia / static_cast<float>(hitTerrAtoms.size() * (m_Resolution ? m_Resolution : 1));
12251225

12261226
for (std::list<Atom*>::iterator aItr = hitTerrAtoms.begin(); aItr != hitTerrAtoms.end(); )
12271227
{
1228-
const std::list<Atom *>::iterator duplicateAtomItr = std::find(penetratingAtoms.begin(), penetratingAtoms.end(), *aItr);
1229-
if (duplicateAtomItr == penetratingAtoms.end()) {
1230-
// Calc and store the accurate hit radius of the Atom in relation to the CoM
1231-
tempVec = (*aItr)->GetOffset().GetXFlipped(hFlipped);
1232-
hitData.HitRadius[HITOR] = tempVec.RadRotate(rotation.GetRadAngle()) *= c_MPP;
1233-
// Figure out the pre-collision velocity of the hitting atom due to body translation and rotation.
1234-
hitData.HitVel[HITOR] = velocity + tempVec.Perpendicularize() * angVel;
1235-
1236-
radMag = hitData.HitRadius[HITOR].GetMagnitude();
1237-
// These are set temporarily here, will be re-set later when the normal of the hit terrain bitmap (ortho pixel side) is known.
1238-
hitData.HitDenominator = (1.0F / distMass) + ((radMag * radMag) / distMI);
1239-
hitData.PreImpulse[HITOR] = hitData.HitVel[HITOR] / hitData.HitDenominator;
1240-
// Set the atom with the hit data with all the info we have so far.
1241-
(*aItr)->SetHitData(hitData);
1242-
1243-
if (g_SceneMan.WillPenetrate((*aItr)->GetCurrentPos().GetFloorIntX(), (*aItr)->GetCurrentPos().GetFloorIntY(), hitData.PreImpulse[HITOR]))
1244-
{
1245-
// Move the penetrating atom to the pen. list from the coll. list.
1246-
penetratingAtoms.push_back(*aItr);
1247-
somethingPenetrated = true;
1248-
} else
1249-
++aItr;
1228+
// Calc and store the accurate hit radius of the Atom in relation to the CoM
1229+
tempVec = (*aItr)->GetOffset().GetXFlipped(hFlipped);
1230+
hitData.HitRadius[HITOR] = tempVec.RadRotate(rotation.GetRadAngle()) *= c_MPP;
1231+
// Figure out the pre-collision velocity of the hitting atom due to body translation and rotation.
1232+
hitData.HitVel[HITOR] = velocity + tempVec.Perpendicularize() * angVel;
1233+
1234+
radMag = hitData.HitRadius[HITOR].GetMagnitude();
1235+
// These are set temporarily here, will be re-set later when the normal of the hit terrain bitmap (ortho pixel side) is known.
1236+
hitData.HitDenominator = (1.0F / distMass) + ((radMag * radMag) / distMI);
1237+
hitData.PreImpulse[HITOR] = hitData.HitVel[HITOR] / hitData.HitDenominator;
1238+
// Set the atom with the hit data with all the info we have so far.
1239+
(*aItr)->SetHitData(hitData);
1240+
1241+
if (g_SceneMan.WillPenetrate((*aItr)->GetCurrentPos().GetFloorIntX(), (*aItr)->GetCurrentPos().GetFloorIntY(), hitData.PreImpulse[HITOR]))
1242+
{
1243+
// Move the penetrating atom to the pen. list from the coll. list.
1244+
penetratingAtoms.push_back(*aItr);
1245+
aItr = hitTerrAtoms.erase(aItr);
1246+
somethingPenetrated = true;
12501247
} else
12511248
++aItr;
12521249
}
12531250
}
1254-
while (somethingPenetrated);
1251+
while (!hitTerrAtoms.empty() && somethingPenetrated);
12551252

12561253
// TERRAIN BOUNCE //////////////////////////////////////////////////////////////////
12571254
// If some Atoms could not penetrate even though all the impulse was on them,
12581255
// gather the bounce results and apply them to the owner.
1259-
if (hitTerrAtoms.size() != penetratingAtoms.size())
1256+
if (!hitTerrAtoms.empty())
12601257
{
12611258
newDir = true;
12621259

@@ -1946,31 +1943,29 @@ before adding them to the MovableMan.
19461943
do {
19471944
somethingPenetrated = false;
19481945

1949-
massDist = mass / static_cast<float>((hitTerrAtoms.size() - penetratingAtoms.size()) * (m_Resolution ? m_Resolution : 1));
1946+
massDist = mass / static_cast<float>(hitTerrAtoms.size() * (m_Resolution ? m_Resolution : 1));
19501947

19511948
for (deque<pair<Atom *, Vector> >::iterator aoItr = hitTerrAtoms.begin(); aoItr != hitTerrAtoms.end(); )
19521949
{
1953-
const deque<pair<Atom *, Vector> >::iterator duplicateAtomItr = std::find(penetratingAtoms.begin(), penetratingAtoms.end(), *aoItr);
1954-
if (duplicateAtomItr == penetratingAtoms.end()) {
1955-
if (g_SceneMan.WillPenetrate(intPos[X] + (*aoItr).second.GetFloorIntX(),
1956-
intPos[Y] + (*aoItr).second.GetFloorIntY(),
1957-
forceVel,
1958-
massDist))
1959-
{
1960-
// Move the penetrating atom to the pen. list from the coll. list.
1961-
penetratingAtoms.push_back(pair<Atom *, Vector>((*aoItr).first, (*aoItr).second));
1962-
somethingPenetrated = true;
1963-
} else
1964-
++aoItr;
1965-
} else
1966-
++aoItr;
1950+
if (g_SceneMan.WillPenetrate(intPos[X] + (*aoItr).second.GetFloorIntX(),
1951+
intPos[Y] + (*aoItr).second.GetFloorIntY(),
1952+
forceVel,
1953+
massDist))
1954+
{
1955+
// Move the penetrating atom to the pen. list from the coll. list.
1956+
penetratingAtoms.push_back(pair<Atom *, Vector>((*aoItr).first, (*aoItr).second));
1957+
aoItr = hitTerrAtoms.erase(aoItr);
1958+
somethingPenetrated = true;
1959+
}
1960+
else
1961+
++aoItr;
19671962
}
1968-
} while (somethingPenetrated);
1963+
} while (!hitTerrAtoms.empty() && somethingPenetrated);
19691964

19701965
// TERRAIN BOUNCE //////////////////////////////////////////////////////////////////
19711966
// If some Atom:s could not penetrate even though all the mass was on them,
19721967
// gather the bounce results and apply them to the owner.
1973-
if (hitTerrAtoms.size() != penetratingAtoms.size())
1968+
if (!hitTerrAtoms.empty())
19741969
{
19751970
newDir = true;
19761971
prevError = error;

0 commit comments

Comments
 (0)