efl

Форк
0
/
ephysics_examples.dox 
1790 строк · 53.9 Кб
1
/**
2
 * @page ephysics_examples EPhysics Examples
3
 *
4
 * Examples:
5
 * @li @ref tutorial_ephysics_bouncing_ball
6
 * @li @ref tutorial_ephysics_bouncing_text
7
 * @li @ref tutorial_ephysics_camera
8
 * @li @ref tutorial_ephysics_camera_track
9
 * @li @ref tutorial_ephysics_collision_detection
10
 * @li @ref tutorial_ephysics_collision_filter
11
 * @li @ref tutorial_ephysics_delete_body
12
 * @li @ref tutorial_ephysics_constraint
13
 * @li @ref tutorial_ephysics_forces
14
 * @li @ref tutorial_ephysics_growing_balls
15
 * @li @ref tutorial_ephysics_gravity
16
 * @li @ref tutorial_ephysics_logo
17
 * @li @ref tutorial_ephysics_rotating_forever
18
 * @li @ref tutorial_ephysics_velocity
19
 * @li @ref tutorial_ephysics_shapes
20
 * @li @ref tutorial_ephysics_sleeping_threshold
21
 * @li @ref tutorial_ephysics_slider
22
 */
23

24
/**
25
 * @page tutorial_ephysics_bouncing_ball EPhysics - Bouncing Ball
26
 *
27
 * The purpose of this example is to show how to write an simple application -
28
 * as the name suggests - with a small ball bouncing on the ground and
29
 * responding to users events by making it jump - applying a central impulse on
30
 * it.
31
 *
32
 * @image html bouncing_ball.png
33
 * @image latex bouncing_ball.eps
34
 *
35
 * We'll guide you on defining a EPhysics world, defining its render geometry
36
 * and the physics limiting boundaries, you'll learn how to add EPhysics bodies
37
 * and how to associate it to evas objects.  We also explain how to change
38
 * restitution and friction properties. We see how to apply central impulse on
39
 * a EPhysics_Body by implementing an elementary input event callback and
40
 * calling the proper function.
41
 *
42
 * @section test-structure A test struct
43
 * @dontinclude ephysics_test.h
44
 *
45
 * While in this example we'll be working with a struct to hold some objects in
46
 * our code. For clarity sake we present you the struct declaration in the
47
 * following block.
48
 *
49
 *
50
 * @skip struct _Test_Data
51
 * @until };
52
 *
53
 * @section world-new World Initialization
54
 * @dontinclude test_bouncing_ball.c
55
 *
56
 * Calling ephysics_world_new()
57
 * will create a new physics world with its collision configuration, constraint
58
 * solver, broadphase interface and dispatcher.
59
 *
60
 * The default gravity is set to -9.81. It's possible to stop a running world
61
 * but its default status is running. Take a look at
62
 * ephysics_world_running_set() for further informations about world running
63
 * status.
64
 *
65
 * @skipline ephysics_world_new
66
 *
67
 * @section render-geometry Render geometry
68
 *
69
 * By setting the render geometry you tell ephysics the dimensions of rendered
70
 * area to be take on account by default updates.
71
 *
72
 * By default it starts with null x, y, z, width, height and depth. Initially 
73
 * there's no physics limits but - as we'll see later in this example -
74
 * boundaries can be added by issuing either ephysics_body_top_boundary_add(),
75
 * ephysics_body_bottom_boundary_add(), ephysics_body_left_boundary_add() and
76
 * ephysics_body_right_boundary_add().
77
 *
78
 * While setting the worlds render geometry the first parameter is our just
79
 * created world, the following parameters indicate the x, y, z, width, height
80
 * and depth of our area of interest.
81
 *
82
 * @skip ephysics_world_render_geometry_set
83
 * @until DEPTH);
84
 *
85
 * @section boundaries Adding boundaries
86
 *
87
 * Boundaries are physics limits added by EPhysics which you can use to limit
88
 * the area where your objects can move around. Bear in mind that those
89
 * boundaries are created by EPhysics taking in account the render geometry you
90
 * have previously defined by calling ephysics_world_render_geometry_set().
91
 *
92
 * In our example we start by adding a bottom boundary. This EPhysics_Body
93
 * represents a physics limit under the world render geometry.
94
 *
95
 * The second line states the restitution factor for that bottom boundary, and
96
 * the third line its friction. These changes will make our ball to bounce
97
 * whenever it hits the ground.
98
 *
99
 * @skip ephysics_body_bottom_boundary_add
100
 * @until ephysics_body_friction_set
101
 *
102
 * Then we add a right boundary limiting the physics world on the left side, we
103
 * also change its restitution and friction factors but with a smaller value,
104
 * we don't want to make it bounce as much as it is when hits the ground.
105
 *
106
 * @skip ephysics_body_right_boundary_add
107
 * @until ephysics_body_friction_set
108
 *
109
 * We also add a left boundary taking the same considerations for right
110
 * boundary.
111
 *
112
 * @skip ephysics_body_left_boundary_add
113
 * @until ephysics_body_friction_set
114
 *
115
 * One of this examples requirements is to make the ball jump after a specific
116
 * user event, so the ball can suffer an impulse for any direction.
117
 *
118
 * With an upper impulse we don't want our ball to fly all over there, we want
119
 * to limit its upper movements, it's intended to limit the ball movement
120
 * within a box, it should not leave the render geometry area, for that purpose
121
 * we must define a top boundary.
122
 *
123
 * @skipline ephysics_body_top_boundary_add
124
 * @dontinclude test_bouncing_ball.c
125
 *
126
 * @section world-populate Adding a ball
127
 *
128
 * Since we have defined the physics limits with our boundaries it's time to
129
 * add some fun. Here we add a ball as an elementary image widget and tell
130
 * ephysics about it.
131
 *
132
 * After setting the file that will be used as the image's source of our elm
133
 * image we move it to the center of render geometry and resize it to 70x70
134
 * pixels and show it.
135
 *
136
 * @skip elm_image_add
137
 * @until evas_object_show
138
 *
139
 * The evas object is just set and we must tell EPhysics about it, creating the
140
 * EPhysics_Body representing our ball and associating it to the just created
141
 * evas object.
142
 *
143
 * Once the ball has been moved to the center of render geometry it should
144
 * start falling after associating it to the EPhysics_Body. By default its mass
145
 * is initially set to 1 kilo, but it can be changed by calling
146
 * ephysics_body_mass_set(). Bear in mind that if you change its mass to 0
147
 * kilos it becomes a static body and will not move at all, the body will
148
 * remain fixed in the initial position.
149
 *
150
 * In the following code the first line adds a circle body, then we associate
151
 * the evas object to EPhysics_Body, EPhysics will map every changes on physics
152
 * object simulation to its evas object. Some restitution and friction factors
153
 * are added as well.
154
 *
155
 * @skip ephysics_body_cylinder_add
156
 * @until ephysics_body_friction_set
157
 *
158
 * @section jumping-ball Making it jump
159
 *
160
 * The next step is to give us the ability to make our ball to jump - actually
161
 * apply some impulse whenever a key has been pressed. Then we add a elementary
162
 * input callback to the window widget.
163
 *
164
 * @skipline elm_object_event_callback_add
165
 *
166
 * @dontinclude test_bouncing_ball.c
167
 *
168
 * The jumping callback implementation consists on handling only key up events
169
 * and discarding any other input event we get. We're interested on keyboard
170
 * events only. All the operations done in the following lines are done on
171
 * sphere EPhysics_Body previously created.
172
 *
173
 * We mainly use the ephysics_body_central_impulse_apply() function. This
174
 * function applies an impulse on the center of a body.
175
 *
176
 * Once pressed \<Up> key it applies a central impulse of 0 kilos on X axis,
177
 * 10 kilos on Y and 0 kilos on Z - so the ball is forced up.
178
 *
179
 * If \<Down> key has been pressed we apply an impulse of 0 kilos on X axis,
180
 * -10 kilos on Y and 0 kilos on Z - here the ball is forced down.
181
 *
182
 * In the case of \<Right> key pressing it's applied an impulse of 10 kilos on X
183
 * axis, 0 kilos on Y and 0 kilos on Z - which applies a force to the right side.
184
 * But if the key being pressed is \<Left> the opposite is done, and an impulse
185
 * of -10 kilos is applied on X, 0 kilos on Y and 0 kilos on Z - and the ball is
186
 * forced to the left.
187
 *
188
 * @skip _on_keydown
189
 * @until }
190
 *
191
 * Here we finish the very simple bouncing ball example. The full source code
192
 * can be found at @ref test_bouncing_ball_c.
193
 *
194
 */
195

196
/**
197
 * @page test_bouncing_ball_c test_bouncing_ball.c
198
 *
199
 * # ephysics_test.h
200
 * @include ephysics_test.h
201
 *
202
 * @section test-bouncing-ball-c test_bouncing_ball.c
203
 * @dontinclude test.c
204
 * @skip test_clean
205
 * @until }
206
 *
207
 * @skip test_data_new
208
 * @until }
209
 *
210
 * @skip test_win_add
211
 * @until }
212
 *
213
 * @include test_bouncing_ball.c
214
 *
215
 *
216
 * @example test_bouncing_ball.c
217
 */
218

219
/**
220
 * @page tutorial_ephysics_bouncing_text EPhysics - Bouncing Text
221
 *
222
 * The purpose of this example is to demonstrate the EPhysics_Body binding to
223
 * a text (Evas_Object)
224
 *
225
 * @image html bouncing_text.png
226
 * @image latex bouncing_text.eps
227
 *
228
 * For this example we'll have an EPhysics_World and one basic EPhysics_Body.
229
 *
230
 * The basic concepts like - initializing an EPhysics_World, render geometry,
231
 * physics limiting boundaries, were already covered in
232
 * @ref tutorial_ephysics_bouncing_ball
233
 *
234
 * @section add-text Creating the text
235
 * @dontinclude test_bouncing_text.c
236
 *
237
 * Create a basic evas_object_text.
238
 *
239
 * @skipline Evas_Object *text;
240
 *
241
 * @skip text =
242
 * @until text);
243
 *
244
 * @section add-textbody Creating the body
245
 *
246
 * Create a simple EPhysics_Body.
247
 *
248
 * Note that we use ephysics_body_geometry_set() to define its size because
249
 * the evas_object has a different size that we want to represent physically.
250
 * The text may have accent or letters like j and g.
251
 *
252
 * @skipline text_body =
253
 * @skip ephysics_body_geometry_set(text_body
254
 * @until 0.1);
255
 *
256
 * @section text-binding Binding
257
 * @dontinclude test_bouncing_text.c
258
 *
259
 * After creating the body and the text, now we need to bind them.
260
 *
261
 * We set the last parameter as EINA_FALSE because in this example we don't
262
 * want to set the physics body position to match evas object position.
263
 *
264
 * @skipline ephysics_body_evas_object_set
265
 *
266
 * Here we finish the example. The full source code can be found at
267
 * @ref test_bouncing_text_c.
268
 *
269
 */
270

271
 /**
272
 * @page test_bouncing_text_c test_bouncing_text.c
273
 *
274
 * # ephysics_test.h
275
 * @include ephysics_test.h
276
 *
277
 * @section test-bouncing_text-c test_bouncing_text.c
278
 * @dontinclude test.c
279
 *
280
 * @skip test_clean
281
 * @until }
282
 *
283
 * @skip test_data_new
284
 * @until }
285
 *
286
 * @skip test_win_add
287
 * @until }
288
 *
289
 * @include test_bouncing_text.c
290
 *
291
 * @example test_bouncing_text.c
292
 */
293

294
/**
295
 * @page tutorial_ephysics_camera EPhysics - Camera
296
 *
297
 * The purpose of this example is to demonstrate the EPhysics_Camera usage.
298
 *
299
 * The EPhysics_Camera facilitates the usage of scenarios bigger than the
300
 * viewport, that's because the EPhysics handles the position of objects
301
 * which has control.
302
 *
303
 * @image html camera.png
304
 * @image latex camera.eps
305
 *
306
 * For this example we'll have an EPhysics_World, two distant EPhysics_Bodys,
307
 * one with an impulse to collide each other and an EPhysics_Camera that
308
 * follows the moving body using an animator.
309
 *
310
 * The basic concepts like - initializing an EPhysics_World, render geometry,
311
 * physics limiting boundaries, add an Ephysics_Body, associate it to evas
312
 * objects, change restitution, friction and impulse properties, were
313
 * already covered in
314
 * @ref tutorial_ephysics_bouncing_ball
315
 *
316
 * @section add-camstruct Camera Data Struct
317
 * @dontinclude test_camera.c
318
 *
319
 * While in this example we'll be working with a struct to hold some objects
320
 * in our code. For clarity sake we present you the struct declaration in the
321
 * following block.
322
 *
323
 * @skip struct _Camera_Data {
324
 * @until };
325
 *
326
 * # Adding a Camera
327
 *
328
 * To move the camera in this example, we'll use an animator.
329
 *
330
 * @skipline camera_data->animator = ecore_animator_add
331
 *
332
 * In the animators function, we'll have to create a specific type of variable:
333
 * @ref EPhysics_Camera
334
 * And also get the worlds rendered area width to define a limit to the camera.
335
 *
336
 * @dontinclude test_camera.c
337
 *
338
 * @skip _camera_move_cb(void *data
339
 * @until &w, NULL, NULL);
340
 *
341
 * Every world has a camera, so here we get this camera used by our
342
 * EPhysics_World.
343
 *
344
 * @skipline camera = ephysics_world_camera_get
345
 *
346
 * Here we get the cameras position to after set the position based on previous.
347
 *
348
 * @skipline ephysics_camera_position_get(camera
349
 *
350
 * Here we check if the camera reached the end of scenario (define the limit
351
 * to the camera) then we stop the animator, else we move the camera + 2
352
 * pixel positions to the right.
353
 *
354
 * @skip if (x + w > WIDTH * 2)
355
 * @until ephysics_camera_position_set(camera, x, y
356
 * @skipline }
357
 *
358
 * # Updating the floor
359
 *
360
 * Here we'll use 2 floor images to give the impression of an infinite ground.
361
 *
362
 * Calling ephysics_world_event_callback_add()
363
 * will register a callback to a type of physics world event.
364
 *
365
 * @ref EPHYSICS_CALLBACK_WORLD_CAMERA_MOVED : called if the camera position
366
 * changed on physics simulation tick.
367
 *
368
 * @skip ephysics_world_event_callback_add(world,
369
 * @until _camera_moved_cb, camera_data);
370
 *
371
 * In the function, we just get the cameras position to know how much
372
 * the camera moved and move the same value to the floor passing it as
373
 * delta_x to the function, note that we use an old_x variable to do this
374
 * calculation.
375
 * @dontinclude test_camera.c
376
 *
377
 * @skip _camera_moved_cb(void *data
378
 * @until }
379
 *
380
 * Here we get the floors position and plus the delta_x value to move the
381
 * floor in the same "velocity".
382
 *
383
 * @dontinclude test_camera.c
384
 *
385
 * @skip _update_floor
386
 * @until fx = x + delta
387
 *
388
 * We use 2 floor images because whenever one exits the screen by the left
389
 * side, another is being shown, when it happens the one which exit the screen
390
 * is sent to the right side, entering into an infinite loop, giving the
391
 * impression of an infinite ground image. Its important to note that we need
392
 * to use the fx to don't gap the images.
393
 *
394
 * @skip if (fx < -FLOOR_WIDTH
395
 * @until }
396
 *
397
 * Here we finish the example. The full source code can be found at
398
 * @ref test_camera_c.
399
 *
400
 */
401

402
 /**
403
 * @page test_camera_c test_camera.c
404
 *
405
 * # ephysics_test.h
406
 * @include ephysics_test.h
407
 *
408
 * @section test-camera-c test_camera.c
409
 * @dontinclude test.c
410
 *
411
 * @skip test_clean
412
 * @until }
413
 *
414
 * @skip test_win_add
415
 * @until }
416
 *
417
 * @include test_camera.c
418
 *
419
 * @example test_camera.c
420
 */
421

422
/**
423
 * @page tutorial_ephysics_camera_track EPhysics - Camera Track
424
 *
425
 * The purpose of this example is to demonstrate the EPhysics_Camera Track
426
 * usage.
427
 *
428
 * The EPhysics_Camera facilitates the usage of scenarios bigger than the
429
 * viewport, that's because the EPhysics handles the position of objects
430
 * which has control.
431
 *
432
 * @image html camera_track.png
433
 * @image latex camera_track.eps
434
 *
435
 * For this example we'll have an EPhysics_World, one main EPhysics_Body that
436
 * will be tracked by an EPhysics_Camera on three ways, horizontal, vertical
437
 * and full tracking. Also nine EPhysics_Bodys with mass 0, that will be used
438
 * as scenario in order to our main body change its position on x and y axes
439
 * when passes through this scenario.
440
 *
441
 * The basic concepts like - initializing an EPhysics_World, render geometry,
442
 * physics limiting boundaries, add an Ephysics_Body, associate it to evas
443
 * objects, change restitution, friction and impulse properties, were
444
 * already covered in
445
 * @ref tutorial_ephysics_bouncing_ball
446
 *
447
 * @section add-trkstruct Track Data Struct
448
 * @dontinclude test_camera_track.c
449
 *
450
 * While in this example we'll be working with a struct to hold some objects
451
 * in our code. For clarity sake we present you the struct declaration in the
452
 * following block.
453
 *
454
 * @skip struct _Track_Data {
455
 * @until };
456
 *
457
 * # Adding a Camera
458
 *
459
 * In this example we'll use 3 kinds of tracking, to change this values we'll
460
 * have an Elementary spinner widget and handle it on this function.
461
 *
462
 * Every world has a camera, so here we get this camera used by our
463
 * EPhysics_World.
464
 *
465
 * @skip _track_apply(Track_Data *track
466
 * @until camera = ephysics_world_camera_get(track_data->base.world
467
 *
468
 * Here we'll get the elm_spinner value to the tracking base on this
469
 * value
470
 *
471
 * @skip mode =
472
 * @until }
473
 *
474
 * Here we'll set the camera to track the body, when a body is tracked,
475
 * the camera will move automatically, following this body. It will keeps the
476
 * body centralized on rendered area. If it will be centralized horizontally
477
 * and / or vertically depends if parameters horizontal and vertical are set
478
 * to EINA_TRUE, in this case we based these values on elm_spinner.
479
 *
480
 * @skip ephysics_camera_body_track(camera, body
481
 * @until }
482
 *
483
 * # Updating the floor
484
 *
485
 * Here we'll use 2 floor images to give the impression of an infinite ground.
486
 *
487
 * Calling ephysics_world_event_callback_add()
488
 * will register a callback to a type of physics world event.
489
 *
490
 * @ref EPHYSICS_CALLBACK_WORLD_CAMERA_MOVED : called if the camera position
491
 * changed on physics simulation tick.
492
 *
493
 * @skip ephysics_world_event_callback_add(world,
494
 * @until _camera_moved_cb, track_data);
495
 *
496
 * In the function, we'll get the cameras position to know how much the camera
497
 * moved and move the same value to the floor passing it as delta_x to the
498
 * function, note that we use an old_x variable to do this calculation.
499
 *
500
 * We'll get also if the body is being tracked on x and y axes. If the body
501
 * isn't being tracked on x axis the floors x position won't change, delta_x
502
 * will be zero.
503
 *
504
 * @dontinclude test_camera_track.c
505
 *
506
 * @skip _camera_moved_cb(void *data
507
 * @until }
508
 *
509
 * Here we get the floors position and plus the delta_x value to move the
510
 * floor in the same "velocity".
511
 *
512
 * @dontinclude test_camera_track.c
513
 *
514
 * @skip _update_floor
515
 * @until fx = x + delta
516
 *
517
 * We use 2 floor images because whenever one exits the screen by the left
518
 * side, another is being shown, when it happens the one which exit the screen
519
 * is sent to the right side, entering into an infinite loop, giving the
520
 * impression of an infinite ground image. Its important to note that we need
521
 * to use the fx to don't gap the images.
522
 *
523
 * Note that the fy is being defined considering its offsets, -20 is to the
524
 * floor image be above the floor, thus having an border above the collision
525
 * point, +40 is the render area height, to offset the cameras y, basically
526
 * to draw in the correct position in the canvas.
527
 *
528
 * @skip if (fx < -FLOOR_WIDTH
529
 * @until }
530
 *
531
 * Here we finish the example. The full source code can be found at
532
 * @ref test_camera_track_c.
533
 *
534
 */
535

536
 /**
537
 * @page test_camera_track_c test_camera_track.c
538
 *
539
 * # ephysics_test.h
540
 * @include ephysics_test.h
541
 *
542
 * @section test-camera-track-c test_camera_track.c
543
 * @dontinclude test.c
544
 *
545
 * @skip test_clean
546
 * @until }
547
 *
548
 * @skip test_win_add
549
 * @until }
550
 *
551
 * @include test_camera_track.c
552
 *
553
 * @example test_camera_track.c
554
 */
555

556
/**
557
 * @page tutorial_ephysics_collision_detection EPhysics - Collision Detection
558
 *
559
 * The purpose of this example is to demonstrate the EPhysics Collision
560
 * Detection usage - The code adds two balls, one with impulse and the second
561
 * with a collision detection callback, to show an effect.
562
 *
563
 * @image html collision_detection.png
564
 * @image latex collision_detection.eps
565
 *
566
 * For this example we'll have an EPhysics_World, and two basic EPhysics_Bodys,
567
 * we'll apply an impulse in one of then and the other will be stopped
568
 * "waiting" for a collision.
569
 *
570
 * The basic concepts like - initializing an EPhysics_World, render geometry,
571
 * physics limiting boundaries, add an Ephysics_Body, associate it to evas
572
 * objects, change restitution, friction and impulse properties, were
573
 * already covered in
574
 * @ref tutorial_ephysics_bouncing_ball
575
 *
576
 * @section add-collstruct Collision Data Struct
577
 * @dontinclude test_collision_detection.c
578
 *
579
 * While in this example we'll be working with a struct to hold some objects
580
 * in our code. For clarity sake we present you the struct declaration in the
581
 * following block.
582
 *
583
 * @skip struct _Collision_Data {
584
 * @until };
585
 *
586
 * # Adding the Callback
587
 *
588
 * Calling ephysics_body_event_callback_add()
589
 * will register a callback to a type of physics body event.
590
 *
591
 * @ref EPHYSICS_CALLBACK_BODY_COLLISION : called just after the collision has
592
 * been actually processed by the physics engine. In other words, to be
593
 * notified about a collision between two physical bodies.
594
 *
595
 * @skip ephysics_body_event_callback_add(collision_data->sphere
596
 * @until );
597
 *
598
 * See
599
 * @ref _EPhysics_Callback_Body_Type
600
 * for more event types.
601
 *
602
 * @section add-collcb Collision Function
603
 *
604
 * The callback function will filter the collision to be sure if that body is
605
 * which we want and then show the effect.
606
 *
607
 * First we need to create a specific variable type to get collision infos:
608
 * @ref EPhysics_Body_Collision
609
 *
610
 * @dontinclude test_collision_detection.c
611
 *
612
 * @skip _collision_cb
613
 * @until int x, y, z;
614
 *
615
 * Now we want to know which body collides with and filter it.
616
 *
617
 * @skip contact_body =
618
 * @until return;
619
 *
620
 * We just get the collision position, move the impact effect to this
621
 * coordinate and send a signal to edje to show it.
622
 *
623
 * @skip ephysics_body_collision_position_get
624
 * @until "ephysics_test");
625
 * @skipline }
626
 *
627
 * Here we finish the example. The full source code can be found at
628
 * @ref test_collision_detection_c.
629
 *
630
 */
631

632
 /**
633
 * @page test_collision_detection_c test_collision_detection.c
634
 *
635
 * # ephysics_test.h
636
 * @include ephysics_test.h
637
 *
638
 * @section test-collision_detection-c test_collision_detection.c
639
 * @dontinclude test.c
640
 *
641
 * @skip test_clean
642
 * @until }
643
 *
644
 * @skip test_win_add
645
 * @until }
646
 *
647
 * @include test_collision_detection.c
648
 *
649
 * @example test_collision_detection.c
650
 */
651

652
/**
653
 * @page tutorial_ephysics_collision_filter EPhysics - Collision Filter
654
 *
655
 * The purpose of this example is to demonstrate the EPhysics Collision Filter
656
 * usage - The code adds four balls in 2 rows and 2 columns, two on each
657
 * collision group, the collision only happens when the balls are in the
658
 * same group (row),to make it easier, balls in the same group has the same
659
 * color and size.
660
 *
661
 * @image html collision_filter.png
662
 * @image latex collision_filter.eps
663
 *
664
 * For this example we'll have an EPhysics_World and four basic EPhysics_Bodys,
665
 * we'll apply an impulse on then and see what happens when they're in other
666
 * collision group.
667
 *
668
 * The basic concepts like - initializing an EPhysics_World, render geometry,
669
 * physics limiting boundaries, add an Ephysics_Body, associate it to evas
670
 * objects, change restitution, friction and impulse properties, were
671
 * already covered in
672
 * @ref tutorial_ephysics_bouncing_ball
673
 *
674
 * # Adding the balls
675
 * @dontinclude test_collision_filter.c
676
 *
677
 * We'll use two arrays (color and size) to distinguish the groups.
678
 *
679
 * @skip _world_populate
680
 * @until row;
681
 *
682
 * The balls declaration was placed into a For loop, just to simplify the
683
 * coding and divide them in two groups.
684
 *
685
 * @skip for (i = 0; i < 4
686
 * @until 0.1);
687
 *
688
 * Note in this part we divide the balls in two groups by color (row).
689
 *
690
 * @skipline ephysics_body_collision_group_add(fall_body
691
 *
692
 * The impulse will be applied in only 1 ball per group, in this case:
693
 *
694
 * The 1st row 2nd column ball will be applied an impulse to the
695
 * left (-300kg * p/s).
696
 *
697
 * The 2nd row 1st column ball will be applied an impulse to the
698
 * right (300kg * p/s).
699
 *
700
 * And then saving the body into a list.
701
 *
702
 * @skip if (column + row == 1
703
 * @until }
704
 * @skipline }
705
 *
706
 * Here we finish the example. The full source code can be found at
707
 * @ref test_collision_filter_c.
708
 *
709
 */
710

711
 /**
712
 * @page test_collision_filter_c test_collision_filter.c
713
 *
714
 * # ephysics_test.h
715
 * @include ephysics_test.h
716
 *
717
 * @section test-collision_filter-c test_collision_filter.c
718
 * @dontinclude test.c
719
 *
720
 * @skip test_clean
721
 * @until }
722
 *
723
 * @skip test_data_new
724
 * @until }
725
 *
726
 * @skip test_win_add
727
 * @until }
728
 *
729
 * @include test_collision_filter.c
730
 *
731
 * @example test_collision_filter.c
732
 */
733

734
/**
735
 * @page tutorial_ephysics_delete_body EPhysics - Delete Body
736
 *
737
 * The purpose of this example is to demonstrate the EPhysics Callbacks usage -
738
 * The code adds two balls, one with impulse and the second with a collision
739
 * detection callback, to delete the body.
740
 *
741
 * For this example we'll have an EPhysics_World and two basic EPhysics_Bodys,
742
 * we'll apply an impulse in one of then and the other will be stopped
743
 * "waiting" for a collision.
744
 *
745
 * The basic concepts like - initializing an EPhysics_World, render geometry,
746
 * physics limiting boundaries, add an EPhysics_Body, associate it to evas
747
 * objects, change restitution, friction and impulse properties, were already
748
 * covered in
749
 * @ref tutorial_ephysics_bouncing_ball
750
 *
751
 * # Adding Callbacks
752
 * @dontinclude test_delete.c
753
 *
754
 * Calling ephysics_body_event_callback_add()
755
 * registers a callback to a given EPhysics_Body event type.
756
 *
757
 * We'll use two types:
758
 *
759
 * @ref EPHYSICS_CALLBACK_BODY_DEL : called when a body deletion has been issued
760
 * and just before the deletion actually happens. In other words, to know that
761
 * body has been marked for
762
 * deletion. Typically to free some data associated with the body.
763
 *
764
 * @skipline ephysics_body_event_callback_add(sphere_body1,
765
 * @skip EPHYSICS_CALLBACK_BODY_DEL
766
 * @until );
767
 *
768
 * The callback function will receive the collision_data and free some data
769
 * associated with the body.
770
 *
771
 * @dontinclude test_delete.c
772
 *
773
 * @skip _del_cb(void *data,
774
 * @until }
775
 *
776
 * @ref EPHYSICS_CALLBACK_BODY_COLLISION : called just after the collision has
777
 * been actually processed by the physics engine. In other words, to be notified
778
 * about a collision between two physical bodies.
779
 *
780
 * @skip ephysics_body_event_callback_add(collision_data->sphere,
781
 * @until );
782
 *
783
 * The callback function will get the collision body and check if its body is
784
 * equal to which we want to delete.
785
 *
786
 * @dontinclude test_delete.c
787
 *
788
 * @skip _collision_cb(void *data,
789
 * @until }
790
 *
791
 * See
792
 * @ref _EPhysics_Callback_Body_Type
793
 * for more event types.
794
 *
795
 * Here we finish the example. The full source code can be found at
796
 * @ref test_delete_c.
797
 *
798
 */
799

800
 /**
801
 * @page test_delete_c test_delete.c
802
 *
803
 * # ephysics_test.h
804
 * @include ephysics_test.h
805
 *
806
 * @section test-delete-c test_delete.c
807
 * @dontinclude test.c
808
 * @skip test_clean
809
 * @until }
810
 *
811
 * @skip test_win_add
812
 * @until }
813
 *
814
 * @include test_delete.c
815
 *
816
 * @example test_delete.c
817
 */
818

819
 /**
820
 * @page tutorial_ephysics_constraint EPhysics - Constraint
821
 *
822
 * The purpose of this example is to demonstrate the EPhysics Constraint usage -
823
 * The code apply a constraint between two cubes.
824
 *
825
 * For this example we'll have an EPhysics_World, and two basic EPhysics_Bodys.
826
 *
827
 * The basic concepts like - defining an EPhysics_World, render geometry,
828
 * physics limiting boundaries, add an EPhysics_Body, associate it to evas
829
 * objects, change restitution, friction and impulse properties, were
830
 * already covered in
831
 * @ref tutorial_ephysics_bouncing_ball
832
 *
833
 * You can use also a slider constraint:
834
 * @ref tutorial_ephysics_slider
835
 *
836
 * @section add-constraint Adding a constraint
837
 * @dontinclude test_constraint.c
838
 *
839
 * Constraint is a specific type of variable in EPhysics.
840
 *
841
 * @skipline EPhysics_Constraint
842
 *
843
 * Here we're working with a point-to-point constraint, its purpose is to join
844
 * two bodies limiting their movements based on specified anchors.
845
 *
846
 * After we create our 2 EPhysics_Bodys, now we'll add a constraint between
847
 * them and setting an anchor to first body's Y using a p2p constraint
848
 * (point to point).
849
 *
850
 * @skip constraint = ephysics_constraint_p2p
851
 * @until );
852
 *
853
 * Here we finish the example. The full source code can be found at
854
 * @ref test_constraint_c.
855
 *
856
 */
857

858
 /**
859
 * @page test_constraint_c test_constraint.c
860
 *
861
 * # ephysics_test.h
862
 * @include ephysics_test.h
863
 *
864
 * @section test-constraint-c test_constraint.c
865
 * @dontinclude test.c
866
 *
867
 * @skip test_clean
868
 * @until }
869
 *
870
 * @skip test_data_new
871
 * @until }
872
 *
873
 * @skip test_win_add
874
 * @until }
875
 *
876
 * @include test_constraint.c
877
 *
878
 * @example test_constraint.c
879
 */
880

881
 /**
882
 * @page tutorial_ephysics_forces EPhysics - Forces
883
 *
884
 * The purpose of this example is to demonstrate the EPhysics Force usage -
885
 * The code applies force over two cubes.
886
 *
887
 * @image html forces.png
888
 * @image latex forces.eps
889
 *
890
 * For this example we'll have an EPhysics_World with gravity setted to zero,
891
 * and two basic EPhysics_Bodys.
892
 *
893
 * The basic concepts like - defining an EPhysics_World, render geometry,
894
 * physics limiting boundaries, add an EPhysics_Body, associate it to evas
895
 * objects, change restitution, friction and impulse properties, were
896
 * already covered in
897
 * @ref tutorial_ephysics_bouncing_ball
898
 *
899
 * @section add-force Adding a Force
900
 * @dontinclude test_forces.c
901
 *
902
 * We apply a force over the first body to change its linear and angular
903
 * accelerations. Applying a force to a body will lead it to change its
904
 * velocity gradually.
905
 *
906
 * Note that in this blue cube we use an offset to apply the force, the two
907
 * last parameters are responsible to set a relative position to apply the
908
 * force.In other words, the force applied with an offset will make the body
909
 * rotates. Otherwise (0, 0, 0) the force would be applied on the center of the
910
 * body, in this case its recommended use the
911
 * ephysics_body_central_force_apply();
912
 *
913
 * @skipline ephysics_body_force_apply(box_body1
914
 *
915
 * Here we apply a central force over the second body avoiding affect the
916
 * angular acceleration (rotate).
917
 *
918
 * @skipline ephysics_body_central_force_apply(box_body2
919
 *
920
 * We can also get all the forces applied over a body, including gravity, but
921
 * in this case we setted to zero.
922
 *
923
 * @dontinclude test_forces.c
924
 *
925
 * @skipline ephysics_body_forces_get(
926
 *
927
 * Here we finish the example. The full source code can be found at
928
 * @ref test_forces_c.
929
 *
930
 */
931

932
 /**
933
 * @page test_forces_c test_forces.c
934
 *
935
 * # ephysics_test.h
936
 * @include ephysics_test.h
937
 *
938
 * @section test-forces-c test_forces.c
939
 * @dontinclude test.c
940
 *
941
 * @skip test_clean
942
 * @until }
943
 *
944
 * @skip test_data_new
945
 * @until }
946
 *
947
 * @skip test_win_add
948
 * @until }
949
 *
950
 * @include test_forces.c
951
 *
952
 * @example test_forces.c
953
 */
954

955
 /**
956
 * @page tutorial_ephysics_growing_balls EPhysics - Growing Balls
957
 *
958
 * The purpose of this example is to demonstrate the dynamically growing
959
 * and shrinking of an EPhysics_Body - The code applies the growth of a ball
960
 * and the shrink of another.
961
 *
962
 * @image html growing_balls.png
963
 * @image latex growing_balls.eps
964
 *
965
 * For this example we'll have an EPhysics_World and three EPhysics_Bodys
966
 * with different sizes associated with an evas_object.
967
 *
968
 * The basic concepts like - defining an EPhysics_World, render geometry,
969
 * physics limiting boundaries, add an EPhysics_Body, associate it to evas
970
 * objects, change restitution, friction and impulse properties, were
971
 * already covered in
972
 * @ref tutorial_ephysics_bouncing_ball
973
 *
974
 * @section add-growshrink Adding the growing/shrinking
975
 * @dontinclude test_growing_balls.c
976
 *
977
 * In this example we'll use a timer to handle the callback function.
978
 *
979
 * @skipline test_data->data = ecore_timer_add
980
 *
981
 * In this callback, we'll pass through a list with 3 balls and apply the
982
 * growth and the shrink between the limit we'll set. Note that the variable
983
 * i receives different values on each iteration (-1, 0, 1). For the first
984
 * iteration it will decrease the size variable, the second will keep the
985
 * same value, and the last one will increase the size variable.
986
 *
987
 * @dontinclude test_growing_balls.c
988
 *
989
 * @skip _grow_cb(void *data
990
 * @until return EINA_TRUE;
991
 * @skipline }
992
 *
993
 * Here we finish the example. The full source code can be found at
994
 * @ref test_growing_balls_c.
995
 *
996
 */
997

998
 /**
999
 * @page test_growing_balls_c test_growing_balls.c
1000
 *
1001
 * # ephysics_test.h
1002
 * @include ephysics_test.h
1003
 *
1004
 * @section test-growing-balls-c test_growing_balls.c
1005
 * @dontinclude test.c
1006
 *
1007
 * @skip test_clean
1008
 * @until }
1009
 *
1010
 * @skip test_data_new
1011
 * @until }
1012
 *
1013
 * @skip test_win_add
1014
 * @until }
1015
 *
1016
 * @include test_growing_balls.c
1017
 *
1018
 * @example test_growing_balls.c
1019
 */
1020

1021
 /**
1022
 * @page tutorial_ephysics_gravity EPhysics - Gravity
1023
 *
1024
 * The purpose of this example is to demonstrate the EPhysics Gravity usage -
1025
 * The code apply gravity in an EPhysics_World with two cubes in movement.
1026
 *
1027
 * @image html no_gravity.png
1028
 * @image latex no_gravity.eps
1029
 *
1030
 * For this example we'll have an EPhysics_World, and two basic EPhysics_Bodys.
1031
 *
1032
 * The basic concepts like - defining an EPhysics_World, render geometry,
1033
 * physics limiting boundaries, add an EPhysics_Body, associate it to evas
1034
 * objects, change restitution, friction and impulse properties, were
1035
 * already covered in
1036
 * @ref tutorial_ephysics_bouncing_ball
1037
 *
1038
 * Concepts like velocity and sleeping threshold were already
1039
 * covered in:
1040
 * @li @ref tutorial_ephysics_velocity
1041
 * @li @ref tutorial_ephysics_sleeping_threshold
1042
 *
1043
 * @section add-gravity Setting Gravity
1044
 * @dontinclude test_no_gravity.c
1045
 *
1046
 * Here we set gravity on 3 axes (x, y, z) to (0, 0, 0). Gravity will act
1047
 * over bodies with mass over all the time.
1048
 *
1049
 * @skipline ephysics_world_gravity_set
1050
 *
1051
 * @section add-stopbody Stopping a Body
1052
 * @dontinclude test_no_gravity.c
1053
 *
1054
 * We're using a button to call this function that receives test_data to stop
1055
 * the chosen body.
1056
 *
1057
 * Stop angular and linear body movement, its equivalent to set linear velocity
1058
 * to 0 on both axis and angular velocity to 0 as well.
1059
 *
1060
 * @skip _stop(void *data
1061
 * @until body);
1062
 * @skipline }
1063
 *
1064
 * Here we finish the example. The full source code can be found at
1065
 * @ref test_no_gravity_c.
1066
 *
1067
 */
1068

1069
 /**
1070
 * @page test_no_gravity_c test_no_gravity.c
1071
 *
1072
 * # ephysics_test.h
1073
 * @include ephysics_test.h
1074
 *
1075
 * @section test-no-gravity-c test_no_gravity.c
1076
 * @dontinclude test.c
1077
 *
1078
 * @skip test_clean
1079
 * @until }
1080
 *
1081
 * @skip test_data_new
1082
 * @until }
1083
 *
1084
 * @skip test_win_add
1085
 * @until }
1086
 *
1087
 * @include test_no_gravity.c
1088
 *
1089
 * @example test_no_gravity.c
1090
 */
1091

1092
/**
1093
 * @page tutorial_ephysics_logo EPhysics - Logo
1094
 *
1095
 * The purpose of this example is to demonstrate the EPhysics_Logo.
1096
 *
1097
 * For this example we'll have an EPhysics_World.
1098
 *
1099
 * The basic concepts like - initializing an EPhysics_World, render geometry,
1100
 * physics limiting boundaries, were already covered in
1101
 * @ref tutorial_ephysics_bouncing_ball
1102
 *
1103
 * @section add-logostruct Logo Data Struct
1104
 * @dontinclude ephysics_logo.c
1105
 *
1106
 * While in this example we'll be working with a struct to hold some objects
1107
 * in our code. For clarity sake we present you the struct declaration in the
1108
 * following block.
1109
 *
1110
 * @skip struct letter_desc {
1111
 * @until };
1112
 *
1113
 * @section add-lett Adding the letters
1114
 * @dontinclude ephysics_logo.c
1115
 *
1116
 * To add the letters we'll use this function that creates the shadow, light
1117
 * and letter images.
1118
 *
1119
 * @skip _letter_add(Evas *evas
1120
 * @until }
1121
 *
1122
 * In this loop we'll use the function letter_add using the falling_letters
1123
 * declared in logo data struct.
1124
 *
1125
 * @skip for (i = 0; i < EINA_C_ARRAY
1126
 * @until (image, &w, &h);
1127
 *
1128
 * Place image and light on top, above what the viewport can show, to fall
1129
 * later on.
1130
 *
1131
 * @skip evas_object_move(image, x,
1132
 * @until evas_object_move(light, x, -h * (i + 1) - 50);
1133
 *
1134
 * Place shadow below the hit-line: FLOOR_Y, centered at image.
1135
 *
1136
 * @skipline evas_object_move(shadow, x + CENTER(w, sh_w
1137
 *
1138
 * Here we set the letters padding and add letter body using the function
1139
 * below and setting its friction.
1140
 *
1141
 * @skip x += falling_letters[i].padd
1142
 * @until }
1143
 *
1144
 * Here we call another function that will be common to the circle body as
1145
 * well, note that we add a callback that will be explained later.
1146
 * @dontinclude ephysics_logo.c
1147
 *
1148
 * @skip _letter_body_box_add(EPhysics_World *world
1149
 * @until }
1150
 *
1151
 * This function is used to create the body setting its properties. Note that
1152
 * we disable its angular movement (rotation) on Z axis to this letters don't
1153
 * tilt or recline.
1154
 * @dontinclude ephysics_logo.c
1155
 *
1156
 * @skip _letter_body_setup_common(EPhysics_Body *body
1157
 * @until }
1158
 *
1159
 * In this callback function that we added to our letter body we'll update its
1160
 * light and shadow.
1161
 *
1162
 * First we'll update the body, get its image geometry and set the floor
1163
 * distance based on images height.
1164
 *
1165
 * @dontinclude ephysics_logo.c
1166
 *
1167
 * @skip _update_box_cb(void *data
1168
 * @until floor_distance = FLOOR_Y - h;
1169
 *
1170
 * As long as the letter approaches the floor, its shadow is darker, with bigger y.
1171
 *
1172
 * @skip if (y > SH_THRESHOLD)
1173
 * @until &sh_h);
1174
 * @skipline alpha = 255 * (y - SH_THRESHOLD)
1175
 *
1176
 * And with bigger x -- its proportional to x / WIDTH, but varies from 100 to
1177
 * 255
1178
 *
1179
 * @skip pos_x = (double) x /
1180
 * @until PROP_GET(pos_x, 100, 255);
1181
 *
1182
 * Note that the box shadow is not resized, just moved. And here set also the
1183
 * colors.
1184
 *
1185
 * @skip evas_object_move(shadow, x +
1186
 * @until alpha, alpha);
1187
 *
1188
 * As long as the letter approaches the floor, its lighter, with bigger x and y.
1189
 *
1190
 * @skipline evas_object_move(light, x
1191
 * @skipline alpha = (y <= 0) ? 0 : y * 255
1192
 * @skip alpha = alpha * (x - OFFSET_X + 80)
1193
 * @until }
1194
 *
1195
 * @section add-lettere Adding the letter E
1196
 *
1197
 * Here we'll add the last letter, "E" is a circle that comes rolling on
1198
 * the floor.
1199
 *
1200
 * First we use the letter_add function, set its shadow color and get
1201
 * its sizes.
1202
 *
1203
 * @skip _letter_add(evas, "E", &image
1204
 * @until evas_object_image_size_get(image, &w, &h);
1205
 *
1206
 * Place image and light above the floor and to the left of viewport, to comes
1207
 * rolling later on.
1208
 *
1209
 * @skip evas_object_move(image, -w - 1, FLOOR_Y
1210
 * @until evas_object_move(light, -w - 1, FLOOR_Y - h + 1);
1211
 *
1212
 * Place the shadow below the hit-line: FLOOR_Y centered at image.
1213
 *
1214
 * @skipline evas_object_move(shadow, -w - 1 + CENTER(w, sh_w)
1215
 *
1216
 * Here we create the body using body_circle function and enable its rotation
1217
 * on Z axis.
1218
 *
1219
 * @skip letter_body = _letter_body_circle_add
1220
 * @until letter_body, EINA_TRUE);
1221
 *
1222
 * Make the "E" logo get into the viewport by applying a horizontal force.
1223
 *
1224
 * @skipline ephysics_body_central_impulse_apply(letter_body
1225
 *
1226
 * Here we use the letter_body_setup_common to create the body and set its
1227
 * properties, note that we add a callback that will be explained below.
1228
 * @dontinclude ephysics_logo.c
1229
 *
1230
 * @skip _letter_body_circle_add(EPhysics_World *world
1231
 * @until }
1232
 *
1233
 * In this callback function that we added to our "E" letter body we'll update
1234
 * its light and shadow.
1235
 *
1236
 * First we'll update the body and get its image geometry.
1237
 *
1238
 * @dontinclude ephysics_logo.c
1239
 *
1240
 * @skip _update_circle_cb(void *data
1241
 * @until geometry_get(image, &x, &y, &w, &h);
1242
 *
1243
 * As long as the letter approaches the floor, its lighter, with bigger x.
1244
 *
1245
 * @skip evas_object_move(light, x
1246
 * @until alpha, alpha);
1247
 *
1248
 * Use the same map from image to the light (rotate it).
1249
 *
1250
 * @skip map = evas_object_map_get(image
1251
 * @until light, EINA_TRUE);
1252
 *
1253
 * As long as the letter approaches the floor, its shadow is darker, with
1254
 * bigger y.
1255
 *
1256
 * @skip evas_object_image_size_get(shadow,
1257
 * @until alpha, alpha);
1258
 *
1259
 * When the letter "E" passes the viewport, we send it to the begin again to
1260
 * collide with the other letters.
1261
 *
1262
 * @skip if (x > E_THRESHOLD)
1263
 * @until }
1264
 *
1265
 * Here we finish the example. The full source code can be found at
1266
 * @ref ephysics_logo_c.
1267
 *
1268
 */
1269

1270
 /**
1271
 * @page ephysics_logo_c ephysics_logo.c
1272
 *
1273
 * @section ephysics-logo-c ephysics_logo.c
1274
 * @include ephysics_logo.c
1275
 *
1276
 * @example ephysics_logo.c
1277
 */
1278

1279
 /**
1280
 * @page tutorial_ephysics_rotating_forever EPhysics - Rotating Forever
1281
 *
1282
 * The purpose of this example is to demonstrate the EPhysics Rotate usage -
1283
 * The code applies different ways to rotate an EPhysics_Body, such as torque,
1284
 * torque impulse and rotation set.
1285
 *
1286
 * For this example we'll have an EPhysics_World with gravity setted to zero,
1287
 * and four basic EPhysics_Bodys.
1288
 *
1289
 * The basic concepts like - defining an EPhysics_World, render geometry,
1290
 * physics limiting boundaries, add an EPhysics_Body, associate it to evas
1291
 * objects, change restitution, friction and impulse properties, were
1292
 * already covered in
1293
 * @ref tutorial_ephysics_bouncing_ball
1294
 *
1295
 * @section add-rotate Rotating
1296
 * @dontinclude test_rotating_forever.c
1297
 *
1298
 * For the first body we'll apply a torque impulse to make it rotate around Z
1299
 * axis (rotate on x-y plane). Will make the body rolls on clockwise rotation,
1300
 * if the value is negative, the impulse will be on counter clockwise.
1301
 *
1302
 * @skipline ephysics_body_torque_impulse_apply(body, 0, 0, 1);
1303
 *
1304
 * For the second body we'll use an offset to apply the force, the three
1305
 * last parameters are responsible to set a relative position to apply the
1306
 * force.In other words, the force applied with an offset will make the body
1307
 * rotates and move around the other cubes.
1308
 *
1309
 * @skipline ephysics_body_impulse_apply(body, 30, 0
1310
 *
1311
 * For the third body we'll use a timer to rotate the body and a callback to
1312
 * delete it.
1313
 *
1314
 * @skip timer = ecore_timer_add(1, _rotate_cb
1315
 * @until _del_cb, timer);
1316
 *
1317
 * @dontinclude test_rotating_forever.c
1318
 * @skip _del_cb(void *data
1319
 * @until }
1320
 *
1321
 * In the function we'll get the body rotation on z axis in degrees and handle
1322
 * it increasing 5 degrees on its position on z axis on each tick of the timer.
1323
 *
1324
 * @dontinclude test_rotating_forever.c
1325
 * @skip _rotate_cb(void *data
1326
 * @until }
1327
 *
1328
 * For the forth body we'll use 2 timers, but before that, we'll apply an
1329
 * initial torque, changing the body angular acceleration and a callback to
1330
 * delete the timers we'll add.
1331
 *
1332
 * @skipline ephysics_body_torque_apply(body, 0, 0, 2
1333
 * @skipline ephysics_body_event_callback_add(body,
1334
 * @skipline EPHYSICS_CALLBACK_BODY_DEL,
1335
 * @skipline _del_torque_cb, cube);
1336
 *
1337
 * Just the callback function to delete the timers.
1338
 *
1339
 * @dontinclude test_rotating_forever.c
1340
 * @skip _del_torque_cb(void *data
1341
 * @until }
1342
 *
1343
 * As we commented we'll use 2 timers, one to increase the torque and
1344
 * another to stop the torque, cleaning the forces related to the body.
1345
 *
1346
 * @skip timer = ecore_timer_add(3, _increase
1347
 * @until "stop_timer", timer);
1348
 *
1349
 * In the increase function we'll apply a torque over the body, changing
1350
 * its angular acceleration, it will leads to a change on angular velocity
1351
 * over time. We're using a timer to increase the angular acceleration on
1352
 * each tick of the timer.
1353
 *
1354
 * @dontinclude test_rotating_forever.c
1355
 * @skip _increase_torque_cb(void *data
1356
 * @until }
1357
 *
1358
 * In the stop function we'll clear all the forces applied to the body,
1359
 * setting its linear and angular acceleration to zero. We're using this
1360
 * timer to "control" the body velocity, since we are increasing it by
1361
 * another timer. Note that we set the acceleration to zero not the
1362
 * velocity.
1363
 *
1364
 * @skip _stop_torque_cb(void *data
1365
 * @until }
1366
 *
1367
 * Here we finish the example. The full source code can be found at
1368
 * @ref test_rotating_forever_c.
1369
 *
1370
 */
1371

1372
 /**
1373
 * @page test_rotating_forever_c test_rotating_forever.c
1374
 *
1375
 * # ephysics_test.h
1376
 * @include ephysics_test.h
1377
 *
1378
 * @section test-rotating-forever-c test_rotating_forever.c
1379
 * @dontinclude test.c
1380
 *
1381
 * @skip test_clean
1382
 * @until }
1383
 *
1384
 * @skip test_data_new
1385
 * @until }
1386
 *
1387
 * @skip test_win_add
1388
 * @until }
1389
 *
1390
 * @include test_rotating_forever.c
1391
 *
1392
 * @example test_rotating_forever.c
1393
 */
1394

1395
/**
1396
 * @page tutorial_ephysics_velocity EPhysics - Velocity
1397
 *
1398
 * The purpose of this example is to demonstrate the EPhysics Velocity usage -
1399
 * The code adds a small bouncing ball on the ground and responding to users
1400
 * events by making it jump - applying a central impulse on it and showing its
1401
 * velocity and acceleration.
1402
 *
1403
 * We'll see in this example how to get EPhysics_Body Linear and Angular
1404
 * velocity and acceleration.
1405
 *
1406
 * For this example we'll have an EPhysics_World and one basic EPhysics_Body,
1407
 * we'll apply impulses that follows user events, it were already covered in
1408
 * @ref tutorial_ephysics_bouncing_ball
1409
 *
1410
 * @section add-velstruct Velocity Data Struct
1411
 * @dontinclude test_velocity.c
1412
 *
1413
 * While in this example we'll be working with a struct to hold some objects
1414
 * in our code. For clarity sake we present you the struct declaration in the
1415
 * following block.
1416
 *
1417
 * @skip struct _Velocity_Data {
1418
 * @until };
1419
 *
1420
 * # Adding the Callbacks
1421
 *
1422
 * Calling ephysics_body_event_callback_add()
1423
 * will register a callback to a type of physics body event.
1424
 *
1425
 * @ref EPHYSICS_CALLBACK_BODY_UPDATE : called after every physics iteration.
1426
 * In other words, will be called after each world tick.
1427
 *
1428
 * @skipline ephysics_body_event_callback_add(sphere_body, EPHYSICS_CALLBACK_
1429
 * @skipline _update_vel_cb
1430
 *
1431
 * @ref EPHYSICS_CALLBACK_BODY_STOPPED : called when a body is found to be
1432
 * stopped. In other words, when the body is not moving anymore.
1433
 *
1434
 * @skip ephysics_body_event_callback_add(sphere_body, EPHYSICS_CALLBACK_BODY_ST
1435
 * @until );
1436
 *
1437
 * See
1438
 * @ref _EPhysics_Callback_Body_Type
1439
 * for more event types.
1440
 *
1441
 * @section add-velcb Velocity Function
1442
 *
1443
 * The callback function will be called on every physics iteration to show the
1444
 * linear and angular velocity and acceleration.
1445
 *
1446
 * Here we're declaring the necessary variables to calculate acelerations and
1447
 * delta time. And checking if its the first time to return before shows
1448
 * informations about the velocity.
1449
 *
1450
 * @dontinclude test_velocity.c
1451
 *
1452
 * @skip _update_vel_cb(void *data,
1453
 * @until EINA_TRUE;
1454
 *
1455
 * Get the delta time to use it soon to calculate the acceleration on every
1456
 * physics iteration.
1457
 *
1458
 * @skip time_now = ecore_time_get();
1459
 * @until time_now;
1460
 *
1461
 * Note in this part we get the angular and linear velocities.
1462
 *
1463
 * @skip ephysics_body_angular_velocity_get
1464
 * @until &vy, NULL);
1465
 *
1466
 * We need to handle the velocity using delta time to have the acceleration
1467
 * on every tick. Check if its the first time to return before shows
1468
 * informations about the velocity because we don't have the old aceletations
1469
 * and then the calculation of this informations will be wrong.
1470
 *
1471
 * Here we calculate the aceletarions using this formula:
1472
 *
1473
 * (velocity - old_velocity) / delta_time;
1474
 *
1475
 * @skip aaz = (vaz -
1476
 * @until return;
1477
 *
1478
 * Turning data into text, to pass it to edje shows on screen.
1479
 *
1480
 * @skip snprintf(buff,
1481
 * @until "linear_acc", buff);
1482
 * @skip snprintf(buff,
1483
 * @until "angular_acc", buff);
1484
 * @skipline }
1485
 *
1486
 * Here we finish the example. The full source code can be found at
1487
 * @ref test_velocity_c.
1488
 *
1489
 */
1490

1491
 /**
1492
 * @page test_velocity_c test_velocity.c
1493
 *
1494
 * # ephysics_test.h
1495
 * @include ephysics_test.h
1496
 *
1497
 * @section test-velocity-c test_velocity.c
1498
 * @dontinclude test.c
1499
 *
1500
 * @skip test_clean
1501
 * @until }
1502
 *
1503
 * @skip test_win_add
1504
 * @until }
1505
 *
1506
 * @include test_velocity.c
1507
 *
1508
 * @example test_velocity.c
1509
 */
1510

1511
 /**
1512
 * @page tutorial_ephysics_shapes EPhysics - Shapes
1513
 *
1514
 * The purpose of this example is to demonstrate the EPhysics Shapes
1515
 * usage - The code creates two EPhysics_Bodys using a custom shape.
1516
 *
1517
 * @image html shapes.png
1518
 * @image latex shapes.eps
1519
 *
1520
 * For this example we'll have an EPhysics_World, and two basic EPhysics_Bodys.
1521
 *
1522
 * The basic concepts like - defining an EPhysics_World, render geometry,
1523
 * physics limiting boundaries, add an EPhysics_Body, associate it to evas
1524
 * objects, change restitution, friction and impulse properties, were
1525
 * already covered in
1526
 * @ref tutorial_ephysics_bouncing_ball
1527
 *
1528
 * @section add-shape Adding a Shape
1529
 * @dontinclude test_shapes.c
1530
 *
1531
 * Shapes are used to create bodies with shapes that differ from primitive
1532
 * ones, like box and circle.
1533
 *
1534
 * A shape consists in a group of points, the vertices of the body to be
1535
 * created later with ephysics_body_shape_add(). You can also save and load
1536
 * it from a file.
1537
 *
1538
 * We'll have to create a specific type of variable:
1539
 * @ref EPhysics_Shape
1540
 *
1541
 * @skip _world_populate(Test_Data
1542
 * @until Evas_Object *pentagon,
1543
 *
1544
 * First we add an image we want to add an EPhysics_Body to have a reference
1545
 * to after set the points (vertices).
1546
 *
1547
 * @skip pentagon = elm_image_add
1548
 * @until evas_object_show(pentagon);
1549
 *
1550
 * Here we create a new shape, note that the returned shape initially
1551
 * doesn't has points set, so its requiered to set vertices.
1552
 *
1553
 * @skipline pentagon_shape =
1554
 *
1555
 * Now we're setting the shape points (vertices) basing on the image that
1556
 * we added, two vertices form a link between them, an edge, so with some
1557
 * vertices is possible to create polygons, in this case a pentagon.
1558
 *
1559
 * @skip ephysics_shape_point_add(pentagon_shape
1560
 * @until , 21/35., 1, 1);
1561
 *
1562
 * Here we create a new physics body using a custom shape. The center of mass
1563
 * will be the center of the shape. Its collision shape will be the convex
1564
 * shape that has all the points (and edges) we added to this shape before.
1565
 *
1566
 * @skip pentagon_body = ephysics_body_shape_add
1567
 * @until ephysics_body_restitution_set(pentagon_body, 1);
1568
 *
1569
 * Here we just delete the custom shape (not the body) after used to create
1570
 * the wanted bodies, it's required to delete it. It won't be deleted
1571
 * automatically by ephysics at any point, even on shutdown.
1572
 *
1573
 * @skipline ephysics_shape_del(pentagon_shape
1574
 *
1575
 * In the example we add another shape with the same process we just used,
1576
 * but with different image and points.
1577
 *
1578
 * @dontinclude test_shapes.c
1579
 *
1580
 * @skip ephysics_shape_point_add(hexagon_shape
1581
 * @until 18, 60, 10);
1582
 *
1583
 * Here we finish the example. The full source code can be found at
1584
 * @ref test_shapes_c.
1585
 *
1586
 */
1587

1588
 /**
1589
 * @page test_shapes_c test_shapes.c
1590
 *
1591
 * # ephysics_test.h
1592
 * @include ephysics_test.h
1593
 *
1594
 * @section test-shapes-c test_shapes.c
1595
 * @dontinclude test.c
1596
 *
1597
 * @skip test_clean
1598
 * @until }
1599
 *
1600
 * @skip test_data_new
1601
 * @until }
1602
 *
1603
 * @skip test_win_add
1604
 * @until }
1605
 *
1606
 * @include test_shapes.c
1607
 *
1608
 * @example test_shapes.c
1609
 */
1610

1611
 /**
1612
 * @page tutorial_ephysics_sleeping_threshold EPhysics - Sleeping Threshold
1613
 *
1614
 * The purpose of this example is to demonstrate the EPhysics Sleeping
1615
 * Threshold usage - The code apply sleeping threshold in two cubes.
1616
 *
1617
 * For this example we'll have an EPhysics_World, and two basic EPhysics_Bodys.
1618
 *
1619
 * The basic concepts like - defining an EPhysics_World, render geometry,
1620
 * physics limiting boundaries, add an EPhysics_Body, associate it to evas
1621
 * objects, change restitution, friction and impulse properties, were
1622
 * already covered in
1623
 * @ref tutorial_ephysics_bouncing_ball
1624
 *
1625
 * Concept of velocity were already covered in
1626
 * @ref tutorial_ephysics_velocity
1627
 *
1628
 * @section add-maxsleeping Adding Max Sleeping Time
1629
 * @dontinclude test_sleeping_threshold.c
1630
 *
1631
 * Setting the max sleeping time determines how long(in seconds) a rigid body
1632
 * under the linear and angular threshold is supposed to be marked as sleeping.
1633
 *
1634
 * @skipline ephysics_world_max_sleeping_time_set
1635
 *
1636
 * @section add-sleeping Adding a Sleeping Threshold
1637
 * @dontinclude test_sleeping_threshold.c
1638
 *
1639
 * Here we set EPhysics_Bodys linear and angular sleeping threshold. These
1640
 * factors are used to determine whenever a rigid body is supposed to
1641
 * increment the sleeping time.
1642
 *
1643
 * After every tick the sleeping time is incremented. After reaching the max
1644
 * sleeping time the body is market to sleep, that means the rigid body is to
1645
 * be deactivated.
1646
 *
1647
 * @skipline ephysics_body_sleeping_threshold_set(sphere_body1
1648
 *
1649
 * @skipline ephysics_body_sleeping_threshold_set(sphere_body2
1650
 *
1651
 * We can get the EPhysics_Bodys linear and angular sleeping threshold as well.
1652
 *
1653
 * @skipline ephysics_body_sleeping_threshold_get(sphere_body1
1654
 *
1655
 * @skipline ephysics_body_sleeping_threshold_get(sphere_body2
1656
 *
1657
 * @section add-damping Adding a Damping
1658
 * @dontinclude test_sleeping_threshold.c
1659
 *
1660
 * Here we set EPhysics_Bodys linear and angular damping values.The damping is
1661
 * a force synchronous with the velocity of the object but in opposite
1662
 * direction - like air resistance.
1663
 *
1664
 * @skipline ephysics_body_damping_set(sphere_body1
1665
 *
1666
 * @skipline ephysics_body_damping_set(sphere_body2
1667
 *
1668
 * Here we finish the example. The full source code can be found at
1669
 * @ref test_sleeping_threshold_c.
1670
 *
1671
 */
1672

1673
 /**
1674
 * @page test_sleeping_threshold_c test_sleeping_threshold.c
1675
 *
1676
 * # ephysics_test.h
1677
 * @include ephysics_test.h
1678
 *
1679
 * @section test-sleeping-threshold-c test_sleeping_threshold.c
1680
 * @dontinclude test.c
1681
 *
1682
 * @skip test_clean
1683
 * @until }
1684
 *
1685
 * @skip test_data_new
1686
 * @until }
1687
 *
1688
 * @skip test_win_add
1689
 * @until }
1690
 *
1691
 * @include test_sleeping_threshold.c
1692
 *
1693
 * @example test_sleeping_threshold.c
1694
 */
1695

1696
 /**
1697
 * @page tutorial_ephysics_slider EPhysics - Slider
1698
 *
1699
 * The purpose of this example is to demonstrate the EPhysics Slider constraint
1700
 * usage - The code applies slider on three cubes.
1701
 *
1702
 * @image html slider.png
1703
 * @image latex slider.eps
1704
 *
1705
 * For this example we'll have an EPhysics_World, and four basic
1706
 * EPhysics_Bodys.
1707
 *
1708
 * The basic concepts like - defining an EPhysics_World, render geometry,
1709
 * physics limiting boundaries, add an EPhysics_Body, associate it to evas
1710
 * objects, change restitution, friction and impulse properties, were
1711
 * already covered in
1712
 * @ref tutorial_ephysics_bouncing_ball
1713
 *
1714
 * You can use also a P2P (point to point) constraint:
1715
 * @ref tutorial_ephysics_constraint
1716
 *
1717
 * @section add-slider Adding a Slider
1718
 * @dontinclude test_slider.c
1719
 *
1720
 * Slider is a constraint that will limit the linear and angular moving of
1721
 * a body.
1722
 *
1723
 * We'll add three sliders on the cubes, starting with the highest purple.
1724
 *
1725
 * First we need to create a specific variable type to get EPhysics_Body
1726
 * constraint and create a new slider constraint passing the body which we
1727
 * want as parameter.
1728
 *
1729
 * @skipline EPhysics_Constraint *constr
1730
 *
1731
 * @skipline constraint = ephysics_constraint_slider_add(box_body2
1732
 *
1733
 * Here we define the linear moving limits of the slider constraint, in this
1734
 * case we just set moving limit down on Y axis (under), but if we wanted we
1735
 * could set left, right and above also.
1736
 *
1737
 * @skip ephysics_constraint_slider_linear_limit_set(constraint, 0,
1738
 * @until , 0, 0);
1739
 *
1740
 * Here we set the angular moving limits of the slider constraint. The angular
1741
 * moving limits is defined in degrees and will limit the moving on Z axis, in
1742
 * this case we just set the clockwise direction, but if we wanted we could
1743
 * set the counter clockwise direction also.
1744
 *
1745
 *
1746
 * @skipline ephysics_constraint_slider_angular_limit_set(constraint, 0, 45
1747
 *
1748
 * When this cube falls by the gravity, the slider constraint will act limiting
1749
 * its linear and angular movings, giving the impression that its hanging.
1750
 *
1751
 * For the next two cubes is the same process.
1752
 *
1753
 * Now we set the slider constraint of the highest blue and lowest purple,
1754
 * limiting moving limits to the left on X axis and applying an impulse
1755
 * to the left where the two cubes will be limited by the slider constraint
1756
 * and pushed back.
1757
 *
1758
 * @skip constraint = ephysics_constraint_slider_add(box_body3
1759
 * @until box_body3, -240, 0, 0);
1760
 *
1761
 * @skip constraint = ephysics_constraint_slider_add(box_body4
1762
 * @until box_body4, -600, 0, 0);
1763
 *
1764
 * Here we finish the example. The full source code can be found at
1765
 * @ref test_slider_c.
1766
 *
1767
 */
1768

1769
 /**
1770
 * @page test_slider_c test_slider.c
1771
 *
1772
 * # ephysics_test.h
1773
 * @include ephysics_test.h
1774
 *
1775
 * @section test-slider-c test_slider.c
1776
 * @dontinclude test.c
1777
 *
1778
 * @skip test_clean
1779
 * @until }
1780
 *
1781
 * @skip test_data_new
1782
 * @until }
1783
 *
1784
 * @skip test_win_add
1785
 * @until }
1786
 *
1787
 * @include test_slider.c
1788
 *
1789
 * @example test_slider.c
1790
 */
1791

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.