Why wont this collision code run?

Started by
1 comment, last by executor_2k2 22 years, 2 months ago
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.m_velocity * elapsedTime; distPlane = floor.DistanceToPlane(DestinationPos); distPlanePost = floor.DistanceToPlane(m_particleList.m_pos); if((distPlane < 0 && distPlanePost >= 0) || (distPlane >= 0 && distPlanePost < 0)) { MessageBox(NULL, "We're Updating Particles", "Bubbles",MB_OK | MB_ICONEXCLAMATION); m_particleList.m_velocity.y = -m_particleList.m_velocity.y; } m_particleList.m_pos = m_particleList.m_pos + m_particleList.m_velocity * elapsedTime; When this code is run, the if statement with the MessageBox command never evaluates to true. Ne1 know why not? Thx </i> Edited by - executor_2k2 on February 5, 2002 1:02:47 AM
Well, that was a waste of 2 minutes of my life. Now I have to code faster to get 'em back...
Advertisement
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.
Graham Rhodes Moderator, Math & Physics forum @ gamedev.net
Maybe it could help if you show us what''s in the DistanceToPlane fonction...
François DagenaisDagenais.f@videotron.ca

This topic is closed to new replies.

Advertisement