The Allegro Wiki is migrating to github at

2D physics resources

From Allegro Wiki
Jump to: navigation, search
Broom icon.png
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.

This article is incomplete and needs some revision or has some pending TODOs. Please help Allegro by editing and finishing it. When the article becomes complete, you may remove this tag.

List of threads about 2d Physics

External links extracted from above

Physics Libraries

See also List of 3d Physics Libraries

Articles and Tutorials

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: <highlightSyntax language="cpp"> // main loop while(...) {

   // every object has a speed on x and y
   // gravity only changes y speed
   object.speed_y += gravity;    // Done!
   // ... Drawing etc. ...

} </highlightSyntax>

How do I detect when my ball collides with my bat?

How do I detect when two circles collide?

Two circles are colliding when the distance between the circle's centers is less than the sum of the circles' radii.


#include <math.h>

typedef struct Circle
   float x, y, radius;

bool is_circles_colliding(const Circle& c1, const Circle& c2)
   float sum_radii = c1.radius + c2.radius;
   float dx = c1.x - c2.x;
   float dy = c2.y - c2.y;
   return (sum_radii) > (dx * dx + dy * dy);

How do I stop my ball going through the bat when it's travelling too fast?