Fix for [#17561] when i try to change the particle to hair I cant choose group or...
authorJanne Karhu <jhkarh@gmail.com>
Tue, 16 Sep 2008 21:16:32 +0000 (21:16 +0000)
committerJanne Karhu <jhkarh@gmail.com>
Tue, 16 Sep 2008 21:16:32 +0000 (21:16 +0000)
-Partly reverted Genscher's previous fix on the issue and added the idea he had as a special case

source/blender/blenkernel/intern/particle.c

index c9d16c0017fbbce553a67745a9e594251b064f27..33af603751960b3f2f6fe9e82d64053231b28e7a 100644 (file)
@@ -3850,7 +3850,7 @@ void psys_get_dupli_texture(Object *ob, ParticleSettings *part, ParticleSystemMo
 
 void psys_get_dupli_path_transform(Object *ob, ParticleSystem *psys, ParticleSystemModifierData *psmd, ParticleData *pa, ChildParticle *cpa, ParticleCacheKey *cache, float mat[][4], float *scale)
 {
-       float loc[3], nor[3], vec[3], len, obrotmat[4][4], qmat[4][4];
+       float loc[3], nor[3], vec[3], side[3], len, obrotmat[4][4], qmat[4][4];
        float xvec[3] = {-1.0, 0.0, 0.0}, q[4];
 
        VecSubf(vec, (cache+cache->steps-1)->co, cache->co);
@@ -3875,9 +3875,27 @@ void psys_get_dupli_path_transform(Object *ob, ParticleSystem *psys, ParticleSys
                Mat4MulMat4(mat, obrotmat, qmat);
        }
        else {
-               Normalize(nor);
-               Mat4One(mat);
-               VECCOPY(mat[2], nor); // mat[2] is normal/direction
+               /* make sure that we get a proper side vector */
+               if(fabs(Inpf(nor,vec))>0.999999) {
+                       if(fabs(Inpf(nor,xvec))>0.999999) {
+                               nor[0] = 0.0f;
+                               nor[1] = 1.0f;
+                               nor[2] = 0.0f;
+                       }
+                       else {
+                               nor[0] = 1.0f;
+                               nor[1] = 0.0f;
+                               nor[2] = 0.0f;
+                       }
+               }
+               Crossf(side, nor, vec);
+               Normalize(side);
+               Crossf(nor, vec, side);
+
+               Mat4One(mat);
+               VECCOPY(mat[0], vec);
+               VECCOPY(mat[1], side);
+               VECCOPY(mat[2], nor);
        }
 
        *scale= len;