TIGSource Forums

Developer => Technical => Topic started by: Sigma on September 18, 2010, 06:19:58 AM



Title: ball physics
Post by: Sigma on September 18, 2010, 06:19:58 AM
Hi guys,
     can anyone give me a link or tutorial about collision detection and response between a slope and a ball? All helps are appreciated.

Thanks in advance...


Title: Re: ball physics
Post by: increpare on September 18, 2010, 06:30:46 AM
Question 1: Have you googled much?
Question 2: Is there a reason you're not using a physics library for your language?
Question 3: 2D or 3D?
Question 4: Do you want to do bouncing, rolling, &c.?


Title: Re: ball physics
Post by: Sigma on September 18, 2010, 06:45:30 AM
i have googled much i couldnt get any tutorials or samples and i dont want to use a physics library and the reason is i have to recode all the remaining stuffs, and its 2D, i want bouncing and rolling on a slope.

 


Title: Re: ball physics
Post by: biino on September 18, 2010, 07:02:23 AM
I don't exactly understand your reasoning not to use an existing library (an approach I'd recommend).

Check out http://procyclone.com/. It's the website for the physics engine development book I use. It's pretty good. The site has source code from the book (c++) but it might be hard to follow without the book.

Or check out the source for http://www.box2d.org/

Bino


Title: Re: ball physics
Post by: nikki on September 18, 2010, 07:04:46 AM
http://www.phy.uct.ac.za/demonline/virtual/slope.html (http://www.phy.uct.ac.za/demonline/virtual/slope.html)

i typed "physics ball slope" in google image search and clicked the first image


Title: Re: ball physics
Post by: bateleur on September 18, 2010, 07:31:28 AM
Or check out the source for http://www.box2d.org/

Whilst this is generally a very good idea I think it's probably overkill for his actual requirements. Ball/slope is very easy physics compared to the general-case rigid body stuff that Box2D simulates.

Box2D's code is surprisingly elegant for what it does, but it's still tricky stuff to understand, even for someone confident with both AS3 and Newtonian mechanics.


Title: Re: ball physics
Post by: st33d on September 18, 2010, 08:08:13 AM
For a beginner's introduction to ball vs line physics I can recommend Tony Pa's old vector tutorial:

http://www.tonypa.pri.ee/vectors/tut07.html

Once you've mastered the basic vector math he's outlined in it, then you can move on to more advanced physics engines. It's very easy to understand and is a great primer on vector math.

It's a tutorial I keep coming back to and one grew my geometry objects out of (although you would barely recognise the connection nowadays).

After you've tackled that, you'll want to learn "separating axis theorem". That will set you up for polygon collisions.

And if you want to do billiard ball collision, I posted a thread on an old forum here:

http://processing.org/discourse/yabb2/YaBB.pl?num=1201461240

It's a fairly basic version of billiard ball collision, but it does work.

For simply testing a collision between a circle and a line, then you can use the proximity() method in my Line object here:

http://github.com/st33d/red-rogue/blob/master/src/com/robotacid/geom/Line.as

Resolving the collision is something you'll have to figure out yourself - but as I said, work through the Tony Pa tutorial and you'll have a good foundation to grow from.


Title: Re: ball physics
Post by: Sigma on September 19, 2010, 02:43:22 AM
I have one more basic question sorry for asking such noob questions

AB is a line segment whose lenth is 50pixels and AB starts at 10,10 so the end point B of line segment AB is at 60,10.Now i rotates the line 40 deg with A as pivot point; now how can i find the end point B after rotation?

Thanks in advance


Title: Re: ball physics
Post by: st33d on September 19, 2010, 03:59:27 AM
Observe my line class again. Look for the method called rotateB. Convert your degrees to radians

radians = degrees * (Math.PI / 180)

use rotateB(radians)


Title: Re: ball physics
Post by: Sigma on September 19, 2010, 09:57:08 AM
Thanks man...