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

Welcome to the AdaPhysics2D wiki! This page describes 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 to the world

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, and how to add it the world we created:

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 circle 
                Rest => 0.5,         -- the restitution factor, i.e. the "bounciness" of the circle 
                Rad => 5.0);         -- the radius of the circle

    -- Create a Rectangle
    R1 := Rectangles.Create(
                Pos => (0.0, 5.0),   -- the (x, y) coordinates of the bottom left corner of the rectangle
                Vel => (0.0, 0.0),   -- the (x, y) initial speed of the rectangle
                Grav => (0.0, 9.81), -- the (x, y) force field in which of the rectangle is
                Dim => (5.0, 10.0),  -- the (width, height) of the rectangle
                Mass => 10.0,        -- the mass of the rectangle
                Rest => 0.5);        -- the restitution factor, i.e. the "bounciness" of the rectangle
end Main;
Clone this wiki locally