-
Notifications
You must be signed in to change notification settings - Fork 0
/
body.t
129 lines (93 loc) · 4.18 KB
/
body.t
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
use strict;
use warnings;
use Test::More;
use Math::Trig qw(:pi);
use Chipmunk::Body;
use Chipmunk::Space;
# TODO: activate_static, sleep_with_group, get/set_user_data,
# reset_forces, apply_force, apply_impulse,
# get_vel_at_world_point, get_vel_at_local_point, kinetic_energy
{
my ( $mass, $inertia ) = ( 1.0, 2.0 );
my $body = Chipmunk::Body->new( $mass, $inertia );
isa_ok( $body, 'Chipmunk::Body', 'new' );
ok( !$body->is_static(), 'is_static (not static)' );
ok( $body->is_rogue(), 'is_rogue' );
my $space = Chipmunk::Space->new();
$space->add_body($body);
ok( !$body->is_rogue(), 'is_rogue (not rogue)' );
$body->sleep();
ok( $body->is_sleeping(), 'is_sleeping' );
$body->activate();
ok( !$body->is_sleeping(), 'is_sleeping (not sleeping)' );
isa_ok( $body->get_space(), 'Chipmunk::Space', 'get_space' );
cmp_ok( abs $body->get_mass() - $mass, '<', 1e-5, 'get_mass' );
$mass = 3.0;
$body->set_mass($mass);
cmp_ok( abs $body->get_mass() - $mass, '<', 1e-5, 'set_mass' );
cmp_ok( abs $body->get_moment() - $inertia, '<', 1e-5, 'get_moment' );
$inertia = 3.0;
$body->set_moment($inertia);
cmp_ok( abs $body->get_moment() - $inertia, '<', 1e-5, 'set_moment' );
cmp_ok( abs $body->get_pos()->[0] - 0.0, '<', 1e-5, 'get_pos x' );
cmp_ok( abs $body->get_pos()->[1] - 0.0, '<', 1e-5, 'get_pos y' );
my $pos = [ 5.0, 6.0 ];
$body->set_pos($pos);
cmp_ok( abs $body->get_pos()->[0] - $pos->[0], '<', 1e-5, 'set_pos x' );
cmp_ok( abs $body->get_pos()->[1] - $pos->[1], '<', 1e-5, 'set_pos y' );
cmp_ok( abs $body->get_vel()->[0] - 0.0, '<', 1e-5, 'get_vel x' );
cmp_ok( abs $body->get_vel()->[1] - 0.0, '<', 1e-5, 'get_vel y' );
my $vel = [ 7.0, 8.0 ];
$body->set_vel($vel);
cmp_ok( abs $body->get_vel()->[0] - $vel->[0], '<', 1e-5, 'set_vel x' );
cmp_ok( abs $body->get_vel()->[1] - $vel->[1], '<', 1e-5, 'set_vel y' );
cmp_ok( abs $body->get_force()->[0] - 0.0, '<', 1e-5, 'get_force x' );
cmp_ok( abs $body->get_force()->[1] - 0.0, '<', 1e-5, 'get_force y' );
my $force = [ 9.0, 10.0 ];
$body->set_force($force);
cmp_ok( abs $body->get_force()->[0] - $force->[0],
'<', 1e-5, 'set_force x' );
cmp_ok( abs $body->get_force()->[1] - $force->[1],
'<', 1e-5, 'set_force y' );
cmp_ok( abs $body->get_angle() - 0.0, '<', 1e-5, 'get_angle' );
my $angle = 1.1;
$body->set_angle($angle);
cmp_ok( abs $body->get_angle() - $angle, '<', 1e-5, 'set_angle' );
cmp_ok( abs $body->get_ang_vel() - 0.0, '<', 1e-5, 'get_ang_vel' );
my $ang_vel = 12.0;
$body->set_ang_vel($ang_vel);
cmp_ok( abs $body->get_ang_vel() - $ang_vel, '<', 1e-5, 'set_ang_vel' );
cmp_ok( abs $body->get_torque() - 0.0, '<', 1e-5, 'get_torque' );
my $torque = 13.0;
$body->set_torque($torque);
cmp_ok( abs $body->get_torque() - $torque, '<', 1e-5, 'set_torque' );
$body->set_angle(0.0);
cmp_ok( abs $body->get_rot()->[0] - 1.0, '<', 1e-5, 'get_rot x' );
cmp_ok( abs $body->get_rot()->[1] - 0.0, '<', 1e-5, 'get_rot y' );
$body->set_angle( pi / 2.0 );
cmp_ok( abs $body->get_rot()->[0] - 0.0, '<', 1e-5, 'get_rot x (pi/2)' );
cmp_ok( abs $body->get_rot()->[1] - 1.0, '<', 1e-5, 'get_rot y (pi/2)' );
my $vel_limit = 100.0;
$body->set_vel_limit($vel_limit);
cmp_ok( abs $body->get_vel_limit() - $vel_limit,
'<', 1e-5, 'set_vel_limit' );
my $ang_vel_limit = 101.0;
$body->set_ang_vel_limit($ang_vel_limit);
cmp_ok( abs $body->get_ang_vel_limit() - $ang_vel_limit,
'<', 1e-5, 'set_ang_vel_limit' );
$body->set_angle(0.0);
cmp_ok( abs $body->local_to_world( [ 0.0, 0.0 ] )->[0] - $pos->[0],
'<', 1e-5, 'local_to_world x' );
cmp_ok( abs $body->local_to_world( [ 0.0, 0.0 ] )->[1] - $pos->[1],
'<', 1e-5, 'local_to_world y' );
cmp_ok( abs $body->world_to_local($pos)->[0],
'<', 1e-5, 'world_to_local x' );
cmp_ok( abs $body->world_to_local($pos)->[1],
'<', 1e-5, 'world_to_local y' );
}
{
my $body = Chipmunk::Body->new_static();
isa_ok( $body, 'Chipmunk::Body', 'new_static' );
ok( $body->is_static(), 'is_static' );
}
done_testing();