Archived

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

Bounding Box Collision Detection

This topic is 5127 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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;
}

// functions

private:
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 members

private:
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....

Share this post


Link to post
Share on other sites