Compressed the two particles effectors loop into one. It was rather stupid of me to do it as two at first, but it was the first thing that came to mind. Fixed now, so it will calculate much faster.

This commit is contained in:
Martin Poirier 2004-07-10 09:17:25 +00:00
parent 6c15a98e76
commit 2a8abfc143

@ -369,11 +369,21 @@ static float linetriangle(float p1[3], float p2[3], float v0[3], float v1[3], fl
return t;
}
static void get_vortex(float opco[], float opno[], float speed[], float cur_time, unsigned int par_layer)
static void get_effector(float opco[], float force[], float speed[], float cur_time, unsigned int par_layer)
{
/* Particle vortex code */
/* Modifies the force on a particle according to its */
/* distance from mesh vertices set to attract / repel */
/*
Particle effector field code
Modifies the force on a particle according to its
relation with the effector object
Different kind of effectors include:
Forcefields: Gravity-like attractor
(force power is related to the inverse of distance to the power of a falloff value)
Vortex fields: swirling effectors
(particles rotate around Z-axis of the object. otherwise, same relation as)
(Forcefields, but this is not done through a force/acceleration)
*/
Object *ob;
Base *base;
float vect_to_vert[3];
@ -383,71 +393,6 @@ static void get_vortex(float opco[], float opno[], float speed[], float cur_time
float force_val, ffall_val;
short cur_frame;
/* Cycle through objects, get total of (1/(vortex_strength * dist^vortex_power)) */
/* Check for min distance here? */
base = G.scene->base.first;
while (base) {
if(base->lay & par_layer) {
ob= base->object;
if(ob->pd && ob->pd->forcefield & 2) {
/* Need to set r.cfra for paths (investigate, ton) */
cur_frame = G.scene->r.cfra;
G.scene->r.cfra = (short)cur_time;
where_is_object_time(ob, cur_time);
G.scene->r.cfra = cur_frame;
/* only use center of object */
obloc[0] = ob->obmat[3][0];
obloc[1] = ob->obmat[3][1];
obloc[2] = ob->obmat[3][2];
/* Get IPO force strength and fall off values here */
if (has_ipo_code(ob->ipo, OB_PD_FSTR))
force_val = IPO_GetFloatValue(ob->ipo, OB_PD_FSTR, cur_time);
else
force_val = ob->pd->f_strength;
if (has_ipo_code(ob->ipo, OB_PD_FFALL))
ffall_val = IPO_GetFloatValue(ob->ipo, OB_PD_FFALL, cur_time);
else
ffall_val = ob->pd->f_power;
/* Now calculate the vortex force */
VecSubf(vect_to_vert, obloc, opco);
distance = Normalise(vect_to_vert);
Crossf(force_vec, ob->obmat[2], vect_to_vert);
Normalise(force_vec);
/* Limit minimum distance to vertex so that */
/* the force is not too big */
if (distance < 0.001) distance = 0.001;
f_force = (force_val)*(1/(100 * pow((double)distance, (double)ffall_val)));
speed[0] -= (force_vec[0] * f_force );
speed[1] -= (force_vec[1] * f_force );
speed[2] -= (force_vec[2] * f_force );
}
}
base = base->next;
}
}
static void get_forcefield(float opco[], float force[], float cur_time, unsigned int par_layer)
{
/* Particle gravity code */
/* Modifies the force on a particle according to its */
/* distance from mesh vertices set to attract / repel */
Object *ob;
Base *base;
float vect_to_vert[3];
float f_force, distance;
float obloc[3];
float force_val, ffall_val;
short cur_frame;
/* Cycle through objects, get total of (1/(gravity_strength * dist^gravity_power)) */
/* Check for min distance here? */
base = G.scene->base.first;
@ -491,6 +436,46 @@ static void get_forcefield(float opco[], float force[], float cur_time, unsigned
force[2] += (vect_to_vert[2] * f_force );
}
if(ob->pd && ob->pd->forcefield & 2) {
/* Need to set r.cfra for paths (investigate, ton) */
cur_frame = G.scene->r.cfra;
G.scene->r.cfra = (short)cur_time;
where_is_object_time(ob, cur_time);
G.scene->r.cfra = cur_frame;
/* only use center of object */
obloc[0] = ob->obmat[3][0];
obloc[1] = ob->obmat[3][1];
obloc[2] = ob->obmat[3][2];
/* Get IPO force strength and fall off values here */
if (has_ipo_code(ob->ipo, OB_PD_FSTR))
force_val = IPO_GetFloatValue(ob->ipo, OB_PD_FSTR, cur_time);
else
force_val = ob->pd->f_strength;
if (has_ipo_code(ob->ipo, OB_PD_FFALL))
ffall_val = IPO_GetFloatValue(ob->ipo, OB_PD_FFALL, cur_time);
else
ffall_val = ob->pd->f_power;
/* Now calculate the vortex force */
VecSubf(vect_to_vert, obloc, opco);
distance = Normalise(vect_to_vert);
Crossf(force_vec, ob->obmat[2], vect_to_vert);
Normalise(force_vec);
/* Limit minimum distance to vertex so that */
/* the force is not too big */
if (distance < 0.001) distance = 0.001;
f_force = (force_val)*(1/(100 * pow((double)distance, (double)ffall_val)));
speed[0] -= (force_vec[0] * f_force );
speed[1] -= (force_vec[1] * f_force );
speed[2] -= (force_vec[2] * f_force );
}
}
base = base->next;
}
@ -833,8 +818,7 @@ void make_particle_keys(int depth, int nr, PartEff *paf, Particle *part, float *
/* Check force field */
cur_time = pa->time;
get_forcefield(opco, new_force, cur_time, par_layer);
get_vortex(opco, opa->no, new_speed, cur_time, par_layer);
get_effector(opco, new_force, new_speed, cur_time, par_layer);
/* new location */
pa->co[0]= opa->co[0] + deltalife * (opa->no[0] + new_speed[0] + 0.5*new_force[0]);