Welcome to Dream.In.Code
Getting Help is Easy!

Join 105,761 Programmers for FREE! Ask your question and get quick answers from experts. There are 1,756 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



Collision Detection

 
Reply to this topicStart new topic

Collision Detection, Performance problems?

manhaeve5
post 4 Jun, 2008 - 09:19 AM
Post #1


D.I.C Regular

Group Icon
Joined: 28 Dec, 2006
Posts: 491



Dream Kudos: 225
My Contributions


Hi there,

I'm developing an RPG (try nr .7) and i want to make my collision detection code better. Right now it checks if the locations of the given rectangle's corners is black on my collision map. If so it returns true, else false. It's very quick but it leaves me with a problem. If one of the sides of the rectangle is bigger then a object on the collision map it goes trough it. I was thinking of checking every pixel on the 4 edges of my rectangle, that should make it more 'waterproof'. But i'm afraid that it will get really slow on big rectangles. Is there an alternative?

Thanks in regards

Pontus

This post has been edited by manhaeve5: 10 Jun, 2008 - 09:54 AM
User is offlineProfile CardPM

Go to the top of the page


BetaWar
post 8 Jun, 2008 - 10:12 AM
Post #2


#include <soul.h>

Group Icon
Joined: 7 Sep, 2006
Posts: 1,011



Thanked 32 times

Dream Kudos: 675
My Contributions


Not exacly sure what you are using to make this, but you may be able to check is 2 lines collide instead of pixels. That would make things faster (I think) and would give you the result you are looking for (probably). But as I said, I am not sure what language you are using or if it even supports that type of thing (line collision).
User is offlineProfile CardPM

Go to the top of the page

Trogdor
post 9 Jun, 2008 - 03:56 AM
Post #3


D.I.C Regular

Group Icon
Joined: 6 Oct, 2006
Posts: 430



Thanked 1 times

Dream Kudos: 125
My Contributions


I thought that most sprite oriented libraries have collision detection built in.
Are you using any library like SDL or Allegro ?
User is offlineProfile CardPM

Go to the top of the page

stayscrisp
post 9 Jun, 2008 - 06:08 PM
Post #4


D.I.C Head

**
Joined: 14 Feb, 2008
Posts: 180



Thanked 4 times
My Contributions


SDL doesnt have built in collision that i know of, Are you using an OOP design, if so then it can make collision detection a lot simpler due to different types of objects intersecting, you could also try a circle bounding shape or like a capsule type shape although circles are easier they are also less accurate. could you post your collision code please?

cheers smile.gif
User is offlineProfile CardPM

Go to the top of the page

manhaeve5
post 10 Jun, 2008 - 09:53 AM
Post #5


D.I.C Regular

Group Icon
Joined: 28 Dec, 2006
Posts: 491



Dream Kudos: 225
My Contributions


Well, after a few (a bit confusing) posts i managed to figure it out myself. If a map has less then a certain number of rectangles to collide, it will use simple, fast collision check between rectangles. If it has more rectangles, it will use the collision map.

Thanks anyway for trying to help me! Much appreciated biggrin.gif

Greets

Robin
User is offlineProfile CardPM

Go to the top of the page

Trogdor
post 11 Jun, 2008 - 03:53 AM
Post #6


D.I.C Regular

Group Icon
Joined: 6 Oct, 2006
Posts: 430



Thanked 1 times

Dream Kudos: 125
My Contributions


You still might want to check out http://sdl-collide.sourceforge.net/
with in it boundingbox and pixelperfect collision detection.

This library does the following:
- It uses the bounding box collision detection to find a collision
- Then, using the pixel perfect collision to refine that collision
That way you only check the slower pixel perfect routines if you need to.

You can also use only boundingbox or circle collision dectection.

Ofcourse you can reinvent the wheel, but you dont need to.

Good luck.
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 8/21/08 01:23PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month