I made multitude of fixes based on the comments provided online:
[blender.git] / source / blender / blenkernel / intern / effect.c
index ee46bef6038469de9756b98ba635e1b9681b1bb4..468f39bf731b214ec613ec089cb3e48a98c3e015 100644 (file)
@@ -241,6 +241,16 @@ static void precalculate_effector(EffectorCache *eff)
        }
        else if(eff->psys)
                psys_update_particle_tree(eff->psys, eff->scene->r.cfra);
+
+       /* Store object velocity */
+       if(eff->ob) {
+               float old_vel[3];
+
+               where_is_object_time(eff->scene, eff->ob, cfra - 1.0f);
+               copy_v3_v3(old_vel, eff->ob->obmat[3]); 
+               where_is_object_time(eff->scene, eff->ob, cfra);
+               sub_v3_v3v3(eff->velocity, eff->ob->obmat[3], old_vel);
+       }
 }
 static EffectorCache *new_effector_cache(Scene *scene, Object *ob, ParticleSystem *psys, PartDeflect *pd)
 {
@@ -580,16 +590,16 @@ int closest_point_on_surface(SurfaceModifierData *surmd, float *co, float *surfa
        BLI_bvhtree_find_nearest(surmd->bvhtree->tree, co, &nearest, surmd->bvhtree->nearest_callback, surmd->bvhtree);
 
        if(nearest.index != -1) {
-               VECCOPY(surface_co, nearest.co);
+               copy_v3_v3(surface_co, nearest.co);
 
                if(surface_nor) {
-                       VECCOPY(surface_nor, nearest.no);
+                       copy_v3_v3(surface_nor, nearest.no);
                }
 
                if(surface_vel) {
                        MFace *mface = CDDM_get_face(surmd->dm, nearest.index);
                        
-                       VECCOPY(surface_vel, surmd->v[mface->v1].co);
+                       copy_v3_v3(surface_vel, surmd->v[mface->v1].co);
                        add_v3_v3(surface_vel, surmd->v[mface->v2].co);
                        add_v3_v3(surface_vel, surmd->v[mface->v3].co);
                        if(mface->v4)
@@ -680,10 +690,6 @@ int get_effector_data(EffectorCache *eff, EffectorData *efd, EffectedPoint *poin
                Object *ob = eff->ob;
                Object obcopy = *ob;
 
-               /* XXX this is not thread-safe, but used from multiple threads by
-                  particle system */
-               where_is_object_time(eff->scene, ob, cfra);
-
                /* use z-axis as normal*/
                normalize_v3_v3(efd->nor, ob->obmat[2]);
 
@@ -699,16 +705,11 @@ int get_effector_data(EffectorCache *eff, EffectorData *efd, EffectedPoint *poin
                                sub_v3_v3v3(efd->loc, point->loc, translate);
                }
                else {
-                       VECCOPY(efd->loc, ob->obmat[3]);
+                       copy_v3_v3(efd->loc, ob->obmat[3]);
                }
 
-               if(real_velocity) {
-                       VECCOPY(efd->vel, ob->obmat[3]);
-
-                       where_is_object_time(eff->scene, ob, cfra - 1.0f);
-
-                       sub_v3_v3v3(efd->vel, efd->vel, ob->obmat[3]);
-               }
+               if(real_velocity)
+                       copy_v3_v3(efd->vel, eff->velocity);
 
                *eff->ob = obcopy;
 
@@ -726,8 +727,8 @@ int get_effector_data(EffectorCache *eff, EffectorData *efd, EffectedPoint *poin
                        mul_v3_fl(efd->vec_to_point, (efd->distance-eff->pd->f_size)/efd->distance);
 
                if(eff->flag & PE_USE_NORMAL_DATA) {
-                       VECCOPY(efd->vec_to_point2, efd->vec_to_point);
-                       VECCOPY(efd->nor2, efd->nor);
+                       copy_v3_v3(efd->vec_to_point2, efd->vec_to_point);
+                       copy_v3_v3(efd->nor2, efd->nor);
                }
                else {
                        /* for some effectors we need the object center every time */
@@ -799,7 +800,7 @@ static void do_texture_effector(EffectorCache *eff, EffectorData *efd, EffectedP
 
        strength= eff->pd->f_strength * efd->falloff;
 
-       VECCOPY(tex_co,point->loc);
+       copy_v3_v3(tex_co,point->loc);
 
        if(eff->pd->flag & PFIELD_TEX_2D) {
                float fac=-dot_v3v3(tex_co, efd->nor);
@@ -877,11 +878,11 @@ static void do_physical_effector(EffectorCache *eff, EffectorData *efd, Effected
                        damp += wind_func(rng, noise_factor);
        }
 
-       VECCOPY(force, efd->vec_to_point);
+       copy_v3_v3(force, efd->vec_to_point);
 
        switch(pd->forcefield){
                case PFIELD_WIND:
-                       VECCOPY(force, efd->nor);
+                       copy_v3_v3(force, efd->nor);
                        mul_v3_fl(force, strength * efd->falloff);
                        break;
                case PFIELD_FORCE:
@@ -943,7 +944,7 @@ static void do_physical_effector(EffectorCache *eff, EffectorData *efd, Effected
                        return;
                case PFIELD_TURBULENCE:
                        if(pd->flag & PFIELD_GLOBAL_CO) {
-                               VECCOPY(temp, point->loc);
+                               copy_v3_v3(temp, point->loc);
                        }
                        else {
                                VECADD(temp, efd->vec_to_point2, efd->nor2);
@@ -954,7 +955,7 @@ static void do_physical_effector(EffectorCache *eff, EffectorData *efd, Effected
                        mul_v3_fl(force, strength * efd->falloff);
                        break;
                case PFIELD_DRAG:
-                       VECCOPY(force, point->vel);
+                       copy_v3_v3(force, point->vel);
                        fac = normalize_v3(force) * point->vel_to_sec;
 
                        strength = MIN2(strength, 2.0f);
@@ -1038,7 +1039,7 @@ void pdDoEffectors(ListBase *effectors, ListBase *colliders, EffectorWeights *we
                                        do_texture_effector(eff, &efd, point, force);
                                else {
                                        float temp1[3]={0,0,0}, temp2[3];
-                                       VECCOPY(temp1, force);
+                                       copy_v3_v3(temp1, force);
 
                                        do_physical_effector(eff, &efd, point, force);