This is a simple clutter & clutter-box2d physics example
At the moment there is no way to apply force or torque to an actor
programatically (it only happens as a consequence of manipulation or
indirectly when colliding with another actor that has had its linear
velocity set.) See bug #1146 in the clutter bugzilla, patches are
welcome.)
Clutter Bugzilla #1146
http://bugzilla.openedhand.com/show_bug.cgi?id=1146
Clutter
[Reference]
http://www.clutter-project.org/docs/clutter/stable/
Clutter-box2d
[Reference]
http://ftp.moblin.org/moblin/releases/t ... ter-box2d/
simple.c
Code:
#include <clutter/clutter.h>
#include <clutter-box2d.h>
/* gcc -Wall -g simple.c -o simple `pkg-config clutter-0.8 clutter-box2d-0.8 --cflags --libs` */
int main (gint argc, gchar **argv)
{
ClutterColor black = {0x33, 0x33, 0x33, 0xff};
ClutterColor white = {0xff, 0xff, 0xff, 0xff};
ClutterActor *stage;
ClutterActor *box2d;
ClutterActor *box;
ClutterActor *title;
clutter_init (&argc, &argv);
/* Create a new stage, set the stage color to black & show the stage*/
stage = clutter_stage_get_default ();
clutter_stage_set_color (CLUTTER_STAGE (stage), &black);
clutter_actor_show (stage);
/* Create a new box2d container and add it to the stage */
box2d = clutter_box2d_new ();
clutter_container_add_actor (CLUTTER_CONTAINER (stage), box2d);
/* Create a dynamic actor set it's position, rotation, color to white & add it to the
* box2d container.*/
title = clutter_label_new_full ("Sans 40px", "Clutter-Box2D", &white);
clutter_actor_set_position (title, 100, 120);
clutter_actor_set_rotation (title, CLUTTER_Z_AXIS, 23, 0, 0, 0);
clutter_group_add (CLUTTER_GROUP (box2d), title);
/* Set child properties, that the actor have as a consequence of
* being in the box2d container.*/
clutter_container_child_set (CLUTTER_CONTAINER (box2d), title,
"manipulatable", TRUE,
"mode", CLUTTER_BOX2D_DYNAMIC, NULL);
/* Create a static actor set its size, position, color to white & add it to the
* box2d container.*/
box = clutter_rectangle_new_with_color (&white);
clutter_actor_set_size (box, 300, 23);
clutter_actor_set_position (box, 0, 250);
clutter_container_add_actor (CLUTTER_CONTAINER (box2d), box);
/* Set child properties, that the actor have as a consequence of
* being in the box2d container.*/
clutter_container_child_set (CLUTTER_CONTAINER (box2d), box,
"mode", CLUTTER_BOX2D_STATIC, NULL);
/* Start simulating */
clutter_box2d_set_simulating (CLUTTER_BOX2D (box2d), TRUE);
/* Enter clutters main loop */
clutter_main ();
return 0;
}
Screenshot:
