This topic is now archived and is closed to further replies.


Why wont this collision code run?

Recommended Posts

executor_2k2    122
Below is code to decide if a particle has hit the "floor" ( a plane that is parallel to xz at the origin): static CVector normal (0, 1, 0); static CPlane floor(normal, 0); static float bouncePercent = 0.5f; static float distPlane = 0.0f; static float distPlanePost = 0.0f; //MessageBox(NULL, "We're Updating Particles", "Bubbles",MB_OK | MB_ICONEXCLAMATION); for (int i = 0; i < m_numParticles; ++i) { CVector DestinationPos = m_particleList.m_pos + m_particleList[i].m_velocity * elapsedTime; distPlane = floor.DistanceToPlane(DestinationPos); distPlanePost = floor.DistanceToPlane(m_particleList[i].m_pos); if((distPlane < 0 && distPlanePost >= 0) || (distPlane >= 0 && distPlanePost < 0)) { MessageBox(NULL, "We're Updating Particles", "Bubbles",MB_OK | MB_ICONEXCLAMATION); m_particleList[i].m_velocity.y = -m_particleList[i].m_velocity.y; } m_particleList[i].m_pos = m_particleList[i].m_pos + m_particleList[i].m_velocity * elapsedTime; When this code is run, the if statement with the MessageBox command never evaluates to true. Ne1 know why not? Thx Edited by - executor_2k2 on February 5, 2002 1:02:47 AM

Share this post

Link to post
Share on other sites
grhodes_at_work    1385
I see only one reason why this code might prevent the if condition from evaluating true at some point. Does your DistanceToPlane() method return the magnitude of the distance (which would only ever be >= 0 and never < 0)?

It that''s not it, then I believe the problem must be outside this block of code. Perhaps your velocity is always moving the particles away from the plane? How do you set your velocity initially? And how do you use acceleration to update your velocity? Are you just using gravity? I see your particle system is called "Bubbles." Are you wanting your particles to float? In which case why should they ever go through the floor....

If DistanceToPlane() really just returns height above the plane (which can be negative when an object is below the plane), then perhaps you might change the function name just to avoid confusion---maybe call it HeightAbovePlane()?

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.

Share this post

Link to post
Share on other sites