Welcome to Dream.In.Code
Become an Expert!

Join 150,043 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,621 people online right now. Registration is fast and FREE... Join Now!




Collision Detection

 
Reply to this topicStart new topic

Collision Detection, Performance problems?

Pontus
4 Jun, 2008 - 08:19 AM
Post #1

Dreaming Coder / Coding Dreamer
Group Icon

Joined: 28 Dec, 2006
Posts: 544



Thanked: 4 times
Dream Kudos: 275
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 - 08:54 AM
User is offlineProfile CardPM
+Quote Post

BetaWar
RE: Collision Detection
8 Jun, 2008 - 09:12 AM
Post #2

#include <soul.h>
Group Icon

Joined: 7 Sep, 2006
Posts: 2,304



Thanked: 101 times
Dream Kudos: 1275
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
+Quote Post

Trogdor
RE: Collision Detection
9 Jun, 2008 - 02:56 AM
Post #3

D.I.C Addict
Group Icon

Joined: 6 Oct, 2006
Posts: 549



Thanked: 4 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
+Quote Post

stayscrisp
RE: Collision Detection
9 Jun, 2008 - 05:08 PM
Post #4

D.I.C Regular
***

Joined: 14 Feb, 2008
Posts: 284



Thanked: 11 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
+Quote Post

Pontus
RE: Collision Detection
10 Jun, 2008 - 08:53 AM
Post #5

Dreaming Coder / Coding Dreamer
Group Icon

Joined: 28 Dec, 2006
Posts: 544



Thanked: 4 times
Dream Kudos: 275
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
+Quote Post

Trogdor
RE: Collision Detection
11 Jun, 2008 - 02:53 AM
Post #6

D.I.C Addict
Group Icon

Joined: 6 Oct, 2006
Posts: 549



Thanked: 4 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
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 09:57PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month