I recently found out that some players of my game discovered a sequence breaking trick by jumping into a cube at high velocity and thus penetrating it. So I am considering adding CCD to my game. However, I was wondering what kinds of side effects I might need to worry about if I add CCD.
How does CCD behave differently then regular physics in general? What changes will I have to make to my collision handling code? Currently, I don't process contacts immediately. Instead I process all existing contacts at the end of each tick. But I'm worried that with CCD, some contacts will never show up with this method even if they should normally.
How does CCD behave differently then regular physics in general? What changes will I have to make to my collision handling code? Currently, I don't process contacts immediately. Instead I process all existing contacts at the end of each tick. But I'm worried that with CCD, some contacts will never show up with this method even if they should normally.
Code:
class ContactManager: public b2ContactListener
{
std::set<b2Contact*> contact_list;
public:
void BeginContact(b2Contact* contact);
void EndContact(b2Contact* contact);
void Reset() {contact_list.clear();}
void GetContacts( std::vector<ContactData>& buffer ) const;
void ThisDebug() const;
};
void ContactManager::BeginContact(b2Contact* contact)
{
bool alreadyexists = !((contact_list.insert(contact)).second);
assert(!alreadyexists);
}
void ContactManager::EndContact(b2Contact* contact)
{
size_t erasecount = contact_list.erase(contact);
assert(erasecount == 1);
}
void ContactManager::GetContacts( std::vector<ContactData>& buffer ) const
{
BOOST_FOREACH( b2Contact* cptr, contact_list )
{
buffer.push_back( ContactData(cptr) );
}
}
void ContactManager::ThisDebug() const
{
BOOST_FOREACH( b2Contact* ptr, contact_list )
{
Debug(ptr);
}
}
{
std::set<b2Contact*> contact_list;
public:
void BeginContact(b2Contact* contact);
void EndContact(b2Contact* contact);
void Reset() {contact_list.clear();}
void GetContacts( std::vector<ContactData>& buffer ) const;
void ThisDebug() const;
};
void ContactManager::BeginContact(b2Contact* contact)
{
bool alreadyexists = !((contact_list.insert(contact)).second);
assert(!alreadyexists);
}
void ContactManager::EndContact(b2Contact* contact)
{
size_t erasecount = contact_list.erase(contact);
assert(erasecount == 1);
}
void ContactManager::GetContacts( std::vector<ContactData>& buffer ) const
{
BOOST_FOREACH( b2Contact* cptr, contact_list )
{
buffer.push_back( ContactData(cptr) );
}
}
void ContactManager::ThisDebug() const
{
BOOST_FOREACH( b2Contact* ptr, contact_list )
{
Debug(ptr);
}
}