[ODE] Collision response etc

Byron Wright bslayerw at mindspring.com
Tue Jan 28 11:26:02 2003


*bump*.

Anyone have any idea on how I might solve this?

-Byron

-----Original Message-----
From: ode-admin@q12.org [mailto:ode-admin@q12.org] On Behalf Of Byron
Wright
Sent: Friday, January 24, 2003 5:30 PM
To: ode@q12.org
Subject: [ODE] Collision response etc


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

_______________________________________________
ODE mailing list
ODE@q12.org
http://q12.org/mailman/listinfo/ode