Bounding Box Collision Detection

Started by
1 comment, last by DarkWhoppy 20 years, 4 months ago
Hello folks, I need to know how to calll an event when two bounding boxes collide. can someone help a man out? This problem is killing my brain.
Visit the 3DHangout
Advertisement
Test each box for intersection with each other box in your game loop.

you can compartmentalize your space for optimization. such as with trees or what have you, but on small scale that''s not necessary.
Not sure I understand the question fully. But usually, from within game libraries, there are callback procedures for events like these, that allow you to intercept an event.

someting like

CCollObject{public:    CCollObject()    : m_pfnCallback(0)    , m_fRadius(0.0f)    , m_vPosition(0.0f, 0.0f, 0.0f)    {}    void SetCallback(bool(*pfnCallback)(CCollObject* pxOtherObj, const Vector& Normal, float t))    {         m_pfnCallback = pfnCallback;    }// functionsprivate:    bool TestCollision(CCollObject* pxObj1, CCollObject* pxObj2)    {        .....        .....        // signal the game a collision is detected        if (bObjectsCollided)        {              if (pxObj1->m_pfnCallback)                  pxObj1->m_pfnCallback(pxObj2, NormalOfColl, fTimeOfColl);              if (pxObj2->m_pfnCallback)                  pxObj2->m_pfnCallback(pxObj1, -NormalOfColl, fTimeOfColl);        }    }// data membersprivate:    float  m_fRadius;    Vector m_vPosition;    bool (*m_pfnCallback)(CCollObject* pxOtherObj, const Vector& Normal, float t);......};


they have usually more data passed on to the callback, like contact velocity, ect....

Everything is better with Metal.

This topic is closed to new replies.

Advertisement