1
/* This example demostrates physics actions, like applying impulses and forces
4
* There are two ways of interacting with bodies. One is using the wanted
5
* action in a program. E.g.:
7
* action: PHYSICS_VEL_SET 0 -200 0;
10
* The other way is via script. The same action described above would be
11
* physics_set_velocity(PART:"part_name", 0, -200, 0);
13
* This a very extensive example, because it illustrate the usage of all
14
* the possible actions in the both ways.
16
* It can be tested with edje_player slave mode
17
* $ edje_player -S -p physics_actions.edj
19
* signal up impulse -> will throw both balls up
20
* signal down impulse -> will throw both balls down
21
* signal left impulse -> will throw blue ball to the left
22
* signal right impulse -> will throw red ball to the right
23
* signal clockwise impulse -> will roll blue ball in clockwise
24
* signal counterclockwise impulse -> will roll blue ball in counterclockwise
25
* signal up force -> will apply a force up in blue ball
26
* signal down force -> will apply a force down in blue ball
27
* signal left force -> will apply a force left in blue ball
28
* signal right force -> will apply a force right in blue ball
29
* signal clockwise torque -> will apply a clockwise torque in blue ball
30
* signal counterclockwise torque -> will apply a counterclockwise torque
32
* signal clear force -> will clear all forces applied over blue ball
33
* signal up velocity -> will set a velocity up in blue ball
34
* signal down velocity -> will set a velocity down in blue ball
35
* signal left velocity -> will set a velocity left in blue ball
36
* signal right velocity -> will set a velocity right in blue ball
37
* signal clockwise velocity -> will set a clockwise velocity in blue ball
38
* signal counterclockwise velocity -> will set a counterclockwise velocity
40
* signal stop velocity -> will stop the blue ball
41
* signal clockwise rotation -> will rotate blue ball 90o degrees clockwise
42
* signal counterclockwise rotation -> will rotate blue ball 90o degrees
45
* message 1 FLOAT_SET 3 50 -100 0 -> apply an impulse on blue ball with
46
* x = 50, y = -100, z = 0, for example
47
* message 2 FLOAT_SET 3 0 0 8.2 -> apply a torque impulse on blue ball with
48
* x = 4, y = 0, z = 0.8, for example
49
* message 3 FLOAT_SET 3 80 100.4 0 -> apply a force on blue ball with
50
* x = 80, y = 100.4, z = 0, for example
51
* message 4 FLOAT_SET 3 0 0 -5.6 -> apply a torque on blue ball with
52
* x = 0, y = 0, z = -5.6, for example
53
* message 5 STRING "blue_circle" -> clear all forces of part.
54
* It will clear all forces (linear and torque) over "blue_circle",
56
* message 6 STRING "blue_circle" -> return a message with all forces applied
58
* message 7 STRING "blue_circle" -> return a message with all torques applied
60
* message 8 FLOAT_SET 3 300 -103.2 0 -> set linear velocity of the blue ball
61
* with x = 300, y = -103.2, z = 150, for example
62
* message 9 STRING "blue_circle" -> return a message with part's linear
64
* message 10 FLOAT_SET 3 0 0 150 -> set angular velocity of the blue ball
65
* with x = 0, y = 0, z = 150, for example
66
* message 11 STRING "blue_circle" -> return a message with part's angular
68
* message 12 STRING "blue_circle" -> stop the part.
69
* message 13 FLOAT_SET 4 0.707 0 0 0.707 -> set blue ball rotation with
70
* quaternion w = 0.707, x = 0, y = 0, z = 0.707
71
* message 14 STRING "blue_circle" -> return a message with part's rotation
75
#define ID_TORQUE_IMPULSE (2)
78
#define ID_FORCES_CLEAR (5)
79
#define ID_FORCES_GET (6)
80
#define ID_TORQUES_GET (7)
83
#define ID_ANG_VEL_SET (10)
84
#define ID_ANG_VEL_GET (11)
86
#define ID_ROT_SET (13)
87
#define ID_ROT_GET (14)
92
image: "bubble-blue.png" COMP;
96
name: "example_group";
99
public message(Msg_Type:type, id, ...) {
100
if ((id == ID_IMPULSE) && (type == MSG_FLOAT_SET)) {
101
new Float:x, Float:y, Float:z;
107
physics_impulse(PART:"blue_circle", x, y, z);
109
else if ((id == ID_TORQUE_IMPULSE) && (type == MSG_FLOAT_SET)) {
110
new Float:x, Float:y, Float:z;
116
physics_torque_impulse(PART:"blue_circle", x, y, z);
118
else if ((id == ID_FORCE) && (type == MSG_FLOAT_SET)) {
119
new Float:x, Float:y, Float:z;
125
physics_force(PART:"blue_circle", x, y, z);
127
else if ((id == ID_TORQUE) && (type == MSG_FLOAT_SET)) {
128
new Float:x, Float:y, Float:z;
134
physics_torque(PART:"blue_circle", x, y, z);
136
else if ((id == ID_FORCES_CLEAR) && (type == MSG_STRING)) {
138
getsarg(2, name, sizeof(name));
139
pid = get_part_id(name);
141
physics_clear_forces(pid);
143
else if ((id == ID_FORCES_GET) && (type == MSG_STRING)) {
144
new Float:x, Float:y, Float:z;
146
getsarg(2, name, sizeof(name));
147
pid = get_part_id(name);
149
physics_get_forces(pid, x, y, z);
150
send_message(MSG_FLOAT_SET, id, x, y, z);
152
else if ((id == ID_TORQUES_GET) && (type == MSG_STRING)) {
153
new Float:x, Float:y, Float:z;
155
getsarg(2, name, sizeof(name));
156
pid = get_part_id(name);
158
physics_get_torques(pid, x, y, z);
159
send_message(MSG_FLOAT_SET, id, x, y, z);
161
else if ((id == ID_VEL_SET) && (type == MSG_FLOAT_SET)) {
162
new Float:x, Float:y, Float:z;
168
physics_set_velocity(PART:"blue_circle", x, y, z);
170
else if ((id == ID_VEL_GET) && (type == MSG_STRING)) {
171
new Float:x, Float:y, Float:z;
173
getsarg(2, name, sizeof(name));
174
pid = get_part_id(name);
176
physics_get_velocity(pid, x, y, z);
177
send_message(MSG_FLOAT_SET, id, x, y, z);
179
else if ((id == ID_ANG_VEL_SET) && (type == MSG_FLOAT_SET)) {
180
new Float:x, Float:y, Float:z;
186
physics_set_ang_velocity(PART:"blue_circle", x, y, z);
188
else if ((id == ID_ANG_VEL_GET) && (type == MSG_STRING)) {
189
new Float:x, Float:y, Float:z;
191
getsarg(2, name, sizeof(name));
192
pid = get_part_id(name);
194
physics_get_ang_velocity(pid, x, y, z);
195
send_message(MSG_FLOAT_SET, id, x, y, z);
197
else if ((id == ID_STOP) && (type == MSG_STRING)) {
199
getsarg(2, name, sizeof(name));
200
pid = get_part_id(name);
204
else if ((id == ID_ROT_SET) && (type == MSG_FLOAT_SET)) {
205
new Float:w, Float:x, Float:y, Float:z;
212
physics_set_rotation(PART:"blue_circle", w, x, y, z);
214
else if ((id == ID_ROT_GET) && (type == MSG_STRING)) {
215
new Float:w, Float:x, Float:y, Float:z;
217
getsarg(2, name, sizeof(name));
218
pid = get_part_id(name);
220
physics_get_rotation(pid, w, x, y, z);
221
send_message(MSG_FLOAT_SET, id, w, x, y, z);
232
state: "default" 0.0;
233
color: 255 255 255 255; /* white */
234
rel1.relative: 0.0 0.0;
235
rel2.relative: 1.0 1.0;
242
physics_body: RIGID_SPHERE;
244
state: "default" 0.0;
245
rel1.relative: 0.35 0.1;
246
rel2.relative: 0.55 0.2;
249
normal: "bubble-blue.png";
261
physics_body: RIGID_SPHERE;
263
state: "default" 0.0;
264
color: 255 0 0 255; /* light red */
265
rel1.relative: 0.65 0.1;
266
rel2.relative: 0.85 0.2;
269
normal: "bubble-blue.png";
281
physics_body: BOUNDARY_BOTTOM;
283
state: "default" 0.0;
295
physics_body: BOUNDARY_RIGHT;
297
state: "default" 0.0;
308
physics_body: BOUNDARY_LEFT;
310
state: "default" 0.0;
321
physics_body: BOUNDARY_TOP;
323
state: "default" 0.0;
338
action: PHYSICS_IMPULSE 0 -300 0;
339
target: "blue_circle";
340
target: "red_circle";
344
name: "impulse_down";
347
action: PHYSICS_IMPULSE 0 300 0;
348
target: "red_circle";
349
target: "blue_circle";
353
name: "impulse_left";
356
action: PHYSICS_IMPULSE -300 0 0;
357
target: "blue_circle";
361
name: "impulse_right";
364
action: PHYSICS_IMPULSE 300 0 0;
365
target: "red_circle";
369
name: "impulse_clockwise";
372
action: PHYSICS_TORQUE_IMPULSE 0 0 4;
373
target: "blue_circle";
377
name: "impulse_counterclockwise";
378
signal: "counterclockwise";
380
action: PHYSICS_TORQUE_IMPULSE 0 0 -4;
381
target: "blue_circle";
388
action: PHYSICS_FORCE 0 -300 0;
389
target: "blue_circle";
396
action: PHYSICS_FORCE 0 300 0;
397
target: "blue_circle";
404
action: PHYSICS_FORCE -300 0 0;
405
target: "blue_circle";
412
action: PHYSICS_FORCE 300 0 0;
413
target: "blue_circle";
417
name: "torque_clockwise";
420
action: PHYSICS_TORQUE 0 0 4;
421
target: "blue_circle";
425
name: "torque_counterclockwise";
426
signal: "counterclockwise";
428
action: PHYSICS_TORQUE 0 0 -4;
429
target: "blue_circle";
433
name: "forces_clear";
436
action: PHYSICS_FORCES_CLEAR;
437
target: "blue_circle";
444
action: PHYSICS_VEL_SET 0 -200 0;
445
target: "blue_circle";
449
name: "velocity_down";
452
action: PHYSICS_VEL_SET 0 200 0;
453
target: "blue_circle";
457
name: "velocity_left";
460
action: PHYSICS_VEL_SET -200 0 0;
461
target: "blue_circle";
465
name: "velocity_right";
468
action: PHYSICS_VEL_SET 200 0 0;
469
target: "blue_circle";
473
name: "velocity_clockwise";
476
action: PHYSICS_ANG_VEL_SET 0 0 80;
477
target: "blue_circle";
481
name: "velocity_counterclockwise";
482
signal: "counterclockwise";
484
action: PHYSICS_ANG_VEL_SET 0 0 -80;
485
target: "blue_circle";
492
action: PHYSICS_STOP;
493
target: "blue_circle";
497
name: "rotation_clockwise";
500
action: PHYSICS_ROT_SET 0.707 0 0 0.707;
501
target: "blue_circle";
505
name: "rotation_counterclockwise";
506
signal: "counterclockwise";
508
action: PHYSICS_ROT_SET 0.707 0 0 -0.707;
509
target: "blue_circle";
516
new Float: mass, Float:rest, Float:fric;
517
new Float: linear, Float:angular;
520
custom_state(PART:"red_circle", "default", 0.0);
521
set_state_val(PART:"red_circle", STATE_COLOR, 0, 0, 0, 255);
522
set_state_val(PART:"red_circle", STATE_PHYSICS_MASS, 4.5);
523
set_state_val(PART:"red_circle", STATE_PHYSICS_RESTITUTION, 0.1);
524
set_state_val(PART:"red_circle", STATE_PHYSICS_FRICTION, 0.345);
525
set_state_val(PART:"red_circle", STATE_PHYSICS_DAMPING, 0.3,
527
set_state_val(PART:"red_circle", STATE_PHYSICS_SLEEP, 34.1,
529
set_state_val(PART:"red_circle", STATE_PHYSICS_LIGHT_ON, 1);
530
set_state_val(PART:"red_circle",
531
STATE_PHYSICS_IGNORE_PART_POS, 1);
532
set_state_val(PART:"red_circle", STATE_PHYSICS_Z, -40);
533
set_state_val(PART:"red_circle", STATE_PHYSICS_DEPTH, 80);
534
set_state(PART:"red_circle", "custom", 0.0);
536
get_state_val(PART:"red_circle", STATE_PHYSICS_MASS, mass);
537
get_state_val(PART:"red_circle", STATE_PHYSICS_RESTITUTION,
539
get_state_val(PART:"red_circle", STATE_PHYSICS_FRICTION,
541
send_message(MSG_STRING_FLOAT_SET, 1, "Mass", mass);
542
send_message(MSG_STRING_FLOAT_SET, 1, "Friction", fric);
543
send_message(MSG_STRING_FLOAT_SET, 1, "Restitution", rest);
545
get_state_val(PART:"red_circle", STATE_PHYSICS_DAMPING,
547
send_message(MSG_STRING_FLOAT_SET, 1, "Damping", linear,
550
get_state_val(PART:"red_circle", STATE_PHYSICS_SLEEP,
552
send_message(MSG_STRING_FLOAT_SET, 1, "Sleep", linear,
555
get_state_val(PART:"red_circle", STATE_PHYSICS_LIGHT_ON, val);
556
send_message(MSG_STRING_INT, 1, "Light On", val);
558
get_state_val(PART:"red_circle",
559
STATE_PHYSICS_IGNORE_PART_POS, val);
560
send_message(MSG_STRING_INT, 1, "Ignore Part Pos", val);
562
get_state_val(PART:"red_circle", STATE_PHYSICS_Z, val);
563
send_message(MSG_STRING_INT, 1, "Z", val);
565
get_state_val(PART:"red_circle", STATE_PHYSICS_DEPTH, val);
566
send_message(MSG_STRING_INT, 1, "Depth", val);