[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [28591] branches/render25/source/blender/ blenkernel/intern: division by zero fix

Joseph Eagar joeedh at gmail.com
Wed May 5 12:20:59 CEST 2010


Revision: 28591
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=28591
Author:   joeedh
Date:     2010-05-05 12:20:59 +0200 (Wed, 05 May 2010)

Log Message:
-----------
division by zero fix

Modified Paths:
--------------
    branches/render25/source/blender/blenkernel/intern/collision.c
    branches/render25/source/blender/blenkernel/intern/implicit.c

Modified: branches/render25/source/blender/blenkernel/intern/collision.c
===================================================================
--- branches/render25/source/blender/blenkernel/intern/collision.c	2010-05-05 06:38:49 UTC (rev 28590)
+++ branches/render25/source/blender/blenkernel/intern/collision.c	2010-05-05 10:20:59 UTC (rev 28591)
@@ -544,7 +544,7 @@
 			float magtangent = 0, repulse = 0, d = 0;
 			double impulse = 0.0;
 			float vrel_t_pre[3];
-			float temp[3];
+			float temp[3], spf;
 
 			// calculate tangential velocity
 			VECCOPY ( temp, collpair->normal );
@@ -582,10 +582,12 @@
 
 			// Apply repulse impulse if distance too short
 			// I_r = -min(dt*kd, m(0,1d/dt - v_n))
+			spf = (float)clmd->sim_parms->stepsPerFrame / clmd->sim_parms->timescale;
+
 			d = clmd->coll_parms->epsilon*8.0/9.0 + epsilon2*8.0/9.0 - collpair->distance;
-			if ( ( magrelVel < 0.1*d*clmd->sim_parms->stepsPerFrame ) && ( d > ALMOST_ZERO ) )
+			if ( ( magrelVel < 0.1*d*spf ) && ( d > ALMOST_ZERO ) )
 			{
-				repulse = MIN2 ( d*1.0/clmd->sim_parms->stepsPerFrame, 0.1*d*clmd->sim_parms->stepsPerFrame - magrelVel );
+				repulse = MIN2 ( d*1.0/spf, 0.1*d*spf - magrelVel );
 
 				// stay on the safe side and clamp repulse
 				if ( impulse > ALMOST_ZERO )

Modified: branches/render25/source/blender/blenkernel/intern/implicit.c
===================================================================
--- branches/render25/source/blender/blenkernel/intern/implicit.c	2010-05-05 06:38:49 UTC (rev 28590)
+++ branches/render25/source/blender/blenkernel/intern/implicit.c	2010-05-05 10:20:59 UTC (rev 28591)
@@ -1813,7 +1813,7 @@
 	Cloth *cloth = clmd->clothObject;
 	ClothVertex *verts = cloth->verts;
 	unsigned int numverts = cloth->numverts;
-	float dt = clmd->sim_parms->timescale / clmd->sim_parms->stepsPerFrame;
+	float dt = clmd->sim_parms->timescale / clmd->sim_parms->stepsPerFrame, spf = (float)clmd->sim_parms->stepsPerFrame / clmd->sim_parms->timescale;
 	Implicit_Data *id = cloth->implicit;
 	int result = 0;
 	
@@ -1861,10 +1861,6 @@
 
 		if(1)
 		{
-			float temp = clmd->sim_parms->stepsPerFrame;
-			/* not too nice hack, but collisions need this correction -jahka */
-			clmd->sim_parms->stepsPerFrame /= clmd->sim_parms->timescale;
-
 			// collisions 
 			// itstart();
 			
@@ -1880,7 +1876,7 @@
 				{
 					float vec[3], fac;
 
-					fac = 1.0 - pow(1.0 - verts[i].goal*clmd->sim_parms->goalspring, 1.0 / (float)(clmd->sim_parms->stepsPerFrame));
+					fac = 1.0 - pow(1.0 - verts[i].goal*clmd->sim_parms->goalspring, 1.0 / spf);
 
 					sub_v3_v3v3(vec, verts[i].xconst, verts[i].tx);
 					mul_v3_fl(vec, fac);
@@ -1911,12 +1907,9 @@
 				VECSUB(verts[i].tv, verts[i].tx, verts[i].txold);
 				VECCOPY(id->Xnew[i], verts[i].tx);
 				VECCOPY(id->Vnew[i], verts[i].tv);
-				mul_v3_fl(id->Vnew[i], ((float)clmd->sim_parms->stepsPerFrame)); // /clmd->sim_parms->timescale);
+				mul_v3_fl(id->Vnew[i], spf);
 			}
 			
-			/* restore original stepsPerFrame */
-			clmd->sim_parms->stepsPerFrame = temp;
-			
 			// X = Xnew;
 			cp_lfvector(id->X, id->Xnew, numverts);
 			





More information about the Bf-blender-cvs mailing list