[ODE] Collision response etc
Byron Wright
bslayerw at mindspring.com
Fri Jan 24 18:30:02 2003
New to ODE, trying to figure out how to play a sound effect when objects
collide.
Here are the steps I take to produce a "bump" sound effects.
- do collision detection and response
- world step
- check all bodies for contact joints, if they have contact joints and
their forces are greater than 0 then play a the bump sound effect
The problem is that after a collision and the contact joints have been
created the magnitude of the force is alway 0. When should I get be
requisting the force from my bodies? Or should I be checking something
else to find out if the body has been "bumped"?
Here is my update function :
void update(float dt) {
dSpaceCollide(space, 0, &NearCallback);
dWorldStep (world, dt);
//iterate though all boxes, if they have contact joints (collision)
//then play a sound effect if the box's force is greater than 0
//BodyCollection is = typedef vector<dBodyID> BodyCollection;
BodyCollection::iterator it = boxBodies.begin();
while(it != boxBodies.end()) {
int numJoints = dBodyGetNumJoints(*it);
if(numJoints > 0) {
for(int joints = 0; joints < numJoints; ++ joints) {
dJointID joint = dBodyGetJoint (*it, joints);
if(dJointGetType(joint) == dJointTypeContact) {
//it's a contact joint. check force of
bodies
const dReal * forceA = dBodyGetForce(*it);
cout << magnitude(forceA) << endl;
if(magnitude(forceA) > 0.05 ) {
Mix_PlayChannel(-1,bump,0);
}
}
}
}
++it;
}
//remove all contact joints from the system
dJointGroupEmpty(contactGroup);
}
Byron Wright