2D physics resources

From Allegro Wiki

Jump to: navigation, search
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

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:

// 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?

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

ContinuousCollision

Personal tools