EPhysics: rotation set implemented
authorBruno Dilly <bdilly@profusion.mobi>
Mon, 20 Aug 2012 22:14:43 +0000 (22:14 +0000)
committerBruno Dilly <bdilly@profusion.mobi>
Mon, 20 Aug 2012 22:14:43 +0000 (22:14 +0000)
SVN revision: 75475

legacy/ephysics/src/bin/test_rotating_forever.c
legacy/ephysics/src/lib/EPhysics.h
legacy/ephysics/src/lib/ephysics_body.cpp

index df2ef46..105a6dc 100644 (file)
@@ -4,6 +4,23 @@
 
 #include "ephysics_test.h"
 
+static Eina_Bool
+_rotate_cb(void *data)
+{
+   EPhysics_Body *body = data;
+   double rotation;
+
+   rotation = ephysics_body_rotation_get(body);
+   ephysics_body_rotation_set(body, ((int) round(rotation) + 5) % 360);
+
+   return EINA_TRUE;
+}
+
+static void
+_del_cb(void *data, EPhysics_Body *body __UNUSED__, void *event_info __UNUSED__)
+{
+   ecore_timer_del(data);
+}
 
 static void
 _update_object_cb(void *data __UNUSED__, EPhysics_Body *body, void *event_info __UNUSED__)
@@ -21,6 +38,7 @@ static void
 _world_populate(Test_Data *test_data)
 {
    EPhysics_Body *body;
+   Ecore_Timer *timer;
    Evas_Object *cube;
 
    cube = elm_image_add(test_data->win);
@@ -56,6 +74,27 @@ _world_populate(Test_Data *test_data)
                                     _update_object_cb, NULL);
 
    ephysics_body_impulse_apply(body, 30, 0, 0, -10);
+
+   cube = elm_image_add(test_data->win);
+   elm_image_file_set(
+      cube, PACKAGE_DATA_DIR "/" EPHYSICS_TEST_THEME ".edj", "purple-cube");
+   evas_object_move(cube, WIDTH / 3, 60);
+   evas_object_resize(cube, 70, 70);
+   evas_object_show(cube);
+   test_data->evas_objs = eina_list_append(test_data->evas_objs, cube);
+
+   body = ephysics_body_box_add(test_data->world);
+   ephysics_body_evas_object_set(body, cube, EINA_TRUE);
+   test_data->bodies = eina_list_append(test_data->bodies, body);
+   ephysics_body_event_callback_add(body,
+                                    EPHYSICS_CALLBACK_BODY_UPDATE,
+                                    _update_object_cb, NULL);
+
+   timer = ecore_timer_add(1, _rotate_cb, body);
+
+   ephysics_body_event_callback_add(body,
+                                    EPHYSICS_CALLBACK_BODY_DEL,
+                                    _del_cb, timer);
 }
 
 static void
index 8200a6d..dec2024 100644 (file)
@@ -2284,12 +2284,32 @@ EAPI void ephysics_body_linear_movement_enable_get(const EPhysics_Body *body, Ei
  * @param body The physics body.
  * @return The amount of degrees @p body is rotated, from 0.0 to 360.0.
  *
+ * @see ephysics_body_rotation_set()
+ *
  * @ingroup EPhysics_Body
  */
 EAPI double ephysics_body_rotation_get(const EPhysics_Body *body);
 
 /**
  * @brief
+ * Set body's rotation on z axis.
+ *
+ * By default rotation is 0 degrees.
+ * Negative values indicates rotation on counterclockwise direction.
+ *
+ * @note The unit used for rotation is degrees.
+ *
+ * @param body The physics body.
+ * @param The amount of degrees @p body should be rotated.
+ *
+ * @see ephysics_body_rotation_get()
+ *
+ * @ingroup EPhysics_Body
+ */
+EAPI void ephysics_body_rotation_set(EPhysics_Body *body, double rotation);
+
+/**
+ * @brief
  * Set data to @p body.
  *
  * If a previous data was set, it's reference will be lost and body
index 26a3491..a907008 100644 (file)
@@ -1341,6 +1341,28 @@ ephysics_body_rotation_get(const EPhysics_Body *body)
 }
 
 EAPI void
+ephysics_body_rotation_set(EPhysics_Body *body, double rotation)
+{
+   btTransform trans;
+   btQuaternion quat;
+
+   if (!body)
+     {
+        ERR("Can't set rotation, body is null.");
+        return;
+     }
+
+   body->rigid_body->activate(1);
+   body->rigid_body->getMotionState()->getWorldTransform(trans);
+   quat.setEuler(0, 0, -rotation / RAD_TO_DEG);
+   trans.setRotation(quat);
+   body->rigid_body->proceedToTransform(trans);
+   body->rigid_body->getMotionState()->setWorldTransform(trans);
+
+   DBG("Body %p rotation set to %lf", body, rotation);
+}
+
+EAPI void
 ephysics_body_data_set(EPhysics_Body *body, void *data)
 {
    if (!body)