aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/extantz/ephysics_demo.c
blob: a7d7c7b2356a5d4d7f88906170ab15f81d835e0c (plain)
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
#include "extantz.h"


#define EPHYSICS_TEST_THEME "extantz"

EPhysics_World *ephysicsAdd(globals *ourGlobals)
{
  EPhysics_Body *boundary;
  EPhysics_World *world;
  EPhysics_Body *box_body1, *box_body2;
  Evas_Object *box1, *box2;
  char buf[PATH_MAX];

  // ePhysics stuff.
  world = ephysics_world_new();
  ephysics_world_render_geometry_set(world, 0, 0, -50, ourGlobals->win_w, ourGlobals->win_h, 100);

  boundary = ephysics_body_bottom_boundary_add(world);
  ephysics_body_restitution_set(boundary, 1);
  ephysics_body_friction_set(boundary, 0);

  boundary = ephysics_body_top_boundary_add(world);
  ephysics_body_restitution_set(boundary, 1);
  ephysics_body_friction_set(boundary, 0);

  boundary = ephysics_body_left_boundary_add(world);
  ephysics_body_restitution_set(boundary, 1);
  ephysics_body_friction_set(boundary, 0);

  boundary = ephysics_body_right_boundary_add(world);
  ephysics_body_restitution_set(boundary, 1);
  ephysics_body_friction_set(boundary, 0);

  sprintf(buf, "%s/%s.edj", prefix_data_get(), EPHYSICS_TEST_THEME);
  box1 = eo_add(ELM_IMAGE_CLASS, ourGlobals->win,
    efl_file_set(buf, "blue-cube"),
    evas_obj_size_set(70, 70),
    evas_obj_position_set(ourGlobals->win_w / 2 - 80, ourGlobals->win_h - 200),
    evas_obj_visibility_set(EINA_TRUE)
  );

  box_body1 = ephysics_body_box_add(world);
  ephysics_body_evas_object_set(box_body1, box1, EINA_TRUE);
  ephysics_body_restitution_set(box_body1, 0.7);
  ephysics_body_friction_set(box_body1, 0);
  ephysics_body_linear_velocity_set(box_body1, -150, 20, 0);
  ephysics_body_angular_velocity_set(box_body1, 0, 0, 36);
  ephysics_body_sleeping_threshold_set(box_body1, 0.1, 0.1);
//  eo_unref(box1);

  sprintf(buf, "%s/%s.edj", prefix_data_get(), EPHYSICS_TEST_THEME);
  box2 = eo_add(ELM_IMAGE_CLASS, ourGlobals->win,
    efl_file_set(buf, "purple-cube"),
    evas_obj_size_set(70, 70),
    evas_obj_position_set(ourGlobals->win_w / 2 + 10, ourGlobals->win_h - 200),
    evas_obj_visibility_set(EINA_TRUE)
  );

  box_body2 = ephysics_body_box_add(world);
  ephysics_body_evas_object_set(box_body2, box2, EINA_TRUE);
  ephysics_body_restitution_set(box_body2, 0.7);
  ephysics_body_friction_set(box_body2, 0);
  ephysics_body_linear_velocity_set(box_body2, 800, -600, 0);
  ephysics_body_angular_velocity_set(box_body2, 0, 0, 360);
  ephysics_body_sleeping_threshold_set(box_body2, 0.1, 0.1);
//  eo_unref(box2);

  ephysics_world_gravity_set(world, 0, 0, 0);

  return world;
}