Skip to content
Alexandre Poumaroux edited this page Nov 26, 2018 · 20 revisions

Welcome to the AdaPhysics2D wiki! This will describe how to use the engine easily.

Creating a world

First, you need to create a World object (in the Worlds package), and initialize it with its delta time dt. This is the time that will be used while integrating the forces and the velocities: the smaller the better, but keep in mind that a too small value will be very intensive. In the code below, you can as well edit the fps that stands for "frames per seconds", and it will automatically deduce the the dt to use.

with Worlds;

procedure Main is
    W1 : Worlds.World;
    fps : Float := 30;
    dt : Float := 1.0 / fps;
begin
    W1.Init(dt);
end Main;

Adding entities

Now that the world is created, you need to add entities to it. Each type of entity has its own package. For now, there is only two: Circles and Rectangles. Each package comes with a Create member function returning an access to the entity. Here's how to create an entity of each type, with its parameters:

with Worlds;
with Rectangles;
with Circles;

procedure Main is
    W1 : Worlds.World;
    C1 : Circles.CircleAcc;
    R1 : Rectangles.RectangleAcc;
    fps : Float := 30;
    dt : Float := 1.0 / fps;
begin
    W1.Init(dt);
    
    -- Create a Circle.
    -- 
    C1 := Circles.Create(Pos => (0.0, 5.0),   -- the (x, y) coordinates of the center of the circle
                         Vel => (0.0, 0.0),   -- the (x, y) initial speed of the circle
                         Grav => (0.0, 9.81), -- the (x, y) force field in which of the circle is
                         Mass => 10.0,        -- the mass of the object
                         Rest => 0.5,         -- the restitution factor, i.e. the "bounciness" of the object
                         Rad => 5.0);         -- the radius of the circle

    R1 := Rectangles.Create(Vec1, VecZero, VecZero, Vec2, 0.0, 1.0);
end Main;
Clone this wiki locally