Cloth: fixed completely useless/wrong friction force; changed some initial settings
authorDaniel Genrich <daniel.genrich@gmx.net>
Wed, 27 Feb 2008 03:23:17 +0000 (03:23 +0000)
committerDaniel Genrich <daniel.genrich@gmx.net>
Wed, 27 Feb 2008 03:23:17 +0000 (03:23 +0000)
source/blender/blenkernel/intern/cloth.c
source/blender/blenkernel/intern/collision.c
source/blender/src/buttons_object.c

index 0e97a5fe9efc889cba8b9d4d0c0a4ff2fd110acd..b1849f8b69347d30b76829d23888e5a13def05eb 100644 (file)
@@ -184,7 +184,7 @@ void cloth_init ( ClothModifierData *clmd )
        clmd->sim_parms->maxgoal = 1.0f;
        clmd->sim_parms->mingoal = 0.0f;
        clmd->sim_parms->defgoal = 0.0f;
        clmd->sim_parms->maxgoal = 1.0f;
        clmd->sim_parms->mingoal = 0.0f;
        clmd->sim_parms->defgoal = 0.0f;
-       clmd->sim_parms->goalspring = 10.0f;
+       clmd->sim_parms->goalspring = 1.0f;
        clmd->sim_parms->goalfrict = 5.0f;
 }
 
        clmd->sim_parms->goalfrict = 5.0f;
 }
 
index 793a49734755bb323a01b70527bc0d23b1390521..6ef6758cab671acf407e8ac77fe9a8e0fb1a1fe8 100644 (file)
@@ -492,33 +492,27 @@ int cloth_collision_response_static(ClothModifierData *clmd, CollisionModifierDa
                if(magrelVel < -ALMOST_ZERO) 
                {
                        // Calculate Impulse magnitude to stop all motion in normal direction.
                if(magrelVel < -ALMOST_ZERO) 
                {
                        // Calculate Impulse magnitude to stop all motion in normal direction.
-                       float tangential[3], magtangent;
+                       float magtangent;
                        double impulse = 0.0;
                        float vrel_t_pre[3];
                        double impulse = 0.0;
                        float vrel_t_pre[3];
-                       float vrel_t[3], temp[3];
+                       float temp[3];
                        
                        // calculate tangential velocity
                        VECCOPY(temp, collpair->normal);
                        VecMulf(temp, magrelVel);
                        VECSUB(vrel_t_pre, relativeVelocity, temp);
                        
                        
                        // calculate tangential velocity
                        VECCOPY(temp, collpair->normal);
                        VecMulf(temp, magrelVel);
                        VECSUB(vrel_t_pre, relativeVelocity, temp);
                        
-                       VECCOPY(vrel_t, vrel_t_pre);
-                       
-                       VecMulf(vrel_t, MAX2(1.0 - (clmd->coll_parms->friction * magrelVel / sqrt(INPR(vrel_t_pre,vrel_t_pre))), 0.0));
-                       
-                       VECSUB(tangential, vrel_t_pre, vrel_t);
-                       VecMulf(tangential, 0.5);
-                       
-                       magtangent = INPR(tangential, tangential);
+                       magtangent = INPR(vrel_t_pre,vrel_t_pre) - MIN2(clmd->coll_parms->friction * 0.01 * magrelVel,INPR(vrel_t_pre,vrel_t_pre));
                        
                        // Apply friction impulse.
                        if (magtangent > ALMOST_ZERO) 
                        
                        // Apply friction impulse.
                        if (magtangent > ALMOST_ZERO) 
-                       {
-                               impulse = magtangent / ( 1.0 + w1*w1 + w2*w2 + w3*w3);
-                               magtangent = sqrt(magtangent);
-                               VECADDMUL(cloth1->verts[collpair->ap1].impulse, tangential, w1 * impulse/magtangent);
-                               VECADDMUL(cloth1->verts[collpair->ap2].impulse, tangential, w2 * impulse/magtangent);
-                               VECADDMUL(cloth1->verts[collpair->ap3].impulse, tangential, w3 * impulse/magtangent);
+                       {       
+                               Normalize(vrel_t_pre);
+
+                               impulse = -2.0 * magtangent / ( 1.0 + w1*w1 + w2*w2 + w3*w3);
+                               VECADDMUL(cloth1->verts[collpair->ap1].impulse, vrel_t_pre, w1 * impulse);
+                               VECADDMUL(cloth1->verts[collpair->ap2].impulse, vrel_t_pre, w2 * impulse);
+                               VECADDMUL(cloth1->verts[collpair->ap3].impulse, vrel_t_pre, w3 * impulse);
                        }
                        
 
                        }
                        
 
index 54c592173ce95c3c61a1a6ce4ebcb2d449d39f45..da06351404ec9203050f29ad1eaf1cfa8f6b6fb4 100644 (file)
@@ -5221,7 +5221,7 @@ static void object_panel_cloth(Object *ob)
                                MEM_freeN (clvg2);
                        }
                        
                                MEM_freeN (clvg2);
                        }
                        
-                       uiDefButF(block, NUM, B_CLOTH_RENEW, "Pin Stiff:", 10,50,150,20, &clmd->sim_parms->goalspring, 0.0, 500.0, 10, 0, "Pin (vertex target position) spring stiffness");
+                       uiDefButF(block, NUM, B_CLOTH_RENEW, "Pin Stiff:", 10,50,150,20, &clmd->sim_parms->goalspring, 0.0, 50.0, 50, 0, "Pin (vertex target position) spring stiffness");
                        uiDefBut(block, LABEL, 0, "",160,50,150,20, NULL, 0.0, 0, 0, 0, "");    
                        // uiDefButI(block, NUM, B_CLOTH_RENEW, "Pin Damp:", 160,50,150,20, &clmd->sim_parms->goalfrict, 1.0, 100.0, 10, 0, "Pined damping (higher = doesn't oszilate so much)");
                        /*
                        uiDefBut(block, LABEL, 0, "",160,50,150,20, NULL, 0.0, 0, 0, 0, "");    
                        // uiDefButI(block, NUM, B_CLOTH_RENEW, "Pin Damp:", 160,50,150,20, &clmd->sim_parms->goalfrict, 1.0, 100.0, 10, 0, "Pined damping (higher = doesn't oszilate so much)");
                        /*
@@ -5335,7 +5335,7 @@ static void object_panel_cloth_II(Object *ob)
                {
                        uiDefButF(block, NUM, REDRAWBUTSOBJECT, "Min Distance:",           160,60,150,20, &clmd->coll_parms->epsilon, 0.001f, 1.0, 0.01f, 0, "Minimum distance between collision objects before collision response takes in, can be changed for each frame");
                        uiDefButS(block, NUM, REDRAWBUTSOBJECT, "Collision Quality:",      10,40,150,20, &clmd->coll_parms->loop_count, 1.0, 20.0, 1.0, 0, "How many collision iterations should be done. (higher = better = slower), can be changed for each frame");
                {
                        uiDefButF(block, NUM, REDRAWBUTSOBJECT, "Min Distance:",           160,60,150,20, &clmd->coll_parms->epsilon, 0.001f, 1.0, 0.01f, 0, "Minimum distance between collision objects before collision response takes in, can be changed for each frame");
                        uiDefButS(block, NUM, REDRAWBUTSOBJECT, "Collision Quality:",      10,40,150,20, &clmd->coll_parms->loop_count, 1.0, 20.0, 1.0, 0, "How many collision iterations should be done. (higher = better = slower), can be changed for each frame");
-                       uiDefButF(block, NUM, REDRAWBUTSOBJECT, "Friction:",       160,40,150,20, &clmd->coll_parms->friction, 0.0, 10.0, 1.0, 0, "Friction force if a collision happened (high=slower movement when collided)");
+                       uiDefButF(block, NUM, REDRAWBUTSOBJECT, "Friction:",       160,40,150,20, &clmd->coll_parms->friction, 0.0, 80.0, 1.0, 0, "Friction force if a collision happened (0=movement not changed, 100=no movement left)");
                        
                        uiDefButBitI(block, TOG, CLOTH_COLLSETTINGS_FLAG_SELF, B_CLOTH_RENEW, "Enable selfcollisions",  10,20,150,20, &clmd->coll_parms->flags, 0, 0, 0, 0, "Enable selfcollisions with this object");
                        if (clmd->coll_parms->flags & CLOTH_COLLSETTINGS_FLAG_SELF)     
                        
                        uiDefButBitI(block, TOG, CLOTH_COLLSETTINGS_FLAG_SELF, B_CLOTH_RENEW, "Enable selfcollisions",  10,20,150,20, &clmd->coll_parms->flags, 0, 0, 0, 0, "Enable selfcollisions with this object");
                        if (clmd->coll_parms->flags & CLOTH_COLLSETTINGS_FLAG_SELF)