Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

AngelForce

Free 2d collision DETECTION library somewhere?

This topic is 5241 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

At the moment, I am trying to create a 2d physics engine. I have a rough structure and already started coding, and now one of the next steps is to ensure that it *works* somehow. Thus I need to perform collision detection on my objects. Yet as I would like to focus on something else first, I am asking if somebody knows of a free (for personal/testing use) collision detection library which can provide standard contact information (nothing fancy). If not, well, I will have to stop everything and first implement some kind of collision detection, before I can go on with collision response and other things... Yet I hope that maybe someone knows of something (or maybe has some dusty code lurking somewhere which does the job) I can use. Thanks for your time!

Share this post


Link to post
Share on other sites
Advertisement
2D collision detection doesn''t really explain anything. There are a billion different ways to collide things, and a billion different things to collide with.

Are you talking about simple rectangle collision? Surely not, since it takes much less time to write one of those than to type out a message here.

Take these steps:

1) Move objects (but remember how far you moved them)
2) Check collision with everything against everything
3) For every collision, move those objects back where they were

That''s it. You can also bounce or push objects very simply in step 3. Where are you having problems?

Share this post


Link to post
Share on other sites
Oh yeah..

if(ObjA->Right > ObjB->Left
&& ObjA->Left < ObjB->Right
&& ObjA->Bottom > ObjB->Top
&& ObjA->Top < ObjB->Bottom)
// There was a collision

Share this post


Link to post
Share on other sites
Yes, sorry, I could have been more precise. (It''s like you just know what you''re talking about and thus assume that everyone else knows, too )
It isn''t just a matter of moving objects back when they collided as than you cannot do e.g. rotations.
So basically, I need the collision detection to return contact points, which consist of position (point of collision), normal, and interpenetration depth of the contact - and of course information on which two bodies collided.
As for which type of bodies, for testing purposes rectangles would be fine.

I hope now you will understand better what I am looking for.

Share this post


Link to post
Share on other sites
I don;t think there is a collision detection library as such, in 2D. I think you''ll have to write your own.

Anyway, I''ve got a few 2D demos if you go the DIY route (Do It Yourself ).

http://uk.geocities.com/olivier_rebellion/
"2d box contact calculation"

plus some others...

Share this post


Link to post
Share on other sites
quote:
Original post by AngelForce
So basically, I need the collision detection to return contact points, which consist of position (point of collision), normal, and interpenetration depth of the contact - and of course information on which two bodies collided.


If you''re planning on rotating your bounding collision primitives, you should just go with 3D math. Static rectangles would not be very accurate if the sprite objects rotate. IE, no reason to find collision points, since the points would be way off anyways.

With static rectangles, it''s very easy to find the inner overlapping of any two colliding. That inner rectangle is basically the depth and points for both objects. If you plan to rotate it, I think sphere''s would be easier to work with. You could apply several to each object and rotate their offsets with the object.

Share this post


Link to post
Share on other sites
quote:
Original post by Jiia
If you''re planning on rotating your bounding collision primitives, you should just go with 3D math. Static rectangles would not be very accurate if the sprite objects rotate. IE, no reason to find collision points, since the points would be way off anyways.



Sorry, but I do not really understand this. Why should I use ''3D math'' (I assume that means 3d vectors, vertices, rotation matrices, boxes [instead of rectangles] etc.) instead of dealing with the two dimensional case?

Also, what do you mean by ''static rectangles''? I am striving for a rigid bodies simulator, so of course the rectangles will be rigid (if that''s what you meant with ''static'') - what would be the alternative?

quote:
Original post by Jiia
With static rectangles, it''s very easy to find the inner overlapping of any two colliding. That inner rectangle is basically the depth and points for both objects. If you plan to rotate it, I think sphere''s would be easier to work with. You could apply several to each object and rotate their offsets with the object.


Please see above.
Spheres are an entirely different type of geometric body, so for now I will focus on rect-rect collision (and maybe add confining lines (2d version of planes) ).

Somehow I just do not really get what you are trying to bring across, so please explain it to stupid me

Share this post


Link to post
Share on other sites
Circles are the easiest collision detection of all
After that, you might try line/line intersections for 2D polygons (pretty trivial) and if you want real accuracy have a search in sourceforge (www.sf.net) for a 2D sprite collision detection library - there are a few.

Writing your own circle/circle is easier than learning a 3rd party API. For sprites, and optimized, probably not

Share this post


Link to post
Share on other sites
quote:
Original post by AngelForce
Sorry, but I do not really understand this. Why should I use ''3D math'' (I assume that means 3d vectors, vertices, rotation matrices, boxes [instead of rectangles] etc.) instead of dealing with the two dimensional case?

I guess calling it 3D math wasn''t very accurate. You can use 2D vectors. But you don''t need vertices, matrices, or boxes

quote:
Also, what do you mean by ''static rectangles''?

I mean where left is always X, top is always Y, right is always X + width, etc. They don''t rotate.

quote:
Spheres are an entirely different type of geometric body, so for now I will focus on rect-rect collision (and maybe add confining lines (2d version of planes) ).

If you''re going all out for rigid body dynamics and such, that''s way over my head. I must have misunderstood your "nothing fancy" phrase.

As far as dynamically rotating collision areas, spheres (or circles) would be much easier to work with. If you plan on applying friction, stacks, etc, with rectangles, you would have no more difficulty doing it in 3D. Which happens to be where very few professional games have excelled. In other words, it gets difficult. And it''s definitely over my head

Share this post


Link to post
Share on other sites
You can try this library : http://www.ifm.liu.se/~ulfek/projects/SCAM-current/doc/SCAM.html

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!