use math vector init functions

This commit is contained in:
Campbell Barton
2012-07-17 12:05:15 +00:00
parent e35d3083ec
commit 6f0950a1f4
3 changed files with 17 additions and 19 deletions

View File

@@ -2441,7 +2441,8 @@ static void sph_particle_courant(SPHData *sphdata, SPHRangeData *pfr)
int i;
float flow[3], offset[3], dist;
flow[0] = flow[1] = flow[2] = 0.0f;
zero_v3(flow);
dist = 0.0f;
if (pfr->tot_neighbors > 0) {
pa = pfr->pa;
@@ -2733,9 +2734,8 @@ static void basic_rotate(ParticleSettings *part, ParticleData *pa, float dfra, f
{
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;
pa->state.rot[1]=pa->state.rot[2]=pa->state.rot[3]=0;
if ((part->flag & PART_ROTATIONS) == 0) {
unit_qt(pa->state.rot);
return;
}
@@ -2747,8 +2747,9 @@ static void basic_rotate(ParticleSettings *part, ParticleData *pa, float dfra, f
float len2 = len_v3(pa->state.vel);
float vec[3];
if (len1==0.0f || len2==0.0f)
pa->state.ave[0] = pa->state.ave[1] = pa->state.ave[2] = 0.0f;
if (len1 == 0.0f || len2 == 0.0f) {
zero_v3(pa->state.ave);
}
else {
cross_v3_v3v3(pa->state.ave, pa->prev_state.vel, pa->state.vel);
normalize_v3(pa->state.ave);
@@ -2761,9 +2762,8 @@ static void basic_rotate(ParticleSettings *part, ParticleData *pa, float dfra, f
}
rotfac = len_v3(pa->state.ave);
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;
if (rotfac == 0.0f || (part->flag & PART_ROT_DYN)==0 || extrotfac == 0.0f) {
unit_qt(rot1);
}
else {
axis_angle_to_quat(rot1,pa->state.ave,rotfac*dtime);
@@ -3750,8 +3750,10 @@ static void save_hair(ParticleSimulationData *sim, float UNUSED(cfra))
pa->totkey++;
/* root is always in the origin of hair space so we set it to be so after the last key is saved*/
if (pa->totkey == psys->part->hair_step + 1)
root->co[0] = root->co[1] = root->co[2] = 0.0f;
if (pa->totkey == psys->part->hair_step + 1) {
zero_v3(root->co);
}
}
}
@@ -4130,9 +4132,8 @@ static void particles_fluid_step(ParticleSimulationData *sim, int UNUSED(cfra))
pa->state.vel[j] = wrf;
}
pa->state.ave[0] = pa->state.ave[1] = pa->state.ave[2] = 0.0f;
pa->state.rot[0] = 1.0;
pa->state.rot[1] = pa->state.rot[2] = pa->state.rot[3] = 0.0;
zero_v3(pa->state.ave);
unit_qt(pa->state.rot);
pa->time = 1.f;
pa->dietime = sim->scene->r.efra + 1;

View File

@@ -326,8 +326,7 @@ static void ptcache_particle_read(int index, void *psys_v, void **data, float cf
/* default to no rotation */
if (data[BPHYS_DATA_LOCATION] && !data[BPHYS_DATA_ROTATION]) {
pa->state.rot[0]=1.0f;
pa->state.rot[1]=pa->state.rot[2]=pa->state.rot[3]=0;
unit_qt(pa->state.rot);
}
}
static void ptcache_particle_interpolate(int index, void *psys_v, void **data, float cfra, float cfra1, float cfra2, float *old_data)

View File

@@ -238,8 +238,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
/* TODO: incremental rotations somehow */
if (state.vel[axis] < -0.9999f || state.vel[axis] > 0.9999f) {
state.rot[0] = 1;
state.rot[1] = state.rot[2] = state.rot[3] = 0.0f;
unit_qt(state.rot);
}
else {
float temp[3] = {0.0f, 0.0f, 0.0f};
@@ -250,7 +249,6 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
/* state.vel[axis] is the only component surviving from a dot product with the axis */
axis_angle_to_quat(state.rot, cross, saacos(state.vel[axis]));
}
}
else {
state.time = -1.0;