Displacement Vector?

Official forum for the Chipmunk2D Physics Library.
Post Reply
georgeburns
Posts: 4
Joined: Sun Jan 10, 2010 10:28 pm
Contact:

Displacement Vector?

Post by georgeburns »

Hi,

First time posting here. I am loving the engine. Have run into one snag though.

Is it possible to obtain a displacement vector from a call back? I just need to know the objects speed and direction... regardless of mass/velocity etc.
would storing the last body->p on the previous step and then comparing to the current one, be the only way?

Thanks.
-george
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Displacement Vector?

Post by slembcke »

I'm not sure I understand the question exactly. By callback I assume you mean a collision handler callbacks.

The "speed and direction" is the velocity vector of a cpBody. Storing the old position of a body and finding the position change will give you the same result as the velocity*timestep. If the issue is that you don't know what the timestep is, it's yet another good reason to use a fixed size timestep.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
georgeburns
Posts: 4
Joined: Sun Jan 10, 2010 10:28 pm
Contact:

Re: Displacement Vector?

Post by georgeburns »

Yes... I was getting confused as my eyes don't operate at 60 fps.

I had a few bodies that were touching each other and using the post/pre collision call backs to compare their velocity vectors to determine sound loudness to playback. It was a row of objects where an external body hit them... the bodies in the middle didn't "appear" to move at all so I had thought the velocity vector had something to do with pent up forces...as the sounds were really loud. I logged the ->v in the step and can see that the middle bodies actually speed up for one step. I'll have to figure out something to make it visual/audible correct.

Thanks and thanks for your time on making this incredible engine.

-George
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Displacement Vector?

Post by slembcke »

You can get the collision force in th postStep() callback if you are not using elastic iterations. http://code.google.com/p/chipmunk-physi ... _Functions
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
georgeburns
Posts: 4
Joined: Sun Jan 10, 2010 10:28 pm
Contact:

Re: Displacement Vector?

Post by georgeburns »

Well... I guess I'm still confused and can't get the desired results....

If the sound of the crash of two bodies is based on the velocity vectors of each body....

I've got body 1 with a constant cpv(-100,0) and body 2 with a constant cpv(+100,0)
and they are right pressing against each other... sort of like i'm pushing two tennis balls together with my hands...

Once they have made initial contact... there is no more sound.
I'm getting constant sound.
Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests