Find the highest point

Official forum for the Chipmunk2D Physics Library.
Post Reply
PeskyJ
Posts: 19
Joined: Fri Apr 24, 2009 4:24 pm
Location: Reading, UK
Contact:

Find the highest point

Post by PeskyJ »

I have a need to find the highest point of all shapes in a space, however I want to restrict this to shapes that are relatively stable / at rest... The space is filled with shapes that fall and pile up in a heap, I am not interested in those that are falling, or that have bounced up and are not really stable on the pile yet, only those that are more or less at rest.

What's the best way to do this?

Thanks,
J
Games games games... I love games. Check out my games: [url]http://www.tinyplay.com/games.html[/url]
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Find the highest point

Post by slembcke »

Iterate through all the bodies (keep your own list! I don't want to have this conversation again) Find the highest one that has a velocity under a certain amount. If you need to me more specific than the center of gravity of the highest body, iterate the shapes instead (check the body the shape is attached to) shapes have a bounding box property that should be up to date outside of cpSpaceStep() as long as you don't move anything yourself. The bounding box is tight fitting and has l,r,t,b properties (left, right, bottom, top) that are in absolute coordinates.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
PeskyJ
Posts: 19
Joined: Fri Apr 24, 2009 4:24 pm
Location: Reading, UK
Contact:

Re: Find the highest point

Post by PeskyJ »

Heh, yes I saw that you have mentioned a few times about not iterating the chipmunk lists directly. Makes perfect sense. I already iterate my objects so I can easily check the body for each one as I go through and use the BB of the attached shape(s) thanks for the tip there.

The problem is using the velocity from the body, the pile can slide around from left to right so I should ignore the x component of velocity. However, objects tossed onto the pile will have a y component of zero at the top of their parabola and low vertical velocity just before and after. I was hoping there is a relatively easy way to check for contact with other objects and even better, a timestamp for the contact so that I can eliminate bouncing objects in the air and only objects that have settled with a contact for more than say 0.2 seconds will be considered.
Games games games... I love games. Check out my games: [url]http://www.tinyplay.com/games.html[/url]
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Find the highest point

Post by slembcke »

I think the simplest and most reliable thing you can do is to keep a "rest" ticks counter. If an object's velocity is below a certain point then increment it's counter, otherwise reset the counter to zero. If the counter is greater than some number, then you know the object is at rest and has been so for a while. That weeds out objects in freefall when their velocity is small for a few frames.

The fun part is that it leaves you with two numbers you have to tweak to make it feel responsive, the velocity threshold, and the tick count. That will take a bit of trial and error to get it to work right.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
PeskyJ
Posts: 19
Joined: Fri Apr 24, 2009 4:24 pm
Location: Reading, UK
Contact:

Re: Find the highest point

Post by PeskyJ »

Yes, you are right, that does seem like a good approach. Thank you for giving us chipmunk, it is truly amazing. I have only been playing with it over the weekend (since Friday) and already I love it.
Games games games... I love games. Check out my games: [url]http://www.tinyplay.com/games.html[/url]
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests