2D physics resources
From Allegro Wiki
This article or section is messy and needs some minor revision to bring it up to quality standards. Please help Allegro by editing it. When the article is formatted correctly, you may remove this tag.
Contents |
List of threads about 2d Physics
- http://www.allegro.cc/forums/thread/592338
- http://www.allegro.cc/forums/thread/412455
- http://www.allegro.cc/forums/thread/591727
- http://www.allegro.cc/forums/thread/588089
- http://www.allegro.cc/forums/thread/547610
- http://www.allegro.cc/forums/thread/340244
- http://www.allegro.cc/forums/thread/590241
- http://www.allegro.cc/forums/thread/593026
External links extracted from above
Physics Libraries
- http://www.gphysics.com/physics-engines Erin Catto's list of links
- http://www.gphysics.com/downloads/ and his Box2d code and tutes
- http://wiki.slembcke.net/main/published/Chipmunk 2d collision lib in C99. MIT licence
See also List of 3d Physics Libraries
Articles and Tutorials
- http://www.ioi.dk/Homepages/thomasj/publications/gdc2001.htm broken link (Bad Gateway)
- http://en.wikipedia.org/wiki/Physics_engine
File Formats
Frequently Asked Questions
How do I make gravity affect something?
Simple. That "something" must have a velocity property. Then you just increase the velocity by gravity. Some pseudo code:
// main loop
while(...)
{
// every object has a speed on x and y
// gravity only changes y speed
object.speed_y += gravity; // Done!
// ... Drawing etc. ...
}
How do I detect when my ball collides with my bat?
How do I detect when two balls collide?
You must use the Circle Colision Technique.
It's only you verify if the distance between the balls centers is less then the sum of the radius. If it's true, the balls is coliding.
Example:
#include <math.h>
struct sBall
{
int x, y, radius;
}
...
sBall ball1, ball2;
...
int dx, dy;
while (loop)
{
...
if (ball1.x > ball2.x)
dx = ball1.x - ball2.x;
else
dx = ball2.x - ball2.y;
if (ball1.y > ball2.y)
dy = ball1.y - ball2.y
else
dy = ball2.y - ball1.y
if (sqrt(dx*dx + dy*dy) > ball1.radius + ball2.radius)
{
// The balls is coliding!
}
...
}
Very simple, it isn't?
