[ODE] Collision response etc

Byron Wright bslayerw at mindspring.com
Tue Jan 28 23:16:01 2003


whether an object has a mass of 1 or 1000 is irrelevant since is can be
used as part of the equation. Two feathers smashing into one another
will probably sound like a bird farting, when was the last time you
heard a bird fart?

-Byron

-----Original Message-----
From: John Savage [mailto:JSavage@data-mate.com] 
Sent: Tuesday, January 28, 2003 9:53 PM
To: 'Byron Wright'; ode@q12.org
Subject: RE: [ODE] Collision response etc


But you can still do all those groovy sound effects!! One way or another
you are going to have to know whether this is the first time any pair of
objects have collided, or whether they were alreay in contact in order
to avoid repeatedly firing the initial collision sound when objects are
continually in contact!

You could even extend the system to keep track of how long any pair of
objects have been in contact and invoke an appropriate scraping/rubbing
sound with its volume/intensity proportional to the magnitude of the two
objects relative velocities perpendicular to their normal of
intersection (woah, now thats a sentence!! :) ).

If you can think of a way of doing any of this without at least keeping
track of whether objecs are alreay in contact before the time step, then
cool, but right now I can't really see many other options. Well... I can
see one. Which would be before you play the 'bump' sound you can see if
it is already playing. If so, then don't play it again... but that is
definitely a hack :).

ODE itself is temporally discrete. The information you get at each call
of your Collision callback is relating exclusively to the current
snapshot being simulated this time step. There is no way (to my
knowledge) that you can ask ODE what things were like the last frame,
since it has alreay forgotten about that in progressing to the next.
Meanwhile, the kind of audio effects you are talking about are
inherently time dependent and MUST store some sort of 'what state was I
in last frame' information.

Thats my two cents anyway.

Oh, Nate just sent a mail on the topic. That could work Nate, but how do
you define a 'huge jerk'. The Impulse resulting from a collision will
always be tiny for a 1mass ball compared to a 1000mass ball, so it may
be difficult to get this to work consistently. Hmmmmm. I guess
experimentaiton is the only way really.

Later,
John



  _____

John Savage <mailto:jsavage@data-mate.com>
Software Engineer DataMate Global Communications
Tel: +1 818 487 3900 ext105
  _____



-----Original Message-----
From: ode-admin@q12.org [mailto:ode-admin@q12.org]On Behalf Of Byron
Wright
Sent: Tuesday, January 28, 2003 9:28 PM
To: ode@q12.org
Subject: RE: [ODE] Collision response etc


I appreciate the feedback on this one but tracking collision states and
such just seems like a hack. I would really like to take advantage of
the physics engine and use "real world" values to simulate "my world".
Also, if I know the forces involved when the objects collide I could
also do things like adjust the amplitude, frequency and such of the
sounds... the harder the impact the louder the bang!, objects might have
different frequencies and amplitudes based on their mass and the
magnitude of the forces (although a very dumbed down simulation).

-Byron

-----Original Message-----
From: ode-admin@q12.org [mailto:ode-admin@q12.org] On Behalf Of John
Savage
Sent: Tuesday, January 28, 2003 7:22 PM
To: 'Byron Wright'; ode@q12.org
Subject: RE: [ODE] Collision response etc


Not having done this myself, here's an idea. It definitely can be
improved upon, but here's the 'of the top of my head explanation'.

You only want to play the 'bump' sound if there is an instantaneous
contacts, or put another, you only want to play the sound the first time
objects touch. But, if they touch in subsequent world steps you don't
want to play the sound again.

What you could do is keep track of whether each object pair generated
any contacts in the previous collision callback. Then as you process the
current callback you check, whether the pair of objects currently
collided also collided during the last frame. If they did, you know they
are continuously in contact so you should not play the sound. If they
were not in contact last frame, then you know that this is the first
time the two objects have met, and so you can safely play the sound.

English descriptions are so hard to do accurately, so here is some
pseudo code...

/*
 purpose of WorldStepCounter is to give each set of calls to
CollisionCallbackRoutine()
 for each call to dWorldStep a unique ID. This value is then stored in
LastCallbackCollided  to record the ID of the world step when this pair
of objects last collided. */ int WorldStepCounter = 0;
/*
 Each entry in this 2D array is set to the WorldStepCounter value when
the two objects  with IDs equal to the index pair last collided. */ int
LastCallbackCollided[NumObjects][NumObjects] = { all set to -1 };

void GameLoop()
{
 while(true)
 {
   DoStuff();
   WorldStepCounter++;
   dWorldStep();
 }
}

foo CollisionCallbackRoutine(int obj1index, int obj2index)
{
  if(LastCallbackCollided[obj1index][obj2index] != WorldStepCounter)
  {
    // then they did not collide last frame, so we can...
    PlaySound('bump.wav');
  }

  // store the fact that these two objects collided in the
LastCallbackCollided array...
  LastCallbackCollided[obj1index][obj2index] = WorldStepCounter; }

End of PseudoCode.
And that should do it. Serious issues to be addressed though: The 2D
array could quite quickly need to be very large since it is
n^num_objects in size. Take the above pseudocode as an idea only! :).

Hope this helps (or even makes sense :p).

John

  _____

John Savage <mailto:jsavage@data-mate.com>
Software Engineer DataMate Global Communications
Tel: +1 818 487 3900 ext105
  _____



-----Original Message-----
From: ode-admin@q12.org [mailto:ode-admin@q12.org]On Behalf Of Byron
Wright
Sent: Tuesday, January 28, 2003 6:56 PM
To: 'David Walker'; ode@q12.org
Subject: RE: [ODE] Collision response etc


I initially attempted that. The problem is that the existence of contact
points does not constitute a "bump" (or high impact). The problem is
that if the object is resting on a ground plane for example,  then the
collision callback is called every time step  (and contact joints are
created) create a horrible array of sound effects. That is why I was
attempting to figure out the forces applied to the objects since that
will most likely help me figure out if the objects are bouncing or have
collided and are not simply resting on/against one another. The problem
still remains that when retrieving the force on a body (in the callback
or not) I still get a result of 0.

-Byron

-----Original Message-----
From: David Walker [mailto:david.walker530@ntlworld.com]
Sent: Tuesday, January 28, 2003 6:38 PM
To: Byron Wright
Subject: Re: [ODE] Collision response etc


Hello,

I think the best place to do this is in the collision callback. when you
actually create the contact joints. that would probably be a good place
to play the sound. I don't know for sure because I haven't done this yet
(It's on my list of things to do) but that's how I'm going to tackle it.
I'm also going to put scoring in there somewhere.

Does this make sense?

David


----- Original Message -----
From: "Byron Wright" <bslayerw@mindspring.com>
To: <ode@q12.org>
Sent: Tuesday, January 28, 2003 6:21 PM
Subject: RE: [ODE] Collision response etc


> *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
>
> _______________________________________________
> ODE mailing list
> ODE@q12.org
> http://q12.org/mailman/listinfo/ode

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

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

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