static void transition_completed_cb (OptTransition *trans, gpointer data) { OptShow *show = (OptShow *)data; OptSlide *from; OptShowPrivate *priv; ClutterActor *stage; priv = show->priv; from = opt_transition_get_from (trans); stage = clutter_stage_get_default(); /* Remove as to free up resources. */ clutter_actor_hide_all (CLUTTER_ACTOR(from)); clutter_container_remove_actor (CLUTTER_CONTAINER(stage), CLUTTER_ACTOR(from)); /* Reset any tranforms to be safe */ clutter_actor_set_rotation (CLUTTER_ACTOR(from), CLUTTER_X_AXIS, 0, 0, 0, 0); clutter_actor_set_rotation (CLUTTER_ACTOR(from), CLUTTER_Y_AXIS, 0, 0, 0, 0); clutter_actor_set_rotation (CLUTTER_ACTOR(from), CLUTTER_Z_AXIS, 0, 0, 0, 0); /* If needed, update the position */ if (priv->position_label_visible) opt_show_update_position_label (show); /* Disconnect the handler */ g_signal_handler_disconnect (trans, priv->trans_signal_id); priv->trans_signal_id = 0; }
/* Timeline handler */ static void frame_cb (ClutterTimeline *timeline, gint frame_num, gpointer data) { SuperOH *oh = data; gint i; /* Rotate everything clockwise about stage center*/ clutter_actor_set_rotation (CLUTTER_ACTOR (oh->group), CLUTTER_Z_AXIS, frame_num, CLUTTER_STAGE_WIDTH () / 2, CLUTTER_STAGE_HEIGHT () / 2, 0); for (i = 0; i < n_hands; i++) { gdouble scale_x, scale_y; clutter_actor_get_scale (oh->hand[i], &scale_x, &scale_y); /* Rotate each hand around there centers - to get this we need * to take into account any scaling. * * FIXME: scaling causes drift so disabled for now. Need rotation * unit based functions to fix. */ clutter_actor_set_rotation (oh->hand[i], CLUTTER_Z_AXIS, - 6.0 * frame_num, 0, 0, 0); } }
/* Timeline handler */ void frame_cb (ClutterTimeline *timeline, gint msecs, gpointer data) { SuperOH *oh = (SuperOH *)data; gint i; guint rotation = clutter_timeline_get_progress (timeline) * 360.0f; /* Rotate everything clockwise about stage center*/ clutter_actor_set_rotation (CLUTTER_ACTOR (oh->group), CLUTTER_Z_AXIS, rotation, WINWIDTH / 2, WINHEIGHT / 2, 0); for (i = 0; i < NHANDS; i++) { /* rotate each hand around there centers */ clutter_actor_set_rotation (oh->hand[i], CLUTTER_Z_AXIS, - 6.0 * rotation, clutter_actor_get_width (oh->hand[i]) / 2, clutter_actor_get_height (oh->hand[i]) / 2, 0); if (fade == TRUE) clutter_actor_set_opacity (oh->hand[i], (255 - (rotation % 255))); } }
/* Timeline handler */ static void frame_cb (ClutterTimeline *timeline, gint msecs, gpointer data) { SuperOH *oh = data; gint i; float rotation = clutter_timeline_get_progress (timeline) * 360.0f; /* Rotate everything clockwise about stage center*/ clutter_actor_set_rotation (oh->group, CLUTTER_Z_AXIS, rotation, oh->stage_width / 2, oh->stage_height / 2, 0); for (i = 0; i < n_hands; i++) { /* Rotate each hand around there centers - to get this we need * to take into account any scaling. */ clutter_actor_set_rotation (oh->hand[i], CLUTTER_Z_AXIS, -6.0 * rotation, 0, 0, 0); } }
static void rc_update_viewport(void *renderer) { RendererClutter *rc = (RendererClutter *)renderer; ClutterColor stage_color = { 0x00, 0x00, 0x00, 0xff }; rc->stereo_off_x = 0; rc->stereo_off_y = 0; if (rc->stereo_mode & PR_STEREO_RIGHT) { if (rc->stereo_mode & PR_STEREO_HORIZ) { rc->stereo_off_x = rc->pr->viewport_width; } else if (rc->stereo_mode & PR_STEREO_VERT) { rc->stereo_off_y = rc->pr->viewport_height; } else if (rc->stereo_mode & PR_STEREO_FIXED) { rc->stereo_off_x = rc->pr->stereo_fixed_x_right; rc->stereo_off_y = rc->pr->stereo_fixed_y_right; } } else { if (rc->stereo_mode & PR_STEREO_FIXED) { rc->stereo_off_x = rc->pr->stereo_fixed_x_left; rc->stereo_off_y = rc->pr->stereo_fixed_y_left; } } DEBUG_3("rc_update_viewport scale %d %d", rc->pr->width, rc->pr->height); clutter_stage_set_color(CLUTTER_STAGE(rc->stage), &stage_color); clutter_actor_set_size(rc->group, rc->pr->viewport_width, rc->pr->viewport_height); clutter_actor_set_position(rc->group, rc->stereo_off_x, rc->stereo_off_y); clutter_actor_set_rotation(CLUTTER_ACTOR(rc->group), CLUTTER_Y_AXIS, (rc->stereo_mode & PR_STEREO_MIRROR) ? 180 : 0, rc->pr->viewport_width / 2.0, 0, 0); clutter_actor_set_rotation(CLUTTER_ACTOR(rc->group), CLUTTER_X_AXIS, (rc->stereo_mode & PR_STEREO_FLIP) ? 180 : 0, 0, rc->pr->viewport_height / 2.0, 0); rc_sync_actor(rc); rc_overlay_update_positions(rc); }
/* rotation */ void on_new_frame (ClutterTimeline * timeline, gint frame_num, gpointer data) { ClutterActor *rect_actor = CLUTTER_ACTOR (data); ClutterActor *texture_actor = g_object_get_data (G_OBJECT (timeline), "texture_actor"); clutter_actor_set_rotation (rect_actor, CLUTTER_Z_AXIS, (gdouble) frame_num, clutter_actor_get_width (rect_actor) / 2, clutter_actor_get_height (rect_actor) / 2, 0); clutter_actor_set_rotation (texture_actor, CLUTTER_Z_AXIS, (gdouble) frame_num, clutter_actor_get_width (texture_actor) / 6, clutter_actor_get_height (texture_actor) / 6, 0); }
gboolean rotate_video (UserInterface * ui) { gfloat *x = 0, *y = 0, *z = 0; gfloat vid_width, vid_height; gfloat x_center, y_center; gdouble angle; angle = clutter_actor_get_rotation (ui->texture, CLUTTER_Z_AXIS, x, y, z); angle += 90; if (angle == 360) angle = 0; clutter_actor_set_rotation (ui->texture, CLUTTER_Z_AXIS, angle, 0, 0, 0); if (angle == 90 || angle == 270) { ui->rotated = TRUE; if (!ui->fullscreen) { clutter_actor_set_width (ui->stage, ui->media_height); clutter_actor_set_height (ui->stage, ui->media_width); } } else { ui->rotated = FALSE; if (!ui->fullscreen) { clutter_actor_set_width (ui->stage, ui->media_width); clutter_actor_set_height (ui->stage, ui->media_height); } } size_change (CLUTTER_STAGE (ui->stage), ui); }
int main (int argc, char *argv[]) { ClutterActor *stage; ClutterActor *coglbox; ClutterTimeline *tl; clutter_init(&argc, &argv); tl = clutter_timeline_new (G_N_ELEMENTS (paint_func) * 1000); clutter_timeline_set_loop (tl, TRUE); clutter_timeline_start (tl); stage = clutter_stage_get_default (); clutter_actor_set_size (stage, 400, 400); clutter_stage_set_title (CLUTTER_STAGE (stage), "Cogl Test"); coglbox = clutter_group_new (); clutter_container_add_actor (CLUTTER_CONTAINER (stage), coglbox); g_signal_connect (coglbox, "paint", G_CALLBACK (paint_cb), tl); /* Redraw every frame of the timeline */ g_signal_connect_swapped (tl, "new-frame", G_CALLBACK (clutter_actor_queue_redraw), coglbox); clutter_actor_set_rotation (coglbox, CLUTTER_Y_AXIS, -30, 200, 0, 0); clutter_actor_set_position (coglbox, 0, 100); clutter_actor_show (stage); clutter_main (); g_object_unref (tl); return 0; }
int main (int argc, char *argv[]) { ClutterActor *stage; ClutterActor *coglbox; clutter_init(&argc, &argv); stage = clutter_stage_get_default (); clutter_actor_set_size (stage, 400, 400); clutter_stage_set_title (CLUTTER_STAGE (stage), "Cogl Test"); coglbox = test_coglbox_new (); clutter_container_add_actor (CLUTTER_CONTAINER (stage), coglbox); clutter_actor_set_rotation (coglbox, CLUTTER_Y_AXIS, -30, 200, 0, 0); clutter_actor_set_position (coglbox, 0, 100); clutter_actor_show_all (stage); while (1) { clutter_actor_hide (coglbox); clutter_actor_show (coglbox); SPIN(); } return 0; }
static void tick (ClutterTimeline *timeline, gint msecs, gpointer data) { Flower **flowers = data; gint i = 0; for (i = 0; i < N_FLOWERS; i++) { flowers[i]->y += flowers[i]->v; flowers[i]->rot += flowers[i]->rv; if (flowers[i]->y > (gint) clutter_actor_get_height (stage)) flowers[i]->y = -clutter_actor_get_height (flowers[i]->ctex); clutter_actor_set_position (flowers[i]->ctex, flowers[i]->x, flowers[i]->y); clutter_actor_set_rotation (flowers[i]->ctex, CLUTTER_Z_AXIS, flowers[i]->rot, clutter_actor_get_width (flowers[i]->ctex)/2, clutter_actor_get_height (flowers[i]->ctex)/2, 0); } }
/* Setup the video texture once its size is known */ void size_change (ClutterActor *texture, gint width, gint height, gpointer user_data) { ClutterActor *stage; gfloat new_x, new_y, new_width, new_height; gfloat stage_width, stage_height; ClutterAnimation *animation = NULL; stage = clutter_actor_get_stage (texture); if (stage == NULL) return; clutter_actor_get_size (stage, &stage_width, &stage_height); /* Center video on window and calculate new size preserving aspect ratio */ new_height = (height * stage_width) / width; if (new_height <= stage_height) { new_width = stage_width; new_x = 0; new_y = (stage_height - new_height) / 2; } else { new_width = (width * stage_height) / height; new_height = stage_height; new_x = (stage_width - new_width) / 2; new_y = 0; } clutter_actor_set_position (texture, new_x, new_y); clutter_actor_set_size (texture, new_width, new_height); clutter_actor_set_rotation (texture, CLUTTER_Y_AXIS, 0.0, stage_width / 2, 0, 0); /* Animate it */ animation = clutter_actor_animate (texture, CLUTTER_LINEAR, 10000, "rotation-angle-y", 360.0, NULL); clutter_animation_set_loop (animation, TRUE); }
int main(int argc,char *argv[]) { ClutterColor stage_color = { 0x00, 0x00, 0x00, 0xff }; ClutterColor actor_color = { 0xff,0xff,0xff,0x98}; /** 初始化clutter */ clutter_init(&argc, &argv); /** 获取默认的场景stage */ ClutterActor *stage = clutter_stage_get_default(); /** 设置场景大小,注意场景也actor的一种,所以可以使用actor的api设置*/ clutter_actor_set_size(stage,400,400); /** 设置场景背景*/ clutter_stage_set_color(CLUTTER_STAGE(stage), &stage_color); /** 载入一个图像的actor */ //ClutterActor * image = clutter_texture_new_from_file("demo.png",NULL); image = clutter_texture_new_from_file("demo.png",NULL); if(!image){ printf("load image error\n"); exit(-1); } /** 设置actor在场景中的位置*/ clutter_actor_set_position(image, 100,100); /** 缩放图像,这里设置长宽各放大了两倍*/ clutter_actor_set_scale(image,2.0,2.0); /** 设置图像旋转,以y轴旋转,角度20'c */ clutter_actor_set_rotation(image, CLUTTER_Y_AXIS, 120,0,0,0); /** 把actor加入场景中*/ clutter_container_add_actor(CLUTTER_CONTAINER(stage),image); clutter_actor_show(image); /** 打开actor的事件响应*/ clutter_actor_set_reactive(image,TRUE); /** 连接actor的某事件*/ g_signal_connect(image, "button-press-event", G_CALLBACK(on_image_button_press),NULL); /** 加入时间线*/ //ClutterTimeline* timeline = clutter_timeline_new(5000); timeline = clutter_timeline_new(5000); g_signal_connect(timeline, "new-frame",G_CALLBACK(on_timeline_new_frame),NULL); clutter_timeline_set_loop(timeline,TRUE); //clutter_timeline_start(timeline); clutter_actor_show(stage); clutter_main(); g_object_unref(timeline); printf("\n"); return 0; }
void on_call_deactivate_complete (ClutterTimeline *timeline, gpointer user_data) { App *app = (App*)user_data; /* reset the now hidden dialing screen */ clutter_actor_set_rotation (app->screen_dial, CLUTTER_Y_AXIS, 0, 0, 0, 0); }
static void zoom_transition_frame_cb (OptTransition *trans, gint frame_num, gpointer data) { OptSlide *from, *to; OptTransitionPrivate *priv; ClutterActor *stage; gint n_frames = 0; priv = trans->priv; from = opt_transition_get_from (trans); to = opt_transition_get_to (trans); stage = clutter_stage_get_default(); n_frames = clutter_timeline_get_n_frames (CLUTTER_TIMELINE(trans)); if (frame_num > n_frames/2) { clutter_actor_hide (CLUTTER_ACTOR(from)); clutter_actor_show_all (CLUTTER_ACTOR(to)); clutter_actor_set_depth (CLUTTER_ACTOR(to), -1 * ((n_frames * 2000) - (frame_num * 2000))); clutter_actor_set_rotation (CLUTTER_ACTOR(to), CLUTTER_Z_AXIS, frame_num * ((360*2)/n_frames), CLUTTER_STAGE_WIDTH()/2, CLUTTER_STAGE_HEIGHT()/2, 0); } else { clutter_actor_hide (CLUTTER_ACTOR(to)); clutter_actor_set_depth (CLUTTER_ACTOR(from), -2000 * frame_num); clutter_actor_set_rotation (CLUTTER_ACTOR(from), CLUTTER_Z_AXIS, frame_num * ((360*2)/n_frames), CLUTTER_STAGE_WIDTH()/2, CLUTTER_STAGE_HEIGHT()/2, 0); } }
static void page_transition_frame_cb (OptTransition *trans, gint frame_num, gpointer data) { OptSlide *from, *to; ClutterActor *stage; ClutterColor color = { 0x22, 0x22, 0x22, 0xff }; OptTransitionPrivate *priv; gint mult, n_frames; priv = trans->priv; from = opt_transition_get_from (trans); to = opt_transition_get_to (trans); stage = clutter_stage_get_default(); clutter_actor_show_all (CLUTTER_ACTOR(to)); mult = priv->direction ? -1 : 1; n_frames = clutter_timeline_get_n_frames (CLUTTER_TIMELINE(trans)); if (frame_num > n_frames/2) { /* Fix Z ordering */ clutter_actor_lower_bottom (CLUTTER_ACTOR(from)); } clutter_stage_set_color (CLUTTER_STAGE(stage), &color); clutter_actor_set_rotation (CLUTTER_ACTOR(from), CLUTTER_Y_AXIS, - (float)frame_num * 2 * mult, CLUTTER_STAGE_WIDTH()*3/2, 0, -1 * (CLUTTER_STAGE_WIDTH()/2)); clutter_actor_set_rotation (CLUTTER_ACTOR(to), CLUTTER_Y_AXIS, (mult * 60) - (frame_num * 2 * mult), CLUTTER_STAGE_WIDTH()*3/2, 0, -1 * (CLUTTER_STAGE_WIDTH()/2)); }
void on_timeline_new_frame(ClutterTimeline* timeline, gint frame_num,gpointer data) { rotation_angle+=1; if(rotation_angle>360) rotation_angle=0; clutter_actor_set_rotation(CLUTTER_ACTOR(data), CLUTTER_Y_AXIS,rotation_angle,0,25,0); }
static gboolean actor_manipulator_motion (ClutterActor *stage, ClutterEvent *event, gpointer data) { if (manipulated_actor) { gfloat x; gfloat y; gfloat dx; gfloat dy; x = (event->button.x); y = (event->button.y); clutter_actor_transform_stage_point ( clutter_actor_get_parent (manipulated_actor), x, y, &x, &y); dx = x - start_x; dy = y - start_y; switch (mode) { #ifdef BOX2D_MANIPULATION case Box2D: { ClutterVertex target = { x, y }; clutter_box2d_mouse_joint_update_target (mouse_joint, &target); break; } #endif case Direct: if (clutter_event_get_state (event) & CLUTTER_BUTTON1_MASK) { x = orig_x + dx; y = orig_y + dy; clutter_actor_set_position (manipulated_actor, x, y); } else if (clutter_event_get_state (event) & CLUTTER_BUTTON2_MASK) { clutter_actor_set_rotation (manipulated_actor, CLUTTER_Z_AXIS, orig_rotation + dx, 0, 0, 0); } break; case None: g_print ("we shouldn't be doing %s in None mode\n", G_STRLOC); return FALSE; } } return FALSE; }
IO_METHOD(IoClutterActor, setRotation) { ClutterRotateAxis axis = IoMessage_locals_intArgAt_(m, locals, 0); double angle = IoMessage_locals_doubleArgAt_(m, locals, 1); float x = IoMessage_locals_floatArgAt_(m, locals, 2), y = IoMessage_locals_floatArgAt_(m, locals, 3), z = IoMessage_locals_floatArgAt_(m, locals, 4); clutter_actor_set_rotation(IOCACTOR(self), axis, angle, x, y, z); return self; }
static void spin_me (ClutterBehaviour *behave, guint32 alpha_value, gpointer null) { gfloat factor = (gfloat)alpha_value / CLUTTER_ALPHA_MAX_ALPHA; clutter_actor_set_rotation (CLUTTER_ACTOR (show), CLUTTER_Y_AXIS, factor * 360, CLUTTER_STAGE_WIDTH ()/2, 0, 0); }
void call_deactivate (App *app) { int i; ClutterAnimation *anim; ClutterAlpha *alpha; /* stop the flashing text */ clutter_timeline_stop (app->dialing_timeline); /* clear dialpad entry ready */ clutter_text_set_text (CLUTTER_TEXT(app->dpy_entry), ""); /* rotate screen_dial, and hide it at mid-animation */ clutter_actor_set_rotation (app->screen_dial, CLUTTER_Y_AXIS, 0.0, 0.0, 0.0, 0.0); anim = clutter_actor_animate (app->screen_dial, CLUTTER_LINEAR, 150, "rotation-angle-y", -180.0, "visible", FALSE, NULL); alpha = clutter_animation_get_alpha (anim); /* reset positions of dialer actors, needed back for flip */ for (i=0; i<12; i++) { clutter_actor_set_position (app->buttons[i]->actor, app->buttons[i]->sx, app->buttons[i]->sy); clutter_actor_set_opacity (app->buttons[i]->actor, 0xff); } clutter_actor_set_position (app->dpy, app->dpyx, app->dpyy); /* rotate hidden screen_dialpad, and show it at mid-animation */ clutter_actor_set_rotation (app->screen_dialpad, CLUTTER_Y_AXIS, 180.0, 0.0, 0.0, 0.0); clutter_actor_animate_with_alpha (app->screen_dialpad, alpha, "rotation-angle-y", 0.0, "visible", TRUE, "signal-after::completed", G_CALLBACK(on_call_deactivate_complete), app, NULL); app->dialing_state = FALSE; }
static void on_key_release_event (ClutterStage *stage, ClutterEvent *event, gpointer null) { static gint i = 0; switch (clutter_key_event_symbol ((ClutterKeyEvent*)event)) { case CLUTTER_Escape: clutter_main_quit (); break; case CLUTTER_Left: i--; if (i == 0) i = 359; clutter_actor_set_rotation (CLUTTER_ACTOR (stage), CLUTTER_Y_AXIS, i, CLUTTER_STAGE_WIDTH ()/2, 0, CLUTTER_STAGE_HEIGHT ()); break; case CLUTTER_Right: i++; if (i == 360) i = 0; clutter_actor_set_rotation (CLUTTER_ACTOR (stage), CLUTTER_Y_AXIS, i, CLUTTER_STAGE_WIDTH ()/2, 0, CLUTTER_STAGE_HEIGHT ()); break; case CLUTTER_Up: if (!clutter_timeline_is_playing (timeline)) clutter_timeline_start (timeline); break; default: break; } }
static void tidy_scroll_view_init (TidyScrollView *self) { TidyScrollViewPrivate *priv = self->priv = SCROLL_VIEW_PRIVATE (self); priv->hscroll = tidy_scroll_bar_new (NULL); priv->vscroll = tidy_scroll_bar_new (NULL); clutter_actor_set_parent (priv->hscroll, CLUTTER_ACTOR (self)); clutter_actor_set_parent (priv->vscroll, CLUTTER_ACTOR (self)); clutter_actor_show (priv->hscroll); clutter_actor_show (priv->vscroll); clutter_actor_set_rotation (priv->vscroll, CLUTTER_Z_AXIS, 90.0, 0, 0, 0); }
void on_timeline_rotation_new_frame(ClutterTimeline * timeline, gint frame_num, gpointer data) { if((++rotation_angle) >= 360) rotation_angle = 0; clutter_actor_set_rotation(rect, CLUTTER_X_AXIS, rotation_angle, 0, 0, 0); if((++color_change_count) >= 100) color_change_count = 0; if(color_change_count == 0) { ClutterColor color = {0xFF, 0xFF, 0xFF, 0xFF}; //White clutter_rectangle_set_color(CLUTTER_RECTANGLE(rect), &color); } else if(color_change_count == 50) { ClutterColor color = {0x00, 0xFF, 0xFF, 0xFF}; //Purple clutter_rectangle_set_color(CLUTTER_RECTANGLE(rect), &color); } }
static void manager_event_object_set(unsigned short type, void *userdata, void *data) { tuio_object_t *o = (tuio_object_t *)data; manager_actor_t *it; ClutterActor *stage; unsigned wx, wy; for ( it = manager_actors_list.lh_first; it != NULL; it = it->next.le_next ) if ( it->id == o->s_id ) break; if ( it == NULL ) return; /* update control */ if ( it->scene_actor->ctl_angle ) (*it->scene_actor->ctl_angle)(it->scene_actor->data_mod, o->angle / PI2); if ( it->scene_actor->ctl_x ) (*it->scene_actor->ctl_x)(it->scene_actor->data_mod, o->xpos); if ( it->scene_actor->ctl_y ) (*it->scene_actor->ctl_y)(it->scene_actor->data_mod, o->ypos); /* retreive last dimensions */ stage = clutter_stage_get_default(); clutter_actor_get_size(stage, &wx, &wy); clutter_actor_set_position(it->clutter_actor, o->xpos * (float)wx, o->ypos * (float)wy ); clutter_actor_set_rotation(it->rotate_actor, CLUTTER_Z_AXIS, TUIO_PI_TO_DEG(o->angle), it->scene_actor->width * 0.5, it->scene_actor->height * 0.5, 0 ); /* update object */ (*it->scene_actor->mod->object_update)(it->scene_actor->data_mod); atomic_set(&c_scene_changed, 1); }
static void alpha_notify_foreach (ClutterBehaviour *behaviour, ClutterActor *actor, gpointer data) { RotateFrameClosure *closure = data; ClutterBehaviourRotate *rotate_behaviour; ClutterBehaviourRotatePrivate *priv; rotate_behaviour = CLUTTER_BEHAVIOUR_ROTATE (behaviour); priv = rotate_behaviour->priv; clutter_actor_set_rotation (actor, priv->axis, closure->angle, priv->center_x, priv->center_y, priv->center_z); }
static void frame_cb (ClutterTimeline *timeline, gint elapsed_msecs, TestState *state) { guint x, y; float period_progress = clutter_timeline_get_progress (timeline); float period_progress_sin = sinf (period_progress); float wave_shift = period_progress * WAVE_SPEED; float ripple_shift = period_progress * RIPPLE_SPEED; for (y = 0; y <= MESH_HEIGHT; y++) for (x = 0; x <= MESH_WIDTH; x++) { guint vert_index = (MESH_WIDTH + 1) * y + x; float *vert = &state->quad_mesh_verts[3 * vert_index]; float real_x = x * QUAD_WIDTH; float real_y = y * QUAD_HEIGHT; float wave_offset = (float)x / (MESH_WIDTH + 1); float wave_angle = (WAVE_PERIODS * 2 * G_PI * wave_offset) + wave_shift; float wave_sin = sinf (wave_angle); float a_sqr = (RIPPLE_CENTER_X - real_x) * (RIPPLE_CENTER_X - real_x); float b_sqr = (RIPPLE_CENTER_Y - real_y) * (RIPPLE_CENTER_Y - real_y); float ripple_offset = sqrtf (a_sqr + b_sqr) / RIPPLE_RADIUS; float ripple_angle = (RIPPLE_PERIODS * 2 * G_PI * ripple_offset) + ripple_shift; float ripple_sin = sinf (ripple_angle); float h, s, l; guint8 *color; vert[2] = (wave_sin * WAVE_DEPTH) + (ripple_sin * RIPPLE_DEPTH); /* Burn some CPU time picking a pretty color... */ h = (HSL_OFFSET + wave_sin + ripple_sin + period_progress_sin) * HSL_SCALE; s = 0.5; l = 0.25 + (period_progress_sin + 1.0) / 4.0; color = &state->quad_mesh_colors[4 * vert_index]; /* A bit of a sneaky cast, but it seems safe to assume the ClutterColor * typedef is set in stone... */ clutter_color_from_hls ((ClutterColor *)color, h * 360.0, l, s); color[0] = (color[0] * color[3] + 128) / 255; color[1] = (color[1] * color[3] + 128) / 255; color[2] = (color[2] * color[3] + 128) / 255; } cogl_vertex_buffer_add (state->buffer, "gl_Vertex", 3, /* n components */ COGL_ATTRIBUTE_TYPE_FLOAT, FALSE, /* normalized */ 0, /* stride */ state->quad_mesh_verts); cogl_vertex_buffer_add (state->buffer, "gl_Color", 4, /* n components */ COGL_ATTRIBUTE_TYPE_UNSIGNED_BYTE, FALSE, /* normalized */ 0, /* stride */ state->quad_mesh_colors); cogl_vertex_buffer_submit (state->buffer); clutter_actor_set_rotation (state->dummy, CLUTTER_Z_AXIS, 360 * period_progress, (MESH_WIDTH * QUAD_WIDTH) / 2, (MESH_HEIGHT * QUAD_HEIGHT) / 2, 0); clutter_actor_set_rotation (state->dummy, CLUTTER_X_AXIS, 360 * period_progress, (MESH_WIDTH * QUAD_WIDTH) / 2, (MESH_HEIGHT * QUAD_HEIGHT) / 2, 0); }
int main (int argc, char *argv[]) { ClutterActor *stage; ClutterActor *texture; ClutterState *transitions; GError *error = NULL; gfloat texture_width, texture_height; clutter_init (&argc, &argv); stage = clutter_stage_get_default (); g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL); texture = clutter_texture_new (); clutter_actor_add_constraint (texture, clutter_align_constraint_new (stage, CLUTTER_ALIGN_X_AXIS, 0.5)); clutter_actor_add_constraint (texture, clutter_align_constraint_new (stage, CLUTTER_ALIGN_Y_AXIS, 0.5)); clutter_texture_set_sync_size (CLUTTER_TEXTURE (texture), TRUE); clutter_texture_set_from_file (CLUTTER_TEXTURE (texture), TESTS_DATA_DIR "/redhand.png", &error); if (error != NULL) { g_error ("Problem loading image into texture - %s", error->message); g_error_free (error); return 1; } clutter_actor_get_size (texture, &texture_width, &texture_height); clutter_actor_set_size (stage, texture_width * 2, texture_height * 2); /* set all centres of rotation to the centre of the texture */ clutter_actor_set_rotation (texture, CLUTTER_X_AXIS, 0.0, texture_width * 0.5, texture_height * 0.5, 0.0); clutter_actor_set_rotation (texture, CLUTTER_Y_AXIS, 0.0, texture_width * 0.5, texture_height * 0.5, 0.0); clutter_actor_set_z_rotation_from_gravity (texture, 0.0, CLUTTER_GRAVITY_CENTER); clutter_container_add_actor (CLUTTER_CONTAINER (stage), texture); /* set up the animations */ transitions = clutter_state_new (); clutter_state_set (transitions, NULL, "start", texture, "rotation-angle-x", CLUTTER_LINEAR, 0.0, texture, "rotation-angle-y", CLUTTER_LINEAR, 0.0, texture, "rotation-angle-z", CLUTTER_LINEAR, 0.0, NULL); clutter_state_set (transitions, NULL, "x-cw", texture, "rotation-angle-x", CLUTTER_LINEAR, ROTATION_ANGLE, NULL); clutter_state_set (transitions, NULL, "x-ccw", texture, "rotation-angle-x", CLUTTER_LINEAR, -ROTATION_ANGLE, NULL); clutter_state_set (transitions, NULL, "x-after", texture, "rotation-angle-x", CLUTTER_LINEAR, 0.0, NULL); clutter_state_set (transitions, NULL, "y-cw", texture, "rotation-angle-y", CLUTTER_LINEAR, ROTATION_ANGLE, NULL); clutter_state_set (transitions, NULL, "y-ccw", texture, "rotation-angle-y", CLUTTER_LINEAR, -ROTATION_ANGLE, NULL); clutter_state_set (transitions, NULL, "y-after", texture, "rotation-angle-y", CLUTTER_LINEAR, 0.0, NULL); clutter_state_set (transitions, NULL, "z-cw", texture, "rotation-angle-z", CLUTTER_LINEAR, ROTATION_ANGLE, NULL); clutter_state_set (transitions, NULL, "z-ccw", texture, "rotation-angle-z", CLUTTER_LINEAR, -ROTATION_ANGLE, NULL); clutter_state_set_duration (transitions, NULL, NULL, DURATION); clutter_state_set_duration (transitions, "start", NULL, DURATION * 0.5); clutter_state_set_duration (transitions, NULL, "start", DURATION * 0.5); clutter_state_set_duration (transitions, NULL, "x-after", DURATION * 0.5); clutter_state_set_duration (transitions, NULL, "y-after", DURATION * 0.5); clutter_state_warp_to_state (transitions, "start"); g_signal_connect (transitions, "completed", G_CALLBACK (_set_next_state), NULL); clutter_state_set_state (transitions, "x-cw"); clutter_actor_show (stage); clutter_main (); return 0; }
int main (int argc, char **argv) { ClutterActor *stage = stage; ClutterActor *side_box; ClutterActor *button_box; ClutterActor *box; ClutterAnimation *anim; MashLightSet *light_set; MxStyle *style; GError *error = NULL; Data data; int i; if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) return 1; style = mx_style_get_default (); if (!mx_style_load_from_file (style, "lights.css", &error)) { g_warning ("Error setting style: %s", error->message); g_clear_error (&error); } stage = clutter_stage_get_default (); clutter_actor_set_size (stage, 800, 600); side_box = mx_table_new (); clutter_actor_set_name (side_box, "side-box"); clutter_container_add_actor (CLUTTER_CONTAINER (stage), side_box); clutter_actor_set_size (side_box, 300, clutter_actor_get_height (stage)); clutter_actor_set_x (side_box, clutter_actor_get_width (stage) - clutter_actor_get_width (side_box)); button_box = mx_table_new (); mx_table_add_actor (MX_TABLE (side_box), button_box, 0, 0); data.notebook = mx_notebook_new (); mx_table_add_actor (MX_TABLE (side_box), data.notebook, 1, 0); data.model = mash_model_new_from_file (MASH_DATA_NONE, argc > 1 ? argv[1] : "suzanne.ply", &error); if (data.model == NULL) { g_warning ("Error loading model: %s", error->message); g_clear_error (&error); return 1; } light_set = mash_light_set_new (); box = clutter_box_new (clutter_fixed_layout_new ()); clutter_actor_set_size (data.model, 400, 400); clutter_actor_set_position (data.model, 50.0, 100.0); clutter_container_add_actor (CLUTTER_CONTAINER (box), data.model); clutter_container_add_actor (CLUTTER_CONTAINER (stage), box); g_signal_connect_swapped (box, "paint", G_CALLBACK (cogl_set_depth_test_enabled), GINT_TO_POINTER (TRUE)); g_signal_connect_data (box, "paint", G_CALLBACK (cogl_set_depth_test_enabled), GINT_TO_POINTER (FALSE), NULL, G_CONNECT_AFTER | G_CONNECT_SWAPPED); data.light_marker_material = cogl_material_new (); { CoglColor color; cogl_color_set_from_4ub (&color, 255, 0, 0, 255); /* Use the layer state to ignore the vertex color from the shader so that the light marker won't itself be lit */ cogl_material_set_layer_combine_constant (data.light_marker_material, 0, &color); cogl_material_set_layer_combine (data.light_marker_material, 0, "RGBA = REPLACE(CONSTANT)", NULL); } clutter_actor_set_rotation (data.model, CLUTTER_Y_AXIS, 0.0f, clutter_actor_get_width (data.model) / 2.0f, 0.0f, 0.0f); anim = clutter_actor_animate (data.model, CLUTTER_LINEAR, 3000, "rotation-angle-y", 360.0f, NULL); clutter_animation_set_loop (anim, TRUE); for (i = 0; i < N_LIGHTS; i++) { ClutterActor *table = mx_table_new (); ClutterActor *button; static ClutterActor *(* constructors[N_LIGHTS]) (void) = { mash_directional_light_new, mash_point_light_new, mash_spot_light_new }; static const ClutterColor black = { 0, 0, 0, 255 }; data.lights[i] = constructors[i] (); button = mx_button_new_with_label (G_OBJECT_TYPE_NAME (data.lights[i])); mx_table_add_actor (MX_TABLE (button_box), button, i, 0); /* Default to disable all of the lights */ g_object_set (data.lights[i], "ambient", &black, "diffuse", &black, "specular", &black, NULL); data.notebook_buttons[i] = button; clutter_container_add_actor (CLUTTER_CONTAINER (box), data.lights[i]); mash_light_set_add_light (light_set, MASH_LIGHT (data.lights[i])); add_color_prop (table, "ambient light", G_OBJECT (data.lights[i]), "ambient"); add_color_prop (table, "diffuse light", G_OBJECT (data.lights[i]), "diffuse"); add_color_prop (table, "specular light", G_OBJECT (data.lights[i]), "specular"); if (MASH_IS_POINT_LIGHT (data.lights[i])) { add_float_prop (table, "constant attenuation", G_OBJECT (data.lights[i]), "constant-attenuation", 0.0f, 10.0f); add_float_prop (table, "linear attenuation", G_OBJECT (data.lights[i]), "linear-attenuation", 0.0f, 10.0f); add_float_prop (table, "quadratic attenuation", G_OBJECT (data.lights[i]), "quadratic-attenuation", 0.0f, 10.0f); } if (MASH_IS_SPOT_LIGHT (data.lights[i])) { clutter_actor_set_x (data.lights[i], 250); add_float_prop (table, "spot cutoff", G_OBJECT (data.lights[i]), "spot-cutoff", 0.0f, 90.0f); add_float_prop (table, "spot exponent", G_OBJECT (data.lights[i]), "spot-exponent", 0.0f, 128.0f); } clutter_container_add_actor (CLUTTER_CONTAINER (data.notebook), table); data.notebook_pages[i] = table; } { ClutterActor *button; ClutterActor *table; CoglHandle material; float maximum_shininess; material = mash_model_get_pipeline (MASH_MODEL (data.model)); /* Before version 1.3.10 on the 1.3 branch and 1.2.14 on the 1.2 branch Cogl would remap the shininess property to the range [0,1]. After this it is just a value greater or equal to zero (but GL imposes a limit of 128.0) */ if (clutter_check_version (1, 3, 9) || (clutter_major_version == 1 && clutter_minor_version == 2 && clutter_micro_version >= 13)) maximum_shininess = 128.0f; else maximum_shininess = 1.0f; cogl_material_set_shininess (material, maximum_shininess); button = mx_button_new_with_label ("Material"); data.notebook_buttons[i] = button; mx_table_add_actor (MX_TABLE (button_box), button, i, 0); table = mx_table_new (); data.notebook_pages[i] = table; clutter_container_add_actor (CLUTTER_CONTAINER (data.notebook), table); add_material_color_prop (table, "emission", material, cogl_material_set_emission, cogl_material_get_emission); add_material_color_prop (table, "diffuse", material, cogl_material_set_diffuse, cogl_material_get_diffuse); add_material_color_prop (table, "ambient", material, cogl_material_set_ambient, cogl_material_get_ambient); add_material_color_prop (table, "specular", material, cogl_material_set_specular, cogl_material_get_specular); add_material_float_prop (table, "shininess", material, 0.0f, maximum_shininess, cogl_material_set_shininess, cogl_material_get_shininess); } mash_model_set_light_set (MASH_MODEL (data.model), light_set); g_object_unref (light_set); for (i = 0; i < N_PAGES; i++) { g_signal_connect (data.notebook_buttons[i], "notify::toggled", G_CALLBACK (notebook_button_cb), &data); mx_button_set_is_toggle (MX_BUTTON (data.notebook_buttons[i]), TRUE); } mx_button_set_toggled (MX_BUTTON (data.notebook_buttons[0]), TRUE); g_signal_connect (stage, "motion-event", G_CALLBACK (motion_event_cb), &data); clutter_actor_show (stage); clutter_main (); cogl_handle_unref (data.light_marker_material); return 0; }
void scene_prismatic_joint (Scene *scene) { ClutterActor *ground; ClutterActor *group; ClutterActor *prev_hand = NULL; ClutterActor *first_hand = NULL; ClutterActor *stage; stage = clutter_stage_get_default (); first_hand = ground = clutter_rectangle_new (); clutter_actor_set_size (ground, 500, 120); group = clutter_box2d_new (); clutter_group_add (CLUTTER_GROUP (stage), group); clutter_group_add (CLUTTER_GROUP (group), ground); clutter_actor_set_position (ground, clutter_actor_get_width ( ground) * -0.3, 568); /* this is wrong */ add_cage (group, TRUE); ground = clutter_rectangle_new (); clutter_actor_set_size (ground, 256, 3); clutter_actor_set_position (ground, -100, 310); clutter_actor_set_rotation (ground, CLUTTER_Z_AXIS, 30, 128, 16, 0); clutter_group_add (CLUTTER_GROUP (group), ground); clutter_container_child_set (CLUTTER_CONTAINER (group), ground, "mode", CLUTTER_BOX2D_STATIC, NULL); ground = clutter_rectangle_new (); clutter_actor_set_size (ground, 256, 3); clutter_actor_set_position (ground, 200, 200); clutter_actor_set_rotation (ground, CLUTTER_Z_AXIS, -30, 0, 0, 0); clutter_group_add (CLUTTER_GROUP (group), ground); clutter_container_child_set (CLUTTER_CONTAINER (group), ground, "mode", CLUTTER_BOX2D_STATIC, NULL); /*add_hand (group, 100, 100);*/ prev_hand = add_hand (group, 200, 100); if(0){ ClutterVertex anchor1 = { (0), (0) }; ClutterVertex anchor2 = { (0), (0) }; ClutterVertex axis = { (100.0), (20.0) }; clutter_box2d_add_prismatic_joint (CLUTTER_BOX2D (group), first_hand, prev_hand, &anchor1, &anchor2, 200.0, 220.0, &axis); } clutter_actor_set_depth (group, -600); clutter_actor_set_position (group, 0, -100); clutter_actor_set_reactive (group, TRUE); clutter_box2d_set_simulating (CLUTTER_BOX2D (group), simulating); scene->group = group; }
static void set_rotation (ClutterActor *actor, gdouble value) { clutter_actor_set_rotation (actor, CLUTTER_Z_AXIS, value, 0, 0, 0); }