need verlet-rect collisions or verlet-poly

BlitzMax Forums/BlitzMax Programming/need verlet-rect collisions or verlet-poly

Nate the Great(Posted 2009) [#1]
Hi

I am newish to blitz max but in no way new to programming
to the point.. I was working on a little physics project just to get used to using types lists inheritence etc when I cam upon a problem.. I really want to make this into a game but I need verlet to rect collisions (verlet to poly works even better!) I have come up with some code but it slows my game down so much (not to mention it is buggy) that rather than handle 700-800 verlets and constraints, it now only handles 90-100 :(

here is the code I am using

variables:
v.x = verlet x
v.y = verlet y
v.ox = verlet old x
v.oy = verlet old y
v.siz = verlet radius

s.x1 = rect upper left corner x value
s.y1 = rect upper left corner y value
s.width = rect width
s.height = rect height

df vars:

dfu = distance from upper side
dfd = distance from lower side
dfl = distance from left side
dfr = distance from right side



if anyone has any fast code for verlet-rect collisions please post.
also does anyone know why the above code is slowing down my program? am I using a slow command in bmax? thanks


Jesse(Posted 2009) [#2]
why don't you use box2d or chipmunt from Brucey's modules. I am shure they can handle what you want really easy and you won't have to worry about dealing with a lot of complex math and the reinventing the wheel. Both modules have demos with source to learn from. Best of all they are FREE. Well, he accept donations, if you care.
... maybe you want to learn how to do everything yourself, In that case, ignore me.


Nate the Great(Posted 2009) [#3]
I really want to learn how to do it myself but I will definitely take a look a bruceys modules thanks :)


BlitzSupport(Posted 2009) [#4]
Have you seen 3D "Verlet" Collision Engine in the Code Archives?


BlitzSupport(Posted 2009) [#5]
Ah, don't know if that does the specific collision types you're after -- apologies if not!


Nate the Great(Posted 2009) [#6]
hmmm that is interesting as far as optimization but it wasnt what I was looking for. I was after 2D circle-box collisions which seem to be a lot harder and slower than planned. does anyone Know what is so slow about the code in my first post? is it possible all of the > and < are slowing it down?


Vilu(Posted 2009) [#7]
If the rectangles are arbitrarily rotated and not axis-oriented, your best bet would be to look into line-circle intersection algorithm here:

http://www.blitzbasic.com/codearcs/codearcs.php?code=2130

I'm sure there are tons of other resources available so there is no need to reinvent the wheel :)

If all the methods are too slow for your collision detection, I suggest you go for a 2-stage collision detection routine. First you detect a preliminary circle-to-circle (=distance) collision test, and do the real collision detection only for the objects that fail the preliminary check. That should cut down the amount of checked objects dramatically in most applications.


Nate the Great(Posted 2009) [#8]
ok thanks for the link. At first I was thinking of having axis-oriented rectangles but with that algorithm combined with a few of my own I can do circle-poly collisions! thanks