GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Mon Oct 20, 2014 4:25 am

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Clutter and Clutter-box2d example ( C )
PostPosted: Mon Mar 09, 2009 2:22 pm 
Offline
GTK+ Guru

Joined: Thu Jun 21, 2007 1:52 pm
Posts: 198
Location: Wilkes Barre Pa
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:
Image


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 12, 2009 3:50 am 
Offline
GTK+ Guru

Joined: Thu Jun 21, 2007 1:52 pm
Posts: 198
Location: Wilkes Barre Pa
Updated:

1. Cleaned up code
2. Added comments
3. Added screenshot


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group