From 398a8a68c2d81924e0e321f8ac69bd802428d028 Mon Sep 17 00:00:00 2001 From: tanya Date: Wed, 28 Jul 2010 15:01:58 +0300 Subject: [PATCH] done tapes with accelerometer --- applet/src/livewp-actor.c | 43 ++++++++++++++++++++++++++++++++++++------- applet/src/livewp-scene.c | 45 ++++++--------------------------------------- 2 files changed, 42 insertions(+), 46 deletions(-) diff --git a/applet/src/livewp-actor.c b/applet/src/livewp-actor.c index c833470..6286b20 100644 --- a/applet/src/livewp-actor.c +++ b/applet/src/livewp-actor.c @@ -677,23 +677,52 @@ change_tape(Actor *actor, AWallpaperPlugin *desktop_plugin) speed[4] = {7, 10, 5, 14}, i; Actor *a; + double angle = 0; + char * accel_filename = "/sys/class/i2c-adapter/i2c-3/3-001d/coord"; + //char * accel_filename = "/home/tanya/coord"; + + FILE *fd = NULL; + int rs, ax, ay, az; + fd = fopen(accel_filename, "r"); + if (fd == NULL){ + //fprintf(stderr, "cannot open file\n"); + fd = fopen("/home/user/coord", "r"); + } + rs = fscanf((FILE*)fd, "%i %i %i", &ax, &ay, &az); + fclose(fd); + if (rs != 3){ + fprintf(stderr, "cannot read information from file\n"); + return; + + } + + //fprintf(stderr, "change obj %i %i %i angle rad=%f, deg=%f\n", ax, ay, az, atan2(ax, -ay), atan2(ax, -ay)*180/M_PI); + angle = atan2(ay, ax); + if (!desktop_plugin->priv->rich_animation) return; - for (i=0; i<12; i++){ + for (i=0; i<24; i++){ a = g_ptr_array_index(actor->child, i); - x = a->x - cos(angle*M_PI/180)*speed[i/3]; - y = a->y - sin(angle*M_PI/180)*speed[i/3]; - if (x <= -700) - x = 700*2; - if (y <= -480) + //x = a->x - cos(angle*M_PI/180)*a->z; + //y = a->y - sin(angle*M_PI/180)*a->z; + x = a->x - cos(angle)*a->z; + y = a->y - sin(angle)*a->z; + if (x <= -a->width) + x = 800; + if (y <= -a->width) + y = 480; + if (x > 800+a->width) + x = 0; + if (y > 480+a->width) y = 0; - //set_actor_rotation(a, HILDON_AA_Z_AXIS, angle, -x, -y, 0); + set_actor_rotation(a, HILDON_AA_Z_AXIS, angle*180/M_PI, 0, 0, 0); set_actor_position(a, x, y, a->z, desktop_plugin); a->x = x; a->y = y; } + } void diff --git a/applet/src/livewp-scene.c b/applet/src/livewp-scene.c index 887e47c..c3d893b 100644 --- a/applet/src/livewp-scene.c +++ b/applet/src/livewp-scene.c @@ -70,7 +70,7 @@ init_scene_Accel(AWallpaperPlugin *desktop_plugin) gchar *str; gint sizes[4] = {170, 229, 130, 150}, heights[4] = {0, 100, 200, 300}, - n, i; + n, i, j; scene = g_new0(Scene, 1); scene->actors = NULL; @@ -82,12 +82,14 @@ init_scene_Accel(AWallpaperPlugin *desktop_plugin) NULL, NULL, NULL); scene->actors = g_slist_append(scene->actors, actor); - child = g_ptr_array_sized_new(12); + child = g_ptr_array_sized_new(24); + + for (j= 0; j<2; j++){ for (n=0; n<4; n++){ for (i=0; i<3; i++){ str = g_strdup_printf("tape%i_%i.png", n+1, i); actor = init_object(desktop_plugin, "tape", str, - 700*i, heights[n], 5, 700, sizes[n], + fast_rnd(700), fast_rnd(430), 5+fast_rnd(20), 800, sizes[n], TRUE, TRUE, 100, 255, NULL, NULL, NULL); scene->actors = g_slist_append(scene->actors, actor); @@ -95,42 +97,7 @@ init_scene_Accel(AWallpaperPlugin *desktop_plugin) g_free(str); } } -#if 0 - actor = init_object(desktop_plugin, "tape1_1", "tape1_1.png", - 700, 0, 5, 700, 170, - TRUE, TRUE, 100, 255, - NULL, NULL, NULL); - scene->actors = g_slist_append(scene->actors, actor); - g_ptr_array_add(child, actor); - - actor = init_object(desktop_plugin, "tape1_2", "tape1_2.png", - 1400, 0, 5, 700, 170, - TRUE, TRUE, 100, 255, - NULL, NULL, NULL); - scene->actors = g_slist_append(scene->actors, actor); - g_ptr_array_add(child, actor); - - actor = init_object(desktop_plugin, "tape2_0", "tape2_0.png", - 0, 220, 5, 700, 229, - TRUE, TRUE, 100, 255, - NULL, NULL, NULL); - scene->actors = g_slist_append(scene->actors, actor); - g_ptr_array_add(child, actor); - - actor = init_object(desktop_plugin, "tape2_1", "tape2_1.png", - 700, 220, 5, 700, 229, - TRUE, TRUE, 100, 255, - NULL, NULL, NULL); - scene->actors = g_slist_append(scene->actors, actor); - g_ptr_array_add(child, actor); - - actor = init_object(desktop_plugin, "tape2_2", "tape2_2.png", - 1400, 220, 5, 700, 229, - TRUE, TRUE, 100, 255, - NULL, NULL, NULL); - scene->actors = g_slist_append(scene->actors, actor); - g_ptr_array_add(child, actor); -#endif + } actor = init_object(desktop_plugin, "tape", "", 0, 800, 5, 800, 170, FALSE, FALSE, 100, 255, -- 1.7.9.5