[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [30150] branches/soc-2010-jwilkins/source/ blender: * bug fix: rake would jump when it was around 360==0 degrees

Jason Wilkins Jason.A.Wilkins at gmail.com
Fri Jul 9 13:41:27 CEST 2010


Revision: 30150
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=30150
Author:   jwilkins
Date:     2010-07-09 13:41:26 +0200 (Fri, 09 Jul 2010)

Log Message:
-----------
* bug fix: rake would jump when it was around 360==0 degrees
* also, changed method of smoothing rake to be more like smooth stroke
** may expose variables for smoothing rake later

Modified Paths:
--------------
    branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/paint_stroke.c
    branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/sculpt.c
    branches/soc-2010-jwilkins/source/blender/makesdna/DNA_brush_types.h

Modified: branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/paint_stroke.c
===================================================================
--- branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/paint_stroke.c	2010-07-09 10:14:12 UTC (rev 30149)
+++ branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/paint_stroke.c	2010-07-09 11:41:26 UTC (rev 30150)
@@ -550,17 +550,23 @@
 		const float min_alpha = 0.20f;
 		const float max_alpha = 0.80f;
 
-		/* keep track of mouse movement angle so rack can start at a sensible angle */
-		int dx = brush->last_x - x;
-		int dy = brush->last_y - y;
 
-		if (dx*dx + dy*dy > 100) {
-			/* only update if distance traveled is more than 10 pixels */
-			brush->last_angle = (brush->last_angle + atan2(dx, dy)) / 2;
-			brush->last_x = x;
-			brush->last_y = y;
-		} /* else, do not update last_x and last_y so that the distance can accumulate */
+		{
+			const float u = 0.5f;
+			const float v = 1 - u;
+			const float r = 20;
 
+			const float dx = brush->last_x - x;
+			const float dy = brush->last_y - y;
+
+			if (dx*dx + dy*dy >= r*r) {
+				brush->last_angle = atan2(dx, dy);
+
+				brush->last_x = u*brush->last_x + v*x;
+				brush->last_y = u*brush->last_y + v*y;
+			}
+		}
+
 		if(!sculpt_get_lock_brush_size(brush) && !(paint->flags & PAINT_SHOW_BRUSH)) 
 			return;
 

Modified: branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/sculpt.c
===================================================================
--- branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/sculpt.c	2010-07-09 10:14:12 UTC (rev 30149)
+++ branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/sculpt.c	2010-07-09 11:41:26 UTC (rev 30150)
@@ -218,7 +218,7 @@
 	int radial_symmetry_pass;
 	float symm_rot_mat[4][4];
 	float symm_rot_mat_inv[4][4];
-	int last_rake[2]; /* Last location of updating rake rotation */
+	float last_rake[2]; /* Last location of updating rake rotation */
 	int original;
 
 	float vertex_rotation;
@@ -2839,6 +2839,8 @@
 			cache->original = 1;
 
 	cache->special_rotation = (brush->flag & BRUSH_RAKE) ? brush->last_angle : 0;
+	//cache->last_rake[0] = brush->last_x;
+	//cache->last_rake[1] = brush->last_y;
 
 	cache->first_time= 1;
 
@@ -2949,22 +2951,21 @@
 		brush->draw_anchored = 1;
 	}
 	else if(brush->flag & BRUSH_RAKE) {
-		int update;
+		const float u = 0.5f;
+		const float v = 1 - u;
+		const float r = 20;
 
-		// XXX: the rake angle is calculated in the cursor drawing code now, probably no need to duplicate it here
+		const float dx = cache->last_rake[0] - cache->mouse[0];
+		const float dy = cache->last_rake[1] - cache->mouse[1];
 
-		dx = cache->last_rake[0] - cache->mouse[0];
-		dy = cache->last_rake[1] - cache->mouse[1];
+		if (cache->first_time) {
+			copy_v3_v3(cache->last_rake, cache->mouse);
+		}
+		else if (dx*dx + dy*dy >= r*r) {
+			cache->special_rotation = atan2(dx, dy);
 
-		/* To prevent jitter, only update the angle if the mouse has moved over 10 pixels */
-		update = dx*dx + dy*dy > 100;
-
-		if(update && !cache->first_time)
-			cache->special_rotation = (cache->special_rotation + atan2(dx, dy)) / 2;
-
-		if(update || cache->first_time) {
-			cache->last_rake[0] = cache->mouse[0];
-			cache->last_rake[1] = cache->mouse[1];
+			cache->last_rake[0] = u*cache->last_rake[0] + v*cache->mouse[0];
+			cache->last_rake[1] = u*cache->last_rake[1] + v*cache->mouse[1];
 		}
 	}
 

Modified: branches/soc-2010-jwilkins/source/blender/makesdna/DNA_brush_types.h
===================================================================
--- branches/soc-2010-jwilkins/source/blender/makesdna/DNA_brush_types.h	2010-07-09 10:14:12 UTC (rev 30149)
+++ branches/soc-2010-jwilkins/source/blender/makesdna/DNA_brush_types.h	2010-07-09 11:41:26 UTC (rev 30150)
@@ -93,7 +93,7 @@
 	float unprojected_radius;
 
 	/* record movement of mouse so that rake can start at an intuitive angle */
-	int last_x, last_y;
+	float last_x, last_y;
 	float last_angle;
 
 	int pad2;





More information about the Bf-blender-cvs mailing list