Esempio n. 1
0
static gboolean
action_add_triangle (ClutterActor *action,
                     ClutterEvent *event,
                     gpointer      userdata)
{
  const ClutterColor transparent = { 0x00, 0x00, 0x00, 0x01 };
  ClutterActor *group = CLUTTER_ACTOR (userdata);
  ClutterVertex vertices[] =
    { { 0.5, 0.0, 0.0 },
      { 1.0, 1.0, 0.0 },
      { 0.0, 1.0, 0.0 } };
  ClutterActor *box;

  box = clutter_rectangle_new_with_color (&transparent);
  clutter_actor_set_size (box, 50, 50);
  clutter_actor_set_position (box, event->button.x, event->button.y);
  clutter_group_add (CLUTTER_GROUP (group), box);

  /* Create a triangle vertex array */
  clutter_box2d_child_set_outline (CLUTTER_BOX2D (group), box, vertices, 3);
  g_signal_connect (box, "paint",
                    G_CALLBACK (paint_triangle), NULL);

  return FALSE;
}
Esempio n. 2
0
static
gboolean
action_zero_gravity (ClutterActor *action,
                     ClutterEvent *event,
                     gpointer      userdata)
{
  ClutterBox2D *box2d  = CLUTTER_BOX2D (scene_get_group ());
  ClutterVertex vertex = { 0, 0, 0 };

  g_object_set (G_OBJECT (box2d), "gravity", &vertex, NULL);

  return FALSE;
}
Esempio n. 3
0
static
gboolean
action_set_static (ClutterActor *action,
                   ClutterEvent *event,
                   gpointer      userdata)
{
  ClutterActor *actor;
  ClutterBox2D *box2d;

  actor = CLUTTER_ACTOR (userdata);
  box2d = CLUTTER_BOX2D (clutter_actor_get_parent (actor));

  clutter_container_child_set (CLUTTER_CONTAINER (box2d), actor,
                               "mode", CLUTTER_BOX2D_STATIC, NULL);

  return FALSE;
}
Esempio n. 4
0
static
gboolean
action_set_linear_velocity (ClutterActor *action,
                            ClutterEvent *event,
                            gpointer      userdata)
{
  ClutterActor *actor;
  ClutterBox2D *box2d;
  ClutterVertex velocity = {  (150.0f),
                              (-150.0f) };
  actor = CLUTTER_ACTOR (userdata);
  box2d = CLUTTER_BOX2D (clutter_actor_get_parent (actor));

  clutter_container_child_set (CLUTTER_CONTAINER (box2d),
                               actor, "linear-velocity", &velocity, NULL);

  return TRUE;
}
Esempio n. 5
0
void
scene_pulley_joint (Scene *scene)
{
  ClutterActor *stage;
  ClutterActor *box2d;

  stage = clutter_stage_get_default ();

  box2d = clutter_box2d_new ();
  clutter_container_add_actor (CLUTTER_CONTAINER (stage), box2d);
  scene->group = box2d;

  add_cage (box2d, FALSE);

  {
    ClutterVertex v1, v2, v3;
    ClutterActor *joint1, *joint2, *box1, *box2;

    /* Create platform 1 */
    joint1 = create_circle (10);
    clutter_actor_set_position (joint1, 110, 250);
    clutter_container_add_actor (CLUTTER_CONTAINER (box2d), joint1);
    clutter_box2d_child_set_is_circle (CLUTTER_BOX2D (box2d), joint1, TRUE);
    clutter_box2d_child_set_mode (CLUTTER_BOX2D (box2d), joint1,
                                  CLUTTER_BOX2D_DYNAMIC);
    clutter_box2d_child_set_manipulatable (CLUTTER_BOX2D (box2d), joint1,
                                           TRUE);

    box1 = clutter_rectangle_new ();
    clutter_actor_set_size (box1, 200, 20);
    clutter_actor_set_position (box1, 10, 350);
    clutter_container_add_actor (CLUTTER_CONTAINER (box2d), box1);
    clutter_box2d_child_set_mode (CLUTTER_BOX2D (box2d), box1,
                                  CLUTTER_BOX2D_DYNAMIC);
    clutter_box2d_child_set_manipulatable (CLUTTER_BOX2D (box2d), box1,
                                           TRUE);

    add_hand (box2d, 20, 350 - 62);
    add_hand (box2d, 210 - 58, 350 - 62);

    v1 = (ClutterVertex){10, 10, 0};
    v2 = (ClutterVertex){0, 0, 0};
    v3 = (ClutterVertex){200, 0, 0};
    clutter_box2d_add_distance_joint (CLUTTER_BOX2D (box2d),
                                      joint1, box1,
                                      &v1, &v2,
                                      150, 0, 0);
    clutter_box2d_add_distance_joint (CLUTTER_BOX2D (box2d),
                                      joint1, box1,
                                      &v1, &v3,
                                      150, 0, 0);

    /* Create platform 2 */
    joint2 = create_circle (10);
    clutter_actor_set_position (joint2, 530, 250);
    clutter_container_add_actor (CLUTTER_CONTAINER (box2d), joint2);
    clutter_box2d_child_set_is_circle (CLUTTER_BOX2D (box2d), joint2, TRUE);
    clutter_box2d_child_set_mode (CLUTTER_BOX2D (box2d), joint2,
                                  CLUTTER_BOX2D_DYNAMIC);
    clutter_box2d_child_set_manipulatable (CLUTTER_BOX2D (box2d), joint2,
                                           TRUE);

    box2 = clutter_rectangle_new ();
    clutter_actor_set_size (box2, 200, 20);
    clutter_actor_set_position (box2, 430, 350);
    clutter_container_add_actor (CLUTTER_CONTAINER (box2d), box2);
    clutter_box2d_child_set_mode (CLUTTER_BOX2D (box2d), box2,
                                  CLUTTER_BOX2D_DYNAMIC);
    clutter_box2d_child_set_manipulatable (CLUTTER_BOX2D (box2d), box2,
                                           TRUE);

    add_hand (box2d, 440, 350 - 62);
    add_hand (box2d, 640 - 58, 350 - 62);

    clutter_box2d_add_distance_joint (CLUTTER_BOX2D (box2d),
                                      joint2, box2,
                                      &v1, &v2,
                                      150, 0, 0);
    clutter_box2d_add_distance_joint (CLUTTER_BOX2D (box2d),
                                      joint2, box2,
                                      &v1, &v3,
                                      150, 0, 0);

    /* Create pulley joint */
    v1 = (ClutterVertex){ 10, 10, 0 };
    v2 = (ClutterVertex){ 120, 50, 0};
    v3 = (ClutterVertex){ 540, 50, 0};
    clutter_box2d_add_pulley_joint (CLUTTER_BOX2D (box2d),
                                    joint1, joint2,
                                    &v1, &v1,
                                    &v2, &v3,
                                    210, 210,
                                    400, 400,
                                    1.0);
  }

  clutter_box2d_set_simulating (CLUTTER_BOX2D (box2d), simulating);
}
Esempio n. 6
0
void
scene_chain (Scene *scene)
{
  ClutterActor *stage;
  ClutterActor *group;
  ClutterActor *box;

  stage = clutter_stage_get_default ();

  group = clutter_box2d_new ();
  clutter_group_add (CLUTTER_GROUP (stage), group);
  scene->group = group;

  add_cage (group, TRUE);

  {
    gint          i;
    gint          y;
    gint          numlinks = 32;
    ClutterActor *prev_actor;

    y = 50;
    box = clutter_rectangle_new ();
    clutter_actor_set_size (box, 18, 5);
    clutter_actor_set_position (box, clutter_actor_get_width(stage)/2, y);
    clutter_group_add (CLUTTER_GROUP (group), box);

    clutter_container_child_set (CLUTTER_CONTAINER (group), box,
                                 "mode", CLUTTER_BOX2D_STATIC, NULL);

    prev_actor = box;

    numlinks = clutter_actor_get_height (stage)/20;
    if (clutter_actor_get_width (stage)/20 < numlinks)
      {
        numlinks = clutter_actor_get_width (stage)/20;
      }

    for (i = 0; i < numlinks; ++i)
      {
        box = clutter_rectangle_new ();
        clutter_actor_set_size (box, 18, 5);
        clutter_actor_set_position (box, 20 + 20 * i, y+=1);
        clutter_group_add (CLUTTER_GROUP (group), box);

        clutter_container_child_set (CLUTTER_CONTAINER (group), box,
                                       "manipulatable", TRUE,
                                     "mode", CLUTTER_BOX2D_DYNAMIC, NULL);

        {
          ClutterVertex anchor1 = {  (18.0),
                                     (0.0) };
          ClutterVertex anchor2 = {  (0.0),
                                     (0.0) };
          clutter_box2d_add_revolute_joint (CLUTTER_BOX2D (group),
                                            prev_actor, box,
                                            &anchor1,
                                            &anchor2);
        }

        prev_actor = box;
      }
  }

  clutter_box2d_set_simulating (CLUTTER_BOX2D (group), simulating);
}
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;
}
Esempio n. 8
0
static gboolean
actor_manipulator_press (ClutterActor *stage,
                         ClutterEvent *event,
                         gpointer      data)
{
  ClutterActor *actor;

  actor = clutter_stage_get_actor_at_pos (CLUTTER_STAGE (stage),
                                          CLUTTER_PICK_ALL,
                                          event->button.x,
                                          event->button.y);


  if (actor == stage ||
      CLUTTER_IS_GROUP (actor))
    {
      if (event->button.button == 3)
        {
          popup_nuke (stage, event->button.x, event->button.y);
          popup_add ("+rectangle", "bar", G_CALLBACK (
                       action_add_rectangle), scene_get_group ());
          popup_add ("+circle", "bar", G_CALLBACK (
                       action_add_circle), scene_get_group ());
          popup_add ("+triangle", "bar", G_CALLBACK (
                       action_add_triangle), scene_get_group ());
          popup_add ("+text", "bar", G_CALLBACK (
                       action_add_text), scene_get_group ());
          popup_add ("+image", "bar", G_CALLBACK (
                       action_add_image), scene_get_group ());
#if 0
          popup_add ("+block-tree", "bar", G_CALLBACK (
                       action_add_block_tree), scene_get_group ());
#endif
          popup_add ("zero gravity", "bar", G_CALLBACK (
                       action_zero_gravity), scene_get_group ());
        }
      return TRUE;
    }

  if (actor == NULL)
    {
      return FALSE;
    }

  if (event->button.button == 3)
    {
      popup_nuke (stage, event->button.x, event->button.y);
      popup_add ("remove", "bar", G_CALLBACK (action_remove), actor);
      popup_add ("set linear velocity", "bar", G_CALLBACK (action_set_linear_velocity), actor);
      popup_add ("set dynamic", "bar", G_CALLBACK (action_set_dynamic), actor);
      popup_add ("set static", "bar", G_CALLBACK (action_set_static), actor);
      popup_add_slider ("opacity", "hm", 0.0, 255.0,
                        clutter_actor_get_opacity (actor) * 1.0,
                        G_CALLBACK (set_opacity), actor);

      popup_add_slider ("rotation", "hm", 0.0, 360.0,
                        clutter_actor_get_rotation (actor, CLUTTER_Z_AXIS, NULL,
                                                    NULL, NULL),
                        G_CALLBACK (set_rotation), actor);

      popup_add ("ok", "bar", NULL, NULL);
      return TRUE;
    }

  if (!should_be_manipulated (actor))
    return FALSE;

  manipulated_actor = actor;

  clutter_actor_get_position (actor, &orig_x, &orig_y);
  orig_rotation = clutter_actor_get_rotation (actor, CLUTTER_Z_AXIS, NULL,
                                               NULL,
                                               NULL);

  start_x =  (event->button.x);
  start_y =  (event->button.y);

  clutter_actor_transform_stage_point (
    clutter_actor_get_parent (manipulated_actor),
    start_x, start_y,
    &start_x, &start_y);


  mode = Direct;


#ifdef BOX2D_MANIPULATION
  /* Use Box2D manipulation if the actor is dynamic, and the physics
   * engine is running
   */
  if (CLUTTER_IS_BOX2D (scene_get_group ()) &&
      clutter_box2d_get_simulating (CLUTTER_BOX2D (scene_get_group ())))
    {
      ClutterBox2D *box2d  = CLUTTER_BOX2D (scene_get_group ());
      /*ClutterVertex target = { start_x, start_y };*/
      gint type;
      
      clutter_container_child_get (CLUTTER_CONTAINER (box2d),
                                   manipulated_actor, "mode", &type, NULL);
      	  
      if (type == CLUTTER_BOX2D_DYNAMIC)
        {
#if 0
            mouse_joint = clutter_box2d_add_mouse_joint (CLUTTER_BOX2D (
                                                           scene_get_group ()),
                                                         manipulated_actor,
                                                         &target);
#endif
            mode = None; /*Box2D;*/
            manipulated_actor = NULL;
            return FALSE;
        }
    }
#endif
  clutter_set_motion_events_enabled (FALSE);

  return TRUE;
}