Collision events

Arkasha

15-05-2006 11:20:19

Hello, I would like to create general collision events when there is a collision in between a Player and user created Objects. I have given them specific CollisionIDs.

I can create the event with the following code, but my problem is if the player is for example "resting" against a wall, events are continuisly generated. Is there any way of detecting a "first contact?" so I can generate only one event.




#include "MaterialCallback.h"

MaterialCallback::MaterialCallback( void )
{
mRealCollision = false;
}

MaterialCallback::~MaterialCallback( void )
{
}

int MaterialCallback::userBegin()
{
return ContactCallback::userBegin();
mRealCollision = false;
}

// This is the method to change for new collision adjustments
// When making a new Contact callback extend from this and return this method at end
int MaterialCallback::userProcess()
{
mRealCollision = true;

return ContactCallback::userProcess();
}

void MaterialCallback::userEnd()
{
if( mRealCollision )
{
String objName0 = ( (Object*)m_body0->getUserData() )->getName();
String objName1 = ( (Object*)m_body1->getUserData() )->getName();
EventManager::getSingleton()->createCollisionEvent(objName0, objName1);
EventManager::getSingleton()->createCollisionEvent(objName1, objName0);
mRealCollision = false;
}

return ContactCallback::userEnd();
}

walaber

15-05-2006 17:48:19

you would need to implement some simple flag variables to keep track of the state of the object(s)...

Arkasha

15-05-2006 20:28:29

Thanks for the swift advice!

Are you suggesting that :

When collision first happens set flag to true,

and then manually test flagged collisions to know if collision is still present and set flag accordingly?

Is their a way to know from Newton if it has cycled through all its contact collisions?

right now i have each contact saved in a contact manager singleton, but I'm having trouble finding a secure way of removing contacts that no longer are present.


And lastly if I should test these "saved" collisions to know if they are still present, what would you recommend? Checking boundingnoxes?