-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrectangles.adb
66 lines (56 loc) · 1.69 KB
/
rectangles.adb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
with Ada.Unchecked_Deallocation;
package body Rectangles is
-- Initialization of a Rectangle
procedure Initialize(This : in RectangleAcc;
Pos, Vel, Grav, Dim : in Vec2D; Mat : in Material)
is
begin
Entities.Initialize(Entities.Entity(This.all),
Entities.EntRectangle, Pos, Vel, Grav, Mat);
This.all.Dim := Dim;
This.all.ComputeMass;
end Initialize;
-- Create a new Rectangle
function Create(Pos, Vel, Grav, Dim : in Vec2D; Mat : in Material) return EntityClassAcc
is
TmpAcc : EntityClassAcc;
begin
TmpAcc := new Rectangle;
Initialize(RectangleAcc(TmpAcc), Pos, Vel, Grav, Dim, Mat);
return TmpAcc;
end Create;
function GetHeight(This : in Rectangle) return Float
is
begin
return This.Dim.y;
end GetHeight;
function GetWidth(This : in Rectangle) return Float
is
begin
return This.Dim.x;
end GetWidth;
function GetCenter(This : in Rectangle) return Vec2D
is
begin
return This.Coords + (This.Dim / 2.0);
end GetCenter;
procedure ComputeMass(This : in out Rectangle)
is
begin
This.Mass := This.Dim.x * This.Dim.y * This.Mat.Density;
This.InvMass := (if This.Mass = 0.0 then 0.0 else 1.0 / This.Mass);
end ComputeMass;
procedure FreeEnt(This : access Rectangle)
is
procedure FreeRectangle is new Ada.Unchecked_Deallocation(Rectangle, RectangleAcc);
P : RectangleAcc := RectangleAcc(This);
begin
FreeRectangle(P);
end FreeEnt;
overriding
function GetPosition(This : in Rectangle) return Vec2D
is
begin
return This.GetCenter;
end GetPosition;
end Rectangles;