Fixed floating point rounding error in goal velocity computation, pointed out my...
authorDaniel Genrich <daniel.genrich@gmx.net>
Tue, 18 Sep 2007 11:42:52 +0000 (11:42 +0000)
committerDaniel Genrich <daniel.genrich@gmx.net>
Tue, 18 Sep 2007 11:42:52 +0000 (11:42 +0000)
source/blender/blenkernel/intern/cloth.c
source/blender/blenkernel/intern/implicit.c

index 14370b59d68f54d07da227ca81f875c30845b5d9..40f3c9816a6a1b1fb3d62e2c321e3f010fb34cc2 100644 (file)
@@ -764,7 +764,7 @@ void clothModifier_do(ClothModifierData *clmd, Object *ob, DerivedMesh *dm,
                                        Mat4MulVecfl(ob->obmat, verts->xconst);
 
                                        /* Compute the vertices velocity. */
-                                       VECSUB (verts->v, verts->x, verts->xold);
+                                       VECSUB (verts->v, verts->xconst, verts->xold);
                                }
 
                                tstart();
index aa28f0a20869f9766d84327a40f793c7be079d0f..df5830f6a7721a26ac417155da23e9d540a237af 100644 (file)
@@ -736,7 +736,7 @@ int implicit_init (Object *ob, ClothModifierData *clmd)
        {
                id->A[i].r = id->A[i].c = id->dFdV[i].r = id->dFdV[i].c = id->dFdX[i].r = id->dFdX[i].c = id->P[i].c = id->P[i].r = id->Pinv[i].c = id->Pinv[i].r = id->bigI[i].c = id->bigI[i].r = i;
 
-               if(verts [i].flags & CVERT_FLAG_PINNED)
+               if(verts [i].goal >= SOFTGOALSNAP)
                {
                        id->S[pinned].pinned = 1;
                        id->S[pinned].c = id->S[pinned].r = i;
@@ -1199,8 +1199,9 @@ DO_INLINE void calc_spring_force(ClothModifierData *clmd, ClothSpring *s, lfVect
                        dfdx_spring_type1(dfdx, dir,length,L,k);
 
                        dfdv_damp(dfdv, dir,clmd->sim_parms.Cdis);      
-                                       
+                               
                        sub_fmatrix_fmatrix(dFdV[s->ij].m, dFdV[s->ij].m, dfdv);
+                       
                        sub_fmatrix_fmatrix(dFdV[s->kl].m, dFdV[s->kl].m, dfdv);
 
                        add_fmatrix_fmatrix(dFdV[s->matrix_index].m, dFdV[s->matrix_index].m, dfdv);    
@@ -1315,15 +1316,15 @@ void calc_force(ClothModifierData *clmd, lfVector *lF, lfVector *lX, lfVector *l
                                mul_fvector_S(tvect, tvect, time);
                                VECADD(tvect, tvect, verts[i].xold);
 
-                               VecSubf(auxvect, tvect, lX[i]);
+                               VECSUB(auxvect, tvect, lX[i]);
                                ks  = 1.0f/(1.0f- verts [i].goal*clmd->sim_parms.goalspring)-1.0f ;
                                VECADDS(lF[i], lF[i], auxvect, -ks);
 
-                               /* calulate damping forces generated by goals*/
+                               // calulate damping forces generated by goals                           
                                VECSUB(velgoal,verts[i].xold, verts[i].xconst);
                                kd =  clmd->sim_parms.goalfrict * 0.01f; // friction force scale taken from SB
                                VECSUBADDSS(lF[i], velgoal, kd, lV[i], kd);
-
+                               
                        }
                }       
        }
@@ -1404,6 +1405,7 @@ int implicit_solver (Object *ob, float frame, ClothModifierData *clmd, ListBase
                        if(verts [i].goal >= SOFTGOALSNAP)
                        {                       
                                VECSUB(id->V[i], verts[i].xconst, verts[i].xold);
+                               // VecMulf(id->V[i], 1.0 / dt);
                        }
                }       
        }
@@ -1413,15 +1415,30 @@ int implicit_solver (Object *ob, float frame, ClothModifierData *clmd, ListBase
                effectors= pdInitEffectors(ob,NULL);
                
                // calculate 
-               calc_force(clmd, id->F, id->X, id->V, id->dFdV, id->dFdX, effectors, step);     
+               calc_force(clmd, id->F, id->X, id->V, id->dFdV, id->dFdX, effectors, step );    
                simulate_implicit_euler(id->Vnew, id->X, id->V, id->F, id->dFdV, id->dFdX, dt, id->A, id->B, id->dV, id->S, id->z, id->olddV);
+               
                add_lfvector_lfvectorS(id->Xnew, id->X, id->Vnew, dt, numverts);
                
                // collisions 
                itstart();
+               
                // update verts to current positions
                for(i = 0; i < numverts; i++)
                {               
+                       if(clmd->sim_parms.flags & CSIMSETT_FLAG_GOAL) /* do goal stuff */
+                       {                       
+                               if(verts [i].goal >= SOFTGOALSNAP)
+                               {                       
+                                       float tvect[3] = {.0,.0,.0};
+                                       // VECSUB(tvect, id->Xnew[i], verts[i].xold);
+                                       mul_fvector_S(tvect, id->V[i], step+dt);
+                                       VECADD(tvect, tvect, verts[i].xold);
+                                       VECCOPY(id->Xnew[i], tvect);
+                               }
+                                       
+                       }
+                       
                        VECCOPY(verts[i].tx, id->Xnew[i]);
                        
                        VECSUB(verts[i].tv, verts[i].tx, verts[i].txold);
@@ -1433,7 +1450,6 @@ int implicit_solver (Object *ob, float frame, ClothModifierData *clmd, ListBase
                // copy corrected positions back to simulation
                for(i = 0; i < numverts; i++)
                {               
-                       // TODO: calculate v_n+1 from v_n+1/2
                        if(result)
                        {
                                VECADD(verts[i].tx, verts[i].txold, verts[i].tv);
@@ -1509,23 +1525,10 @@ void implicit_set_positions (ClothModifierData *clmd)
        ClothVertex *verts = cloth->verts;
        unsigned int numverts = cloth->numverts, i;
        Implicit_Data *id = cloth->implicit;
-       unsigned int pinned = 0;
-       
-       // reset pinned verts in S matrix to zero
-       // id->S[0].vcount = 0; id->S[0].scount = 0;
        
        for(i = 0; i < numverts; i++)
        {                               
                VECCOPY(id->X[i], verts[i].x);
                VECCOPY(id->V[i], verts[i].v);
-               /*
-               if(verts [i].flags & CVERT_FLAG_PINNED)
-               {
-                       id->S[pinned].pinned = 1;
-                       id->S[pinned].c = id->S[pinned].r = i;
-                       pinned++;
-               }
-               */
        }       
-       // id->S[0].vcount = pinned;
 }