-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Welcome to the AdaPhysics2D wiki! This page describes how to use the engine easily.
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
-- Create the World object
W1 : Worlds.World;
-- Frames per seconds desired
fps : Float := 30;
dt : Float := 1.0 / fps;
begin
-- Initialize the world with its dt
W1.Init(dt);
end Main;
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
-- Add the Circle and the Rectangle to the World we created
W1.Add(C1);
W1.Add(R1);
end Main;
Now that the world is full of entities, you just need to use the Step
primitive on the World object. It will then make the entities evolve for dt
seconds. The primitive GetEntities
will return an array, a EArray
containing accesses to all the entities. You just then to get their Coords and render !
loop
W1.Step;
declare
Ents : Worlds.EArray := W1.GetEntities;
begin
for I of Ents loop
Put(if I.EntityType = Entities.EntRectangle then "Re" else "Ci");
Put_Line(+I.Coords);
end loop;
delay 0.1;
end;
end loop;