Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411423 Posts in 69363 Topics- by 58416 Members - Latest Member: JamesAGreen

April 18, 2024, 07:58:58 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)detecting collision
Pages: [1]
Print
Author Topic: detecting collision  (Read 3751 times)
Jay Jeon
Level 0
***


Jay Jaewoo Jeon


View Profile WWW
« on: May 11, 2008, 07:38:20 AM »

http://www.youtube.com/v/0DrcxkcNeVk
this is my pysics engine demo.
but fps is very low.(about 30? or 20?)
I want to make faster. and I really wonder about aquaria's fps.
How could you keep 60 fps? besides, render and compute many things same time.
how? using separated space? or what?
« Last Edit: May 11, 2008, 07:50:01 AM by imwill » Logged

yet...
dustin
Level 6
*


View Profile
« Reply #1 on: May 11, 2008, 01:05:28 PM »

um... well what language is it written in?  Also are you using hardware acceleration for the graphics?  If not it could easily be your rendering method slowing things down.  Even so if your using a fast language (like c/c++ etc.) it does seem slow for just simple no torque physics like that.  I know in my java game I don't have a physics detection going on exactly like your but it's pretty simlar in terms of speed usage I would imagine (100 or so things colliding with 10 or so other objects which would be roughly equivalent to 32 things colliding with 32 other things) and I seem to be able to pretty easily get constant 60 fps and java is slower then c/c++.  I know your video is in flash so if this is programmed in flash then I would imagine that is the main reason why your fps is low...

If you want general tips in how to handle collision detection faster then I would suggest splitting the screen up into areas.  For example divide the screen into 4 quadrants, everything in the upper left only needs to worry about collision with other things in the upper left etc. That kinda thing helps a lot because then instead of 32 objects colliding with 32 other objects (1024 collisions possible) you only have to check

1.  each object with the 4 quadrants worst case (32*4=128)
2.  each object with the others in it's quadrant assuming equal distribution (32/4*32/4*4=256) the 32/4 are the number of objects in each quadrant and there are 4 quadrants in total.

Those add up to 128+256=384 as apposed to 1024.  Again though I would make sure nothings wrong before making your code more complicated even if it's not that much.  You could be not adressing the real problem.
« Last Edit: May 11, 2008, 01:10:55 PM by dustin » Logged
BenH
Level 2
**


Dirty boy, wash your hands!


View Profile WWW
« Reply #2 on: May 11, 2008, 01:51:05 PM »

Why not use an existing physics engine like Box2D or ODE?
Logged

Jay Jeon
Level 0
***


Jay Jaewoo Jeon


View Profile WWW
« Reply #3 on: May 11, 2008, 05:12:32 PM »

Quote
Why not use an existing physics engine like Box2D or ODE?
I think Box2D isn't good to compute a lots of thing at the same time.
(Box2D is too sensitive Lips Sealed)
That's why I use my simple pysics engine.

and dustin thank you.now I got it. :D
(Iam using C/C++ with directX.)
Logged

yet...
dustin
Level 6
*


View Profile
« Reply #4 on: May 11, 2008, 05:41:02 PM »

Quote
Why not use an existing physics engine like Box2D or ODE?

I can see not using one of thse just because it's fun coding your own and less complicated if you want a simpler physics engine...

Quote
and dustin thank you.now I got it. Cheesy
(Iam using C/C++ with directX.)

you are welcome however if your using c++ it seems weird that you are getting slow down with only 50 by 50 objects.  Just as a test I tried it with my own code which like I said is not exactly like yours but still.  I managed to do about 500*500 rectangular collision detections (plus displaying, and stuff) at 30 fps in java.  It seems like there might be something wrong with your code that's slowing it down a ton.
Logged
Jay Jeon
Level 0
***


Jay Jaewoo Jeon


View Profile WWW
« Reply #5 on: May 11, 2008, 05:54:43 PM »

Quote
you are welcome however if your using c++ it seems weird that you are getting slow down with only 50 by 50 objects.

Oh. Actually, now I use 450 boxes.
Logged

yet...
dustin
Level 6
*


View Profile
« Reply #6 on: May 11, 2008, 07:39:11 PM »

oh ok well sweet then!
Logged
Alex May
...is probably drunk right now.
Level 10
*


hen hao wan


View Profile WWW
« Reply #7 on: May 11, 2008, 10:08:36 PM »

If you want general tips in how to handle collision detection faster then I would suggest splitting the screen up into areas.  For example divide the screen into 4 quadrants, everything in the upper left only needs to worry about collision with other things in the upper left etc. That kinda thing helps a lot because then instead of 32 objects colliding with 32 other objects (1024 collisions possible) you only have to check

1.  each object with the 4 quadrants worst case (32*4=128)
2.  each object with the others in it's quadrant assuming equal distribution (32/4*32/4*4=256) the 32/4 are the number of objects in each quadrant and there are 4 quadrants in total.

Those add up to 128+256=384 as apposed to 1024.  Again though I would make sure nothings wrong before making your code more complicated even if it's not that much.  You could be not adressing the real problem.

This would cause problems for objects along the boundaries between the quadrants intersecting each other.

A better way would be to divide the space up into smaller partitions (let's call them buckets) and the have each object do collisions with things in adjacent buckets as well as the one it is in.

Also see Quadtrees.
Logged

dustin
Level 6
*


View Profile
« Reply #8 on: May 11, 2008, 10:14:36 PM »

yeah I know it's probably not the absolute best but it is the simplest I know of and it sure cuts down on the needed calculations.  Also you don't get the problems along the  boundaries as long as you specify that each object can be in multiple quadrants.  At least I don't see how...

Splitting the screen up into more then 4 areas is also what I was thinking of (I just suggested splitting it up into areas) but I didn't want to make my calculations over complicated Smiley
Logged
Alex May
...is probably drunk right now.
Level 10
*


hen hao wan


View Profile WWW
« Reply #9 on: May 11, 2008, 11:36:53 PM »

Ah, please forgive a tired programmer for being pedantic on a monday morning Smiley
Logged

Jay Jeon
Level 0
***


Jay Jaewoo Jeon


View Profile WWW
« Reply #10 on: May 12, 2008, 02:43:58 AM »

yeah, I've heard about Quad Tree on my class.
but I don't know how it works exactly. and It's so complicated to me. Roll Eyes
I think the best way is simple thing.
Logged

yet...
Alex May
...is probably drunk right now.
Level 10
*


hen hao wan


View Profile WWW
« Reply #11 on: May 12, 2008, 02:52:51 AM »

I've never found a straight-up bucket sort to be particularly lacking, personally. I've never implemented a quadtree!
Logged

DrDerekDoctors
THE ARSEHAMMER
Level 8
******



View Profile WWW
« Reply #12 on: May 13, 2008, 01:43:11 AM »

Another vote for bucket sort here! I use 'em in my engine and I can have craploads of stuff colliding at once without slowdown.
Logged

Me, David Williamson and Mark Foster do an Indie Games podcast. Give it a listen. And then I'll send you an apology.
http://pigignorant.com/
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic