Yustme
04-01-2008 16:31:24
Hi,
I'm trying to play a sound when 2 specific bodies are colliding against each other. I have managed to make the callbacks for it but i don't know how to actually check if 2 bodies collided against each other.
I have searched in the forums of newtondynamics and ogrenewt. I couldn't find an example where this was actually done in C++.
This is my default properties of newton:
And these are my callback functions:
Basically, i just want to play a sound when 2 bodies collide. I have no interest whether how fast the sphere's moved or not, or anything else.
But at the moment as it is, it plays a sound the whole time, even if there is no collision.
Can anyone help me with this issue?
Thanks in advance!
I'm trying to play a sound when 2 specific bodies are colliding against each other. I have managed to make the callbacks for it but i don't know how to actually check if 2 bodies collided against each other.
I have searched in the forums of newtondynamics and ogrenewt. I couldn't find an example where this was actually done in C++.
This is my default properties of newton:
// Set up default material properties for newton
int i = NewtonMaterialGetDefaultGroupID(nWorld);
NewtonMaterialSetDefaultFriction (nWorld, i, i, 0.5f, 0.4f);
NewtonMaterialSetDefaultElasticity (nWorld, i, i, 0.75f);
NewtonMaterialSetDefaultSoftness (nWorld, i, i, 0.0f);
NewtonMaterialSetCollisionCallback (nWorld, i, i, spherebody1, beginCallback, processCallback, endCallback);
NewtonMaterialSetCollisionCallback (nWorld, i, i, sphereBody2, beginCallback, processCallback, endCallback);
And these are my callback functions:
struct COLLISION
{
const NewtonBody *colBody0, *colBody1;
} g_col;
// check if bodies are almost colliding
int _cdecl beginCallback(const NewtonMaterial* material, const NewtonBody* body0, const NewtonBody* body1)
{
g_col.colBody0 = body0;
g_col.colBody1 = body1;
return 1;
}
// process the collided bodies
int _cdecl processCallback(const NewtonMaterial* material, const NewtonContact* contact)
{
return true;
}
// end the callback and play sound
void _cdecl endCallback(const NewtonMaterial* material)
{
vector3 pos(sphere->getPosition());
const char* filename;
filename = "explosion.wav";
pos.X /= 100 * 10;
pos.Y /= 100 * 10;
pos.Z /= 100 * 10;
engine->play3D(filename, pos);
cout << "pos.X: " << pos.X << " pos.Y: " << pos.Y << " pos.Z: " << pos.Z << endl;
}
Basically, i just want to play a sound when 2 bodies collide. I have no interest whether how fast the sphere's moved or not, or anything else.
But at the moment as it is, it plays a sound the whole time, even if there is no collision.
Can anyone help me with this issue?
Thanks in advance!