[cairo-commit] cairo-demo/sproing ChangeLog, 1.7, 1.8 sproing.c, 1.6, 1.7

Kristian Hogsberg commit at pdx.freedesktop.org
Mon Mar 28 16:39:05 PST 2005


Committed by: krh

Update of /cvs/cairo/cairo-demo/sproing
In directory gabe:/tmp/cvs-serv19705

Modified Files:
	ChangeLog sproing.c 
Log Message:
2005-03-28  Kristian Høgsberg  <krh at redhat.com>

        * sproing.c (model_step_object): Add simplistic collision
        detection experiment.



Index: ChangeLog
===================================================================
RCS file: /cvs/cairo/cairo-demo/sproing/ChangeLog,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- ChangeLog	28 Mar 2005 20:29:14 -0000	1.7
+++ ChangeLog	29 Mar 2005 00:39:03 -0000	1.8
@@ -1,3 +1,8 @@
+2005-03-28  Kristian Høgsberg  <krh at redhat.com>
+
+	* sproing.c (model_step_object): Add simplistic collision
+	detection experiment.
+
 2005-03-28  Carl Worth  <cworth at cworth.org>
 
 	* sproing.c: (model_step_object), (sproing_button_release_event),

Index: sproing.c
===================================================================
RCS file: /cvs/cairo/cairo-demo/sproing/sproing.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- sproing.c	28 Mar 2005 20:29:15 -0000	1.6
+++ sproing.c	29 Mar 2005 00:39:03 -0000	1.7
@@ -23,6 +23,9 @@
 #define DEFAULT_SPRING_K 15.0
 #define DEFAULT_FRICTION  4.2
 
+#define WALL_X 400
+#define WALL_Y 300
+
 struct _Spring {
   Object *a;
   Object *b;
@@ -269,6 +272,16 @@
 
     object->position.x += object->velocity.x;
     object->position.y += object->velocity.y;
+
+    if (object->position.x > WALL_X) {
+      object->position.x = WALL_X - (object->position.x - WALL_X) * 0.7;
+      object->velocity.x = -object->velocity.x * 0.3;
+    }
+
+    if (object->position.y > WALL_Y) {
+      object->position.y = WALL_Y - (object->position.y - WALL_Y) * 0.7;
+      object->velocity.y = -object->velocity.y * 0.3;
+    }
   }
 
   object->force.x = 0.0;
@@ -499,6 +512,21 @@
 }
 #endif
 
+static void
+draw_wall (GtkWidget *widget)
+{
+  cairo_t *cr;
+  
+  cr = begin_paint (widget->window);
+
+  cairo_move_to (cr, 0, WALL_Y);
+  cairo_line_to (cr, WALL_X, WALL_Y);
+  cairo_line_to (cr, WALL_X, 0);
+  cairo_stroke (cr);
+
+  end_paint (cr);
+}
+
 static gboolean
 sproing_expose_event (GtkWidget      *widget,
 		      GdkEventExpose *event,
@@ -524,7 +552,9 @@
 	       model->objects[i].position.y, model->objects[i].theta, &blue);
   }
 #endif
-  
+
+  draw_wall (widget);
+
   return TRUE;
 }
 




More information about the cairo-commit mailing list