summaryrefslogtreecommitdiff
path: root/legacy
diff options
context:
space:
mode:
authorRicardo de Almeida Gonzaga <ricardo@profusion.mobi>2012-10-18 19:18:13 +0000
committerBruno Dilly <bdilly@profusion.mobi>2012-10-18 19:18:13 +0000
commite7b72f567ac12438c17b51cf3d043d4a7cc24202 (patch)
tree2777c325f730eca79ddfd234f18b410ae53185d3 /legacy
parentd7757986c2bc141c193e00eefc1c5bf556711b0b (diff)
ephysics: sandbox apply actions on restart
Patch by: Ricardo de Almeida Gonzaga <ricardo@profusion.mobi> SVN revision: 78195
Diffstat (limited to 'legacy')
-rw-r--r--legacy/ephysics/src/bin/ephysics_sandbox.c59
1 files changed, 51 insertions, 8 deletions
diff --git a/legacy/ephysics/src/bin/ephysics_sandbox.c b/legacy/ephysics/src/bin/ephysics_sandbox.c
index f02ea22292..6c1dd5f3cc 100644
--- a/legacy/ephysics/src/bin/ephysics_sandbox.c
+++ b/legacy/ephysics/src/bin/ephysics_sandbox.c
@@ -32,9 +32,21 @@ struct _World_Data {
32struct _Body_Data { 32struct _Body_Data {
33 World_Data *wd; 33 World_Data *wd;
34 EPhysics_Body *body; 34 EPhysics_Body *body;
35 Evas_Object *sl_hardness; 35 struct {
36 struct {
37 Evas_Object *x, *y, *relx, *rely;
38 }impulse;
39 struct {
40 Evas_Object *x, *y, *relx, *rely, *torque;
41 }force;
42 struct {
43 Evas_Object *x, *y, *angular;
44 }velocity;
45 Evas_Object *hardness;
46 }controls;
36}; 47};
37 48
49
38/*** Sandbox Callbacks ***/ 50/*** Sandbox Callbacks ***/
39static void 51static void
40_body_del(void *data __UNUSED__, EPhysics_Body *body __UNUSED__, 52_body_del(void *data __UNUSED__, EPhysics_Body *body __UNUSED__,
@@ -128,13 +140,13 @@ _type_set_cb(void *data, Evas_Object *obj, void *event_info __UNUSED__)
128 { 140 {
129 body = ephysics_body_soft_circle_add(world); 141 body = ephysics_body_soft_circle_add(world);
130 ephysics_body_soft_body_hardness_set( 142 ephysics_body_soft_body_hardness_set(
131 body, elm_slider_value_get(bd->sl_hardness)); 143 body, elm_slider_value_get(bd->controls.hardness));
132 elm_object_disabled_set(bd->sl_hardness, EINA_FALSE); 144 elm_object_disabled_set(bd->controls.hardness, EINA_FALSE);
133 } 145 }
134 else 146 else
135 { 147 {
136 body = ephysics_body_circle_add(world); 148 body = ephysics_body_circle_add(world);
137 elm_object_disabled_set(bd->sl_hardness, EINA_TRUE); 149 elm_object_disabled_set(bd->controls.hardness, EINA_TRUE);
138 } 150 }
139 151
140 ephysics_body_evas_object_set(body, body_image, EINA_TRUE); 152 ephysics_body_evas_object_set(body, body_image, EINA_TRUE);
@@ -146,6 +158,14 @@ _type_set_cb(void *data, Evas_Object *obj, void *event_info __UNUSED__)
146 ephysics_body_sleeping_threshold_set(body, lin_sleeping, ang_sleeping); 158 ephysics_body_sleeping_threshold_set(body, lin_sleeping, ang_sleeping);
147 ephysics_body_material_set(body, material); 159 ephysics_body_material_set(body, material);
148 160
161 ephysics_body_force_apply(body,
162 elm_slider_value_get(bd->controls.force.x),
163 elm_slider_value_get(bd->controls.force.y), 0,
164 elm_slider_value_get(bd->controls.force.relx),
165 elm_slider_value_get(bd->controls.force.rely), 0);
166 ephysics_body_torque_apply(body, 0, 0,
167 elm_slider_value_get(bd->controls.force.torque));
168
149 bd->body = body; 169 bd->body = body;
150} 170}
151 171
@@ -438,10 +458,21 @@ static void
438_simulate_body(Body_Data *bd, Evas_Coord x, Evas_Coord y) 458_simulate_body(Body_Data *bd, Evas_Coord x, Evas_Coord y)
439{ 459{
440 ephysics_body_stop(bd->body); 460 ephysics_body_stop(bd->body);
441 ephysics_body_forces_clear(bd->body);
442 ephysics_body_geometry_set(bd->body, x, y, -15, 70, 70, 30); 461 ephysics_body_geometry_set(bd->body, x, y, -15, 70, 70, 30);
443 462 ephysics_body_impulse_apply(bd->body,
444 /*FIXME TODO apply impulses, velocities, forces ... */ 463 elm_slider_value_get(bd->controls.impulse.x),
464 elm_slider_value_get(bd->controls.impulse.y), 0,
465 elm_slider_value_get(bd->controls.impulse.relx),
466 elm_slider_value_get(bd->controls.impulse.rely),
467 0);
468 ephysics_body_linear_velocity_set(bd->body,
469 elm_slider_value_get(
470 bd->controls.velocity.x),
471 elm_slider_value_get(
472 bd->controls.velocity.y), 0);
473 ephysics_body_angular_velocity_set(bd->body, 0, 0,
474 elm_slider_value_get(
475 bd->controls.velocity.angular));
445} 476}
446 477
447static void 478static void
@@ -691,13 +722,17 @@ _menu_body_page_add(World_Data *wd, Body_Data *bd, const char *pg_label)
691 _label_add(bx, "Impulse X"); 722 _label_add(bx, "Impulse X");
692 aux_widget = _slider_add(bx, "X (kg * p/s)", "%1.3f", 723 aux_widget = _slider_add(bx, "X (kg * p/s)", "%1.3f",
693 -9999, 9999, 0); 724 -9999, 9999, 0);
725 bd->controls.impulse.x = aux_widget;
694 widget = _slider_add(bx, "Rel Position X", "%1.2f", 726 widget = _slider_add(bx, "Rel Position X", "%1.2f",
695 -360, 360, 0); 727 -360, 360, 0);
728 bd->controls.impulse.relx = widget;
696 evas_object_data_set(aux_widget, "relx", widget); 729 evas_object_data_set(aux_widget, "relx", widget);
697 _label_add(bx, "Impulse Y"); 730 _label_add(bx, "Impulse Y");
698 widget = _slider_add(bx, "Y (kg * p/s)", "%1.3f", -9999, 9999, 0); 731 widget = _slider_add(bx, "Y (kg * p/s)", "%1.3f", -9999, 9999, 0);
732 bd->controls.impulse.y = widget;
699 evas_object_data_set(aux_widget, "y", widget); 733 evas_object_data_set(aux_widget, "y", widget);
700 widget = _slider_add(bx, "Rel Position Y", "%1.2f", -360, 360, 0); 734 widget = _slider_add(bx, "Rel Position Y", "%1.2f", -360, 360, 0);
735 bd->controls.impulse.rely = widget;
701 evas_object_data_set(aux_widget, "rely", widget); 736 evas_object_data_set(aux_widget, "rely", widget);
702 evas_object_smart_callback_add(aux_widget, "delay,changed", 737 evas_object_smart_callback_add(aux_widget, "delay,changed",
703 _impulse_x_x_set_cb, bd); 738 _impulse_x_x_set_cb, bd);
@@ -715,12 +750,16 @@ _menu_body_page_add(World_Data *wd, Body_Data *bd, const char *pg_label)
715 750
716 _label_add(bx, "Force X"); 751 _label_add(bx, "Force X");
717 aux_widget = _slider_add(bx, "X (kg * p/s/s)", "%1.3f", -1999, 1999, 0); 752 aux_widget = _slider_add(bx, "X (kg * p/s/s)", "%1.3f", -1999, 1999, 0);
753 bd->controls.force.x = aux_widget;
718 widget = _slider_add(bx, "Rel Position X", "%1.2f", -360, 360, 0); 754 widget = _slider_add(bx, "Rel Position X", "%1.2f", -360, 360, 0);
755 bd->controls.force.relx = widget;
719 evas_object_data_set(aux_widget, "relx", widget); 756 evas_object_data_set(aux_widget, "relx", widget);
720 _label_add(bx, "Force Y"); 757 _label_add(bx, "Force Y");
721 widget = _slider_add(bx, "Y (kg * p/s/s)", "%1.3f", -1999, 1999, 0); 758 widget = _slider_add(bx, "Y (kg * p/s/s)", "%1.3f", -1999, 1999, 0);
759 bd->controls.force.y = widget;
722 evas_object_data_set(aux_widget, "y", widget); 760 evas_object_data_set(aux_widget, "y", widget);
723 widget = _slider_add(bx, "Rel Position Y", "%1.2f", -360, 360, 0); 761 widget = _slider_add(bx, "Rel Position Y", "%1.2f", -360, 360, 0);
762 bd->controls.force.rely = widget;
724 evas_object_data_set(aux_widget, "rely", widget); 763 evas_object_data_set(aux_widget, "rely", widget);
725 evas_object_smart_callback_add(aux_widget, "delay,changed", 764 evas_object_smart_callback_add(aux_widget, "delay,changed",
726 _force_x_x_set_cb, bd); 765 _force_x_x_set_cb, bd);
@@ -736,11 +775,14 @@ _menu_body_page_add(World_Data *wd, Body_Data *bd, const char *pg_label)
736 evas_object_smart_callback_add(widget, "delay,changed", 775 evas_object_smart_callback_add(widget, "delay,changed",
737 _force_y_rel_set_cb, bd); 776 _force_y_rel_set_cb, bd);
738 widget = _slider_add(bx, "Torque", "%1.3f", -100, 100, 0); 777 widget = _slider_add(bx, "Torque", "%1.3f", -100, 100, 0);
778 bd->controls.force.torque = widget;
739 evas_object_smart_callback_add(widget, "delay,changed", _torque_set_cb, bd); 779 evas_object_smart_callback_add(widget, "delay,changed", _torque_set_cb, bd);
740 780
741 _label_add(bx, "Linear Velocity"); 781 _label_add(bx, "Linear Velocity");
742 aux_widget = _slider_add(bx, "X (p/s)", "%1.2f", -1499, 1499, 0); 782 aux_widget = _slider_add(bx, "X (p/s)", "%1.2f", -1499, 1499, 0);
783 bd->controls.velocity.x = aux_widget;
743 widget = _slider_add(bx, "Y (p/s)", "%1.2f", -1499, 1499, 0); 784 widget = _slider_add(bx, "Y (p/s)", "%1.2f", -1499, 1499, 0);
785 bd->controls.velocity.y = widget;
744 evas_object_data_set(aux_widget, "y", widget); 786 evas_object_data_set(aux_widget, "y", widget);
745 evas_object_smart_callback_add(aux_widget, "delay,changed", 787 evas_object_smart_callback_add(aux_widget, "delay,changed",
746 _linear_velocity_x_set_cb, bd); 788 _linear_velocity_x_set_cb, bd);
@@ -749,15 +791,16 @@ _menu_body_page_add(World_Data *wd, Body_Data *bd, const char *pg_label)
749 _linear_velocity_y_set_cb, bd); 791 _linear_velocity_y_set_cb, bd);
750 792
751 widget = _slider_add(bx, "Angular Velocity (º/s)", "%1.2f", -360, 360, 0); 793 widget = _slider_add(bx, "Angular Velocity (º/s)", "%1.2f", -360, 360, 0);
794 bd->controls.velocity.angular = widget;
752 evas_object_smart_callback_add(widget, "delay,changed", 795 evas_object_smart_callback_add(widget, "delay,changed",
753 _angular_velocity_set_cb, bd); 796 _angular_velocity_set_cb, bd);
754 797
755 bx = _category_add(bxbody, "Soft Body", EINA_TRUE); 798 bx = _category_add(bxbody, "Soft Body", EINA_TRUE);
756 widget = _slider_add(bx, "Hardness (%)", "%1.2f%", 0, 100, 100); 799 widget = _slider_add(bx, "Hardness (%)", "%1.2f%", 0, 100, 100);
800 bd->controls.hardness = widget;
757 elm_object_disabled_set(widget, EINA_TRUE); 801 elm_object_disabled_set(widget, EINA_TRUE);
758 evas_object_smart_callback_add(widget, "delay,changed", _hardness_set_cb, 802 evas_object_smart_callback_add(widget, "delay,changed", _hardness_set_cb,
759 bd); 803 bd);
760 bd->sl_hardness = widget;
761 804
762 it = elm_naviframe_item_insert_before(wd->nf, 805 it = elm_naviframe_item_insert_before(wd->nf,
763 evas_object_data_get(wd->nf, "world"), 806 evas_object_data_get(wd->nf, "world"),