From 666667bd8360b1a4d3f3a63a999f67bcf4153a2b Mon Sep 17 00:00:00 2001 From: Lukas Toenne Date: Mon, 28 May 2012 16:58:12 +0000 Subject: [PATCH] Fix #29846, Dynamic rotation of particles not affected by forcefields 2.61 64 bit. Patch by Arno Mayrhofer (azrael3000). Minor fix by me to initialize the effector point angular velocity vector correctly. --- source/blender/blenkernel/intern/effect.c | 1 + source/blender/blenkernel/intern/particle_system.c | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/source/blender/blenkernel/intern/effect.c b/source/blender/blenkernel/intern/effect.c index 1d109d5f616..eb84f4ae9c0 100644 --- a/source/blender/blenkernel/intern/effect.c +++ b/source/blender/blenkernel/intern/effect.c @@ -929,6 +929,7 @@ static void do_physical_effector(EffectorCache *eff, EffectorData *efd, Effected } } + zero_v3(point->ave); if (pd->flag & PFIELD_DO_ROTATION && point->ave && point->rot) { float xvec[3] = {1.0f, 0.0f, 0.0f}; float dave[3]; diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c index fa47600deb2..cdedd818b43 100644 --- a/source/blender/blenkernel/intern/particle_system.c +++ b/source/blender/blenkernel/intern/particle_system.c @@ -2673,6 +2673,9 @@ static void basic_force_cb(void *efdata_v, ParticleKey *state, float *force, flo force[1] += (BLI_frand()-0.5f) * part->brownfac; force[2] += (BLI_frand()-0.5f) * part->brownfac; } + + if(part->flag & PART_ROT_DYN && epoint.ave) + copy_v3_v3(pa->state.ave, epoint.ave); } /* gathers all forces that effect particles and calculates a new state for the particle */ static void basic_integrate(ParticleSimulationData *sim, int p, float dfra, float cfra) @@ -2730,7 +2733,7 @@ static void basic_integrate(ParticleSimulationData *sim, int p, float dfra, floa } static void basic_rotate(ParticleSettings *part, ParticleData *pa, float dfra, float timestep) { - float rotfac, rot1[4], rot2[4]={1.0,0.0,0.0,0.0}, dtime=dfra*timestep; + float rotfac, rot1[4], rot2[4]={1.0,0.0,0.0,0.0}, dtime=dfra*timestep, extrotfac; if ((part->flag & PART_ROTATIONS)==0) { pa->state.rot[0]=1.0f; @@ -2738,7 +2741,9 @@ static void basic_rotate(ParticleSettings *part, ParticleData *pa, float dfra, f return; } - if ((part->flag & PART_ROT_DYN)==0 && ELEM3(part->avemode, PART_AVE_VELOCITY, PART_AVE_HORIZONTAL, PART_AVE_VERTICAL)) { + extrotfac = len_v3(pa->state.ave); + + if ((part->flag & PART_ROT_DYN) && ELEM3(part->avemode, PART_AVE_VELOCITY, PART_AVE_HORIZONTAL, PART_AVE_VERTICAL)) { float angle; float len1 = len_v3(pa->prev_state.vel); float len2 = len_v3(pa->state.vel); @@ -2758,7 +2763,7 @@ static void basic_rotate(ParticleSettings *part, ParticleData *pa, float dfra, f } rotfac = len_v3(pa->state.ave); - if (rotfac == 0.0f) { /* unit_qt(in VecRotToQuat) doesn't give unit quat [1,0,0,0]?? */ + if (rotfac == 0.0f || (part->flag & PART_ROT_DYN)==0 || extrotfac == 0.0f) { /* unit_qt(in VecRotToQuat) doesn't give unit quat [1,0,0,0]?? */ rot1[0]=1.0f; rot1[1]=rot1[2]=rot1[3]=0; }