Skip to content

Commit

Permalink
Physics: better rest collision filter based on ball travel distance i…
Browse files Browse the repository at this point in the history
…nstead of time
  • Loading branch information
vbousquet committed Apr 7, 2024
1 parent 3aa66f4 commit 3b3f101
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
10 changes: 3 additions & 7 deletions src/physics/collide.cpp
Expand Up @@ -15,21 +15,17 @@ void HitObject::FireHitEvent(Ball * const pball)
{
if (m_obj && m_fe && m_enabled)
{
// is this the same place as last event and elapsed time is short enough, then ignores it
if ((g_pplayer->m_time_msec - pball->m_lastEventTime) <= 2 * PHYSICS_STEPTIME / 1000)
// is this the same place as last event and ball did not travel in between, then ignores it
if (pball->m_lastEventSqrDist < 0.5f) // 0.5 VPU is a magic value to filter out rest collision
{
const float dist_ls = (pball->m_lastEventPos - pball->m_d.m_pos).LengthSquared();
const float normalDist = (m_ObjType == eHitTarget) ? 0.0f // hit targets when used with a captured ball have always a too small distance
: 0.25f; //!! magic distance
if (dist_ls <= normalDist) // must be a new place if only by a little
{
pball->m_lastEventTime = g_pplayer->m_time_msec;
return;
}
}

pball->m_lastEventSqrDist = 0.f;
pball->m_lastEventPos = pball->m_d.m_pos; // remember last collision position
pball->m_lastEventTime = g_pplayer->m_time_msec;
((IFireEvents*)m_obj)->FireGroupEvent(DISPID_HitEvents_Hit);
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/physics/hitball.cpp
Expand Up @@ -498,6 +498,8 @@ void Ball::UpdateDisplacements(const float dtime)
const Vertex3Ds ds = dtime * m_d.m_vel;
m_d.m_pos += ds;

m_lastEventSqrDist += ds.LengthSquared();

#ifdef C_DYNAMIC
m_drsq = ds.LengthSquared(); // used to determine if static ball
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/physics/hitball.h
Expand Up @@ -64,8 +64,8 @@ class Ball : public HitObject

Vertex3Ds m_oldVel; // hack for kicker hole handling only

U32 m_lastEventTime; // last hit event time (to filter hit 'equal' hit events)
Vertex3Ds m_lastEventPos; // last hit event position (to filter hit 'equal' hit events)
float m_lastEventSqrDist; // distance travelled since last event

Vertex3Ds m_angularmomentum;

Expand Down

0 comments on commit 3b3f101

Please sign in to comment.