gnomemm r1670 - in clutter-box2dmm/trunk: . examples examples/bridge examples/chain examples/pyramid examples/slides examples/table



Author: murrayc
Date: Sun Aug 10 13:43:47 2008
New Revision: 1670
URL: http://svn.gnome.org/viewvc/gnomemm?rev=1670&view=rev

Log:
2008-08-10  Murray Cumming  <murrayc murrayc com>

* configure.in:
* examples/Makefile.am:
* examples/chain/
* examples/pyramid/
* examples/slides/
* examples/table/:
Added C++ versions of the other examples for clutter-box2d.

Added:
   clutter-box2dmm/trunk/examples/chain/
      - copied from r1666, /clutter-box2dmm/trunk/examples/bridge/
   clutter-box2dmm/trunk/examples/pyramid/
      - copied from r1666, /clutter-box2dmm/trunk/examples/bridge/
   clutter-box2dmm/trunk/examples/pyramid/redhand.png   (contents, props changed)
   clutter-box2dmm/trunk/examples/slides/
      - copied from r1666, /clutter-box2dmm/trunk/examples/bridge/
   clutter-box2dmm/trunk/examples/slides/redhand.png   (contents, props changed)
   clutter-box2dmm/trunk/examples/table/
      - copied from r1666, /clutter-box2dmm/trunk/examples/bridge/
   clutter-box2dmm/trunk/examples/table/redhand.png   (contents, props changed)
Modified:
   clutter-box2dmm/trunk/ChangeLog
   clutter-box2dmm/trunk/configure.in
   clutter-box2dmm/trunk/examples/Makefile.am
   clutter-box2dmm/trunk/examples/bridge/main.cc
   clutter-box2dmm/trunk/examples/chain/main.cc
   clutter-box2dmm/trunk/examples/pyramid/main.cc
   clutter-box2dmm/trunk/examples/slides/main.cc
   clutter-box2dmm/trunk/examples/table/main.cc

Modified: clutter-box2dmm/trunk/configure.in
==============================================================================
--- clutter-box2dmm/trunk/configure.in	(original)
+++ clutter-box2dmm/trunk/configure.in	Sun Aug 10 13:43:47 2008
@@ -120,5 +120,9 @@
   demo/Makefile
   examples/Makefile
     examples/bridge/Makefile
+    examples/chain/Makefile
+    examples/pyramid/Makefile
+    examples/slides/Makefile
+    examples/table/Makefile
 ])
 :

Modified: clutter-box2dmm/trunk/examples/Makefile.am
==============================================================================
--- clutter-box2dmm/trunk/examples/Makefile.am	(original)
+++ clutter-box2dmm/trunk/examples/Makefile.am	Sun Aug 10 13:43:47 2008
@@ -1,3 +1,3 @@
-SUBDIRS = bridge
+SUBDIRS = bridge chain pyramid slides table
 
 

Modified: clutter-box2dmm/trunk/examples/bridge/main.cc
==============================================================================
--- clutter-box2dmm/trunk/examples/bridge/main.cc	(original)
+++ clutter-box2dmm/trunk/examples/bridge/main.cc	Sun Aug 10 13:43:47 2008
@@ -50,12 +50,10 @@
     return -1;
   }
 
-  Clutter::Color stage_color(0x61, 0x64, 0x8c, 0xff);
   Glib::RefPtr<Clutter::Stage> stage = Clutter::Stage::get_default();
+  stage->set_color( Clutter::Color(0x00, 0x00, 0x00, 0xff) );
   stage->set_size(800, 600);
-
-  stage->set_title("Actors Test");
-  stage->set_color(stage_color);
+  stage->set_title("Clutter::Box2D Example");
 
 
   Glib::RefPtr<Clutter::Box2D::Box2D> box2d = Clutter::Box2D::Box2D::create();
@@ -64,8 +62,8 @@
 
   add_cage(box2d, true /* roof */);
 
-  int y = stage->get_height() / 2;
-  int numplanks = stage->get_width() / 20 - 2;
+  const int y = stage->get_height() / 2;
+  int num_planks = stage->get_width() / 20 - 2;
   Glib::RefPtr<Clutter::Rectangle> rect = Clutter::Rectangle::create();
   rect->set_size(18, 5);
   rect->set_position(10, y);
@@ -75,7 +73,7 @@
 
   Glib::RefPtr<Clutter::Actor> prev_actor = rect;
 
-  for(int i = 0; i < numplanks; ++i)
+  for(int i = 0; i < num_planks; ++i)
   {
     Glib::RefPtr<Clutter::Rectangle> box = Clutter::Rectangle::create();
     box->set_size(18, 5);
@@ -93,12 +91,12 @@
 
   Glib::RefPtr<Clutter::Rectangle> box = Clutter::Rectangle::create();
   box->set_size(18, 5);
-  box->set_position(20 + 20 * numplanks, y);
+  box->set_position(20 + 20 * num_planks, y);
   box2d->add_actor(box);
 
   box2d->set_child_property(box, "mode", (int)Clutter::Box2D::BOX2D_STATIC);
 
-  ClutterVertex anchor = { CLUTTER_UNITS_FROM_FLOAT (20 + 20 * numplanks),
+  ClutterVertex anchor = { CLUTTER_UNITS_FROM_FLOAT (20 + 20 * num_planks),
              CLUTTER_UNITS_FROM_FLOAT (y) };
   box2d->add_revolute_joint2(prev_actor, box, &anchor);
 

Modified: clutter-box2dmm/trunk/examples/chain/main.cc
==============================================================================
--- /clutter-box2dmm/trunk/examples/bridge/main.cc	(original)
+++ clutter-box2dmm/trunk/examples/chain/main.cc	Sun Aug 10 13:43:47 2008
@@ -50,13 +50,10 @@
     return -1;
   }
 
-  Clutter::Color stage_color(0x61, 0x64, 0x8c, 0xff);
   Glib::RefPtr<Clutter::Stage> stage = Clutter::Stage::get_default();
+  stage->set_color( Clutter::Color(0x00, 0x00, 0x00, 0xff) );
   stage->set_size(800, 600);
-
-  stage->set_title("Actors Test");
-  stage->set_color(stage_color);
-
+  stage->set_title("Clutter::Box2D Example");
 
   Glib::RefPtr<Clutter::Box2D::Box2D> box2d = Clutter::Box2D::Box2D::create();
   stage->add_actor(box2d);
@@ -64,44 +61,37 @@
 
   add_cage(box2d, true /* roof */);
 
-  int y = stage->get_height() / 2;
-  int numplanks = stage->get_width() / 20 - 2;
+  int y = 50;
+  const int num_links = stage->get_height() / 20 - 2;
+  if((stage->get_width() / 20) < num_links)
+    num_links = stage->get_width() / 20;
+
   Glib::RefPtr<Clutter::Rectangle> rect = Clutter::Rectangle::create();
   rect->set_size(18, 5);
-  rect->set_position(10, y);
+  rect->set_position(stage->get_width() / 2, y);
   box2d->add_actor(rect);
 
   box2d->set_child_property(rect, "mode", (int)Clutter::Box2D::BOX2D_STATIC);  //TODO: Avoid the need for the int cast.
 
   Glib::RefPtr<Clutter::Actor> prev_actor = rect;
 
-  for(int i = 0; i < numplanks; ++i)
+  for(int i = 0; i < num_links; ++i)
   {
     Glib::RefPtr<Clutter::Rectangle> box = Clutter::Rectangle::create();
     box->set_size(18, 5);
-    box->set_position(20 + 20 * i, y);
+    box->set_position(20 + 20 * i, y+=1);
     box2d->add_actor(box);
 
     box2d->set_child_property(box, "manipulatable", true);
     box2d->set_child_property(box, "mode", (int)Clutter::Box2D::BOX2D_DYNAMIC);
 
-    ClutterVertex anchor = { CLUTTER_UNITS_FROM_FLOAT (20 + 20 * i), CLUTTER_UNITS_FROM_FLOAT (y) };
-    box2d->add_revolute_joint2(prev_actor, box, &anchor);
+    ClutterVertex anchor1 = { CLUTTER_UNITS_FROM_FLOAT (18), CLUTTER_UNITS_FROM_FLOAT (0.0) };
+    ClutterVertex anchor2 = { CLUTTER_UNITS_FROM_FLOAT (0.0), CLUTTER_UNITS_FROM_FLOAT (0.0) };
+    box2d->add_revolute_joint(prev_actor, box, &anchor1, &anchor2, 0.0);
    
     prev_actor = box;
   }
 
-  Glib::RefPtr<Clutter::Rectangle> box = Clutter::Rectangle::create();
-  box->set_size(18, 5);
-  box->set_position(20 + 20 * numplanks, y);
-  box2d->add_actor(box);
-
-  box2d->set_child_property(box, "mode", (int)Clutter::Box2D::BOX2D_STATIC);
-
-  ClutterVertex anchor = { CLUTTER_UNITS_FROM_FLOAT (20 + 20 * numplanks),
-             CLUTTER_UNITS_FROM_FLOAT (y) };
-  box2d->add_revolute_joint2(prev_actor, box, &anchor);
-
   box2d->set_simulating();
 
   stage->show();

Modified: clutter-box2dmm/trunk/examples/pyramid/main.cc
==============================================================================
--- /clutter-box2dmm/trunk/examples/bridge/main.cc	(original)
+++ clutter-box2dmm/trunk/examples/pyramid/main.cc	Sun Aug 10 13:43:47 2008
@@ -50,12 +50,10 @@
     return -1;
   }
 
-  Clutter::Color stage_color(0x61, 0x64, 0x8c, 0xff);
   Glib::RefPtr<Clutter::Stage> stage = Clutter::Stage::get_default();
+  stage->set_color( Clutter::Color(0x00, 0x00, 0x00, 0xff) );
   stage->set_size(800, 600);
-
-  stage->set_title("Actors Test");
-  stage->set_color(stage_color);
+  stage->set_title("Clutter::Box2D Example");
 
 
   Glib::RefPtr<Clutter::Box2D::Box2D> box2d = Clutter::Box2D::Box2D::create();
@@ -64,43 +62,27 @@
 
   add_cage(box2d, true /* roof */);
 
-  int y = stage->get_height() / 2;
-  int numplanks = stage->get_width() / 20 - 2;
-  Glib::RefPtr<Clutter::Rectangle> rect = Clutter::Rectangle::create();
-  rect->set_size(18, 5);
-  rect->set_position(10, y);
-  box2d->add_actor(rect);
-
-  box2d->set_child_property(rect, "mode", (int)Clutter::Box2D::BOX2D_STATIC);  //TODO: Avoid the need for the int cast.
-
-  Glib::RefPtr<Clutter::Actor> prev_actor = rect;
+  const int pyramid_rows = (stage->get_width() / 64)-1;
 
-  for(int i = 0; i < numplanks; ++i)
+  for(int row = 0; row < pyramid_rows; ++row)
   {
-    Glib::RefPtr<Clutter::Rectangle> box = Clutter::Rectangle::create();
-    box->set_size(18, 5);
-    box->set_position(20 + 20 * i, y);
-    box2d->add_actor(box);
-
-    box2d->set_child_property(box, "manipulatable", true);
-    box2d->set_child_property(box, "mode", (int)Clutter::Box2D::BOX2D_DYNAMIC);
-
-    ClutterVertex anchor = { CLUTTER_UNITS_FROM_FLOAT (20 + 20 * i), CLUTTER_UNITS_FROM_FLOAT (y) };
-    box2d->add_revolute_joint2(prev_actor, box, &anchor);
-   
-    prev_actor = box;
-  }
+    const int count = pyramid_rows - row + 1;
+    const int y = 420 - (row + 1) * 120;
 
-  Glib::RefPtr<Clutter::Rectangle> box = Clutter::Rectangle::create();
-  box->set_size(18, 5);
-  box->set_position(20 + 20 * numplanks, y);
-  box2d->add_actor(box);
-
-  box2d->set_child_property(box, "mode", (int)Clutter::Box2D::BOX2D_STATIC);
-
-  ClutterVertex anchor = { CLUTTER_UNITS_FROM_FLOAT (20 + 20 * numplanks),
-             CLUTTER_UNITS_FROM_FLOAT (y) };
-  box2d->add_revolute_joint2(prev_actor, box, &anchor);
+    for(int i = 0; i < count; ++i)
+    {
+      const int x = (stage->get_width() / 2) - (count * 64 / 2) + i * 64;
+      
+      Glib::RefPtr<Clutter::Texture> texture = Clutter::Texture::create();
+      texture->set_from_file("redhand.png");
+      box2d->add_actor(texture);
+      texture->set_opacity(1.0 * 255);
+      texture->set_position(x, y);
+
+      box2d->set_child_property(texture, "manipulatable", true);
+      box2d->set_child_property(texture, "mode", (int)Clutter::Box2D::BOX2D_DYNAMIC);
+    }
+  }
 
   box2d->set_simulating();
 

Added: clutter-box2dmm/trunk/examples/pyramid/redhand.png
==============================================================================
Binary file. No diff available.

Modified: clutter-box2dmm/trunk/examples/slides/main.cc
==============================================================================
--- /clutter-box2dmm/trunk/examples/bridge/main.cc	(original)
+++ clutter-box2dmm/trunk/examples/slides/main.cc	Sun Aug 10 13:43:47 2008
@@ -50,58 +50,50 @@
     return -1;
   }
 
-  Clutter::Color stage_color(0x61, 0x64, 0x8c, 0xff);
   Glib::RefPtr<Clutter::Stage> stage = Clutter::Stage::get_default();
+  stage->set_color( Clutter::Color(0x00, 0x00, 0x00, 0xff) );
   stage->set_size(800, 600);
-
-  stage->set_title("Actors Test");
-  stage->set_color(stage_color);
+  stage->set_title("Clutter::Box2D Example");
 
 
   Glib::RefPtr<Clutter::Box2D::Box2D> box2d = Clutter::Box2D::Box2D::create();
   stage->add_actor(box2d);
   
 
-  add_cage(box2d, true /* roof */);
+  add_cage(box2d, false /* no roof */);
+
 
-  int y = stage->get_height() / 2;
-  int numplanks = stage->get_width() / 20 - 2;
-  Glib::RefPtr<Clutter::Rectangle> rect = Clutter::Rectangle::create();
-  rect->set_size(18, 5);
-  rect->set_position(10, y);
-  box2d->add_actor(rect);
+  Glib::RefPtr<Clutter::Rectangle> ground1 = Clutter::Rectangle::create();
+  ground1->set_size(256, 3);
+  ground1->set_position(0, 310);
+  ground1->set_rotation(Clutter::Z_AXIS, 30.0, 128, 16, 0);
+  box2d->add_actor(ground1);
+  box2d->set_child_property(ground1, "mode", (int)Clutter::Box2D::BOX2D_STATIC);  //TODO: Avoid the need for the int cast.
 
-  box2d->set_child_property(rect, "mode", (int)Clutter::Box2D::BOX2D_STATIC);  //TODO: Avoid the need for the int cast.
+  Glib::RefPtr<Clutter::Rectangle> ground2 = Clutter::Rectangle::create();
+  ground2->set_size(256, 3);
+  ground2->set_position(200, 200);
+  ground2->set_rotation(Clutter::Z_AXIS, -30.0, 0, 0, 0);
+  box2d->add_actor(ground2);
+  box2d->set_child_property(ground2, "mode", (int)Clutter::Box2D::BOX2D_STATIC);  //TODO: Avoid the need for the int cast.
 
-  Glib::RefPtr<Clutter::Actor> prev_actor = rect;
 
-  for(int i = 0; i < numplanks; ++i)
+  for(int i = 0; i < 20; ++i)
   {
-    Glib::RefPtr<Clutter::Rectangle> box = Clutter::Rectangle::create();
-    box->set_size(18, 5);
-    box->set_position(20 + 20 * i, y);
-    box2d->add_actor(box);
-
-    box2d->set_child_property(box, "manipulatable", true);
-    box2d->set_child_property(box, "mode", (int)Clutter::Box2D::BOX2D_DYNAMIC);
-
-    ClutterVertex anchor = { CLUTTER_UNITS_FROM_FLOAT (20 + 20 * i), CLUTTER_UNITS_FROM_FLOAT (y) };
-    box2d->add_revolute_joint2(prev_actor, box, &anchor);
-   
-    prev_actor = box;
-  }
+    const int x = g_random_int_range(0, stage->get_width());
+    const int y = g_random_int_range(-(stage->get_height()), 0);
 
-  Glib::RefPtr<Clutter::Rectangle> box = Clutter::Rectangle::create();
-  box->set_size(18, 5);
-  box->set_position(20 + 20 * numplanks, y);
-  box2d->add_actor(box);
-
-  box2d->set_child_property(box, "mode", (int)Clutter::Box2D::BOX2D_STATIC);
-
-  ClutterVertex anchor = { CLUTTER_UNITS_FROM_FLOAT (20 + 20 * numplanks),
-             CLUTTER_UNITS_FROM_FLOAT (y) };
-  box2d->add_revolute_joint2(prev_actor, box, &anchor);
+    Glib::RefPtr<Clutter::Texture> texture = Clutter::Texture::create();
+    texture->set_from_file("redhand.png");
+    box2d->add_actor(texture);
+    texture->set_opacity(1.0 * 255);
+    texture->set_position(x, y);
+
+    box2d->set_child_property(texture, "manipulatable", true);
+    box2d->set_child_property(texture, "mode", (int)Clutter::Box2D::BOX2D_DYNAMIC);
+  }
 
+  box2d->set_reactive();
   box2d->set_simulating();
 
   stage->show();

Added: clutter-box2dmm/trunk/examples/slides/redhand.png
==============================================================================
Binary file. No diff available.

Modified: clutter-box2dmm/trunk/examples/table/main.cc
==============================================================================
--- /clutter-box2dmm/trunk/examples/bridge/main.cc	(original)
+++ clutter-box2dmm/trunk/examples/table/main.cc	Sun Aug 10 13:43:47 2008
@@ -50,59 +50,33 @@
     return -1;
   }
 
-  Clutter::Color stage_color(0x61, 0x64, 0x8c, 0xff);
   Glib::RefPtr<Clutter::Stage> stage = Clutter::Stage::get_default();
+  stage->set_color( Clutter::Color(0x00, 0x00, 0x00, 0xff) );
   stage->set_size(800, 600);
-
-  stage->set_title("Actors Test");
-  stage->set_color(stage_color);
+  stage->set_title("Clutter::Box2D Example");
 
 
   Glib::RefPtr<Clutter::Box2D::Box2D> box2d = Clutter::Box2D::Box2D::create();
   stage->add_actor(box2d);
+  box2d->set_simulating();
+  box2d->property_gravity() = Clutter::Vertex(0, 0, 0);
   
-
   add_cage(box2d, true /* roof */);
 
-  int y = stage->get_height() / 2;
-  int numplanks = stage->get_width() / 20 - 2;
-  Glib::RefPtr<Clutter::Rectangle> rect = Clutter::Rectangle::create();
-  rect->set_size(18, 5);
-  rect->set_position(10, y);
-  box2d->add_actor(rect);
-
-  box2d->set_child_property(rect, "mode", (int)Clutter::Box2D::BOX2D_STATIC);  //TODO: Avoid the need for the int cast.
-
-  Glib::RefPtr<Clutter::Actor> prev_actor = rect;
-
-  for(int i = 0; i < numplanks; ++i)
+  for(int i = 42; i >= 0; --i)
   {
-    Glib::RefPtr<Clutter::Rectangle> box = Clutter::Rectangle::create();
-    box->set_size(18, 5);
-    box->set_position(20 + 20 * i, y);
-    box2d->add_actor(box);
-
-    box2d->set_child_property(box, "manipulatable", true);
-    box2d->set_child_property(box, "mode", (int)Clutter::Box2D::BOX2D_DYNAMIC);
-
-    ClutterVertex anchor = { CLUTTER_UNITS_FROM_FLOAT (20 + 20 * i), CLUTTER_UNITS_FROM_FLOAT (y) };
-    box2d->add_revolute_joint2(prev_actor, box, &anchor);
-   
-    prev_actor = box;
-  }
+    const int x = stage->get_width() / 2;
+    const int y = stage->get_height() * 0.8;
 
-  Glib::RefPtr<Clutter::Rectangle> box = Clutter::Rectangle::create();
-  box->set_size(18, 5);
-  box->set_position(20 + 20 * numplanks, y);
-  box2d->add_actor(box);
-
-  box2d->set_child_property(box, "mode", (int)Clutter::Box2D::BOX2D_STATIC);
-
-  ClutterVertex anchor = { CLUTTER_UNITS_FROM_FLOAT (20 + 20 * numplanks),
-             CLUTTER_UNITS_FROM_FLOAT (y) };
-  box2d->add_revolute_joint2(prev_actor, box, &anchor);
+    Glib::RefPtr<Clutter::Texture> texture = Clutter::Texture::create();
+    texture->set_from_file("redhand.png");
+    box2d->add_actor(texture);
+    texture->set_opacity(1.0 * 255);
+    texture->set_position(x, y);
 
-  box2d->set_simulating();
+    box2d->set_child_property(texture, "manipulatable", true);
+    box2d->set_child_property(texture, "mode", (int)Clutter::Box2D::BOX2D_DYNAMIC);
+  }
 
   stage->show();
 

Added: clutter-box2dmm/trunk/examples/table/redhand.png
==============================================================================
Binary file. No diff available.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]