Detect collisions with only static shapes

Official forum for the Chipmunk2D Physics Library.
Post Reply
bueda
Posts: 3
Joined: Tue Jan 01, 2008 6:56 pm
Contact:

Detect collisions with only static shapes

Post by bueda »

Hello everyone,

just to introduce myself: i am cs-student from germany, currently working on some side-project to keep my programming skills somewhat fresh; maybe someday i'll proudly post some screenshots ;)

Okay, this game of mine is going to be some kind of top-down rts-game; different in that way (at least until now; may change later), that all objects are not-moving. I am making use of Chipmunk consequently only for collision detection, e.g. if a new user-created object would be placed ontop of another.

I thought of now creating only static shapes, but these are not collision-checked; so my next idea was to create a body without impulse for every "building" and calling cpSpaceStep everytime something is added or removed. Another idea that i thought of would be using no cpSpace at all and iterating over all known shapes, testing everyone for collision with my newly created one.

As i am not sure about how to do this, my question is: What is a good way to use Chipmunk for checking if a user-placed object may be interfering with already existing objects, when it is already known that none of these objects will ever move? What way to chose if i may add moving things later on?

Thanks (also for this great library :D ),
bueda
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Detect collisions with only static shapes

Post by slembcke »

If you only want my collision detection, I actually wouldn't bother using Chipmunk at all. You could just use my collision detection code, but it's not really documented at a low enough level to be able to use it separately. Using the full physics API just for dealing with static collisions is not going to be easy either.

I might be able to give so some pointers on writing your own collision detection. What collision shape(s) are you using? Are there ever enough objects that you need a spatial index? If you can get away with just circles and lines, and speed isn't a huge issue, collision detection is really easy.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
bueda
Posts: 3
Joined: Tue Jan 01, 2008 6:56 pm
Contact:

Re: Detect collisions with only static shapes

Post by bueda »

Well,
as I am quite unsure about where this will lead to (i am still laking an idea of some kind of .. goal), I dont really know what kinds of shapes I might be needing. For the moment i could probably get along with rectangles, lines (as in small but long things) and circles, yes.

Bevor looking out for already written solutions I took a half-baked attempt at trying some collision detection, which lead to nothing realy. So if you could give me a nice start I'll be happily listening :)
bueda
Posts: 3
Joined: Tue Jan 01, 2008 6:56 pm
Contact:

Re: Detect collisions with only static shapes

Post by bueda »

Just out of curisity:

I went with the create-your-own-collision-detection thing, and am basically now copying all the parts i need from your source ;)
Now, stumbling upon the cpvtoangle-function, i was wondering about the semantics of atan2, and think you might have a little error there:

Your code reads:

Code: Select all

cpFloat
cpvtoangle(const cpVect v)
{
	return atan2(v.x, v.y);
}
Though the reference says (cpp as well as c) that the y-parameter is first.
It should be

Code: Select all

cpFloat
cpvtoangle(const cpVect v)
{
	return atan2(v.y, v.x);
}
Not that dramatic, but may lead to funny results :)
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Detect collisions with only static shapes

Post by slembcke »

You are correct sir. I had that wrong because I never tested it when I rewrote some of my vector stuff way back when. :oops: It's fixed in the latest SVN. Does the most recent release still have it?
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Heise IT-Markt [Crawler] and 15 guests