Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2018-09-25 04:41:29 +0300
committerCampbell Barton <ideasman42@gmail.com>2018-09-25 04:41:29 +0300
commit10fbea8845d6994bce0ccbdad763793548ef757d (patch)
tree12a58fd35d4216718495a56bddbc4c7a5f0fe68c /source/blender/blenkernel
parent50731ff5963a058c86e45d153de56b74b9f27176 (diff)
Cleanup: style
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r--source/blender/blenkernel/intern/effect.c394
1 files changed, 213 insertions, 181 deletions
diff --git a/source/blender/blenkernel/intern/effect.c b/source/blender/blenkernel/intern/effect.c
index 89f85530439..82bf65993a8 100644
--- a/source/blender/blenkernel/intern/effect.c
+++ b/source/blender/blenkernel/intern/effect.c
@@ -56,7 +56,7 @@
#include "PIL_time.h"
-#include "BKE_anim.h" /* needed for where_on_path */
+#include "BKE_anim.h" /* needed for where_on_path */
#include "BKE_collision.h"
#include "BKE_curve.h"
#include "BKE_displist.h"
@@ -87,8 +87,9 @@ EffectorWeights *BKE_add_effector_weights(Group *group)
EffectorWeights *weights = MEM_callocN(sizeof(EffectorWeights), "EffectorWeights");
int i;
- for (i=0; i<NUM_PFIELD_TYPES; i++)
+ for (i = 0; i < NUM_PFIELD_TYPES; i++) {
weights->weight[i] = 1.0f;
+ }
weights->global_gravity = 1.0f;
@@ -100,13 +101,13 @@ PartDeflect *object_add_collision_fields(int type)
{
PartDeflect *pd;
- pd= MEM_callocN(sizeof(PartDeflect), "PartDeflect");
+ pd = MEM_callocN(sizeof(PartDeflect), "PartDeflect");
pd->forcefield = type;
pd->pdef_sbdamp = 0.1f;
pd->pdef_sbift = 0.2f;
pd->pdef_sboft = 0.02f;
- pd->seed = ((unsigned int)(ceil(PIL_check_seconds_timer()))+1) % 128;
+ pd->seed = ((uint)(ceil(PIL_check_seconds_timer())) + 1) % 128;
pd->f_strength = 1.0f;
pd->f_damp = 1.0f;
@@ -126,7 +127,7 @@ PartDeflect *object_add_collision_fields(int type)
pd->f_flow = 1.0f;
break;
}
- pd->flag = PFIELD_DO_LOCATION|PFIELD_DO_ROTATION;
+ pd->flag = PFIELD_DO_LOCATION | PFIELD_DO_ROTATION;
return pd;
}
@@ -136,12 +137,12 @@ PartDeflect *object_add_collision_fields(int type)
/* -------------------------- Effectors ------------------ */
void free_partdeflect(PartDeflect *pd)
{
- if (!pd)
+ if (!pd) {
return;
-
- if (pd->rng)
+ }
+ if (pd->rng) {
BLI_rng_free(pd->rng);
-
+ }
MEM_freeN(pd);
}
@@ -159,15 +160,18 @@ static void add_object_to_effectors(ListBase **effectors, Scene *scene, Effector
{
EffectorCache *eff = NULL;
- if ( ob == ob_src )
+ if (ob == ob_src) {
return;
+ }
if (for_simulation) {
- if (weights->weight[ob->pd->forcefield] == 0.0f )
+ if (weights->weight[ob->pd->forcefield] == 0.0f) {
return;
+ }
- if (ob->pd->shape == PFIELD_SHAPE_POINTS && !ob->derivedFinal )
+ if (ob->pd->shape == PFIELD_SHAPE_POINTS && !ob->derivedFinal) {
return;
+ }
}
if (*effectors == NULL)
@@ -182,72 +186,70 @@ static void add_object_to_effectors(ListBase **effectors, Scene *scene, Effector
}
static void add_particles_to_effectors(ListBase **effectors, Scene *scene, EffectorWeights *weights, Object *ob, ParticleSystem *psys, ParticleSystem *psys_src, bool for_simulation)
{
- ParticleSettings *part= psys->part;
+ ParticleSettings *part = psys->part;
- if ( !psys_check_enabled(ob, psys, G.is_rendering) )
+ if (!psys_check_enabled(ob, psys, G.is_rendering)) {
return;
-
- if ( psys == psys_src && (part->flag & PART_SELF_EFFECT) == 0)
+ }
+ if (psys == psys_src && (part->flag & PART_SELF_EFFECT) == 0) {
return;
-
- if ( part->pd && part->pd->forcefield && (!for_simulation || weights->weight[part->pd->forcefield] != 0.0f)) {
- if (*effectors == NULL)
+ }
+ if (part->pd && part->pd->forcefield && (!for_simulation || weights->weight[part->pd->forcefield] != 0.0f)) {
+ if (*effectors == NULL) {
*effectors = MEM_callocN(sizeof(ListBase), "effectors list");
-
+ }
BLI_addtail(*effectors, new_effector_cache(scene, ob, psys, part->pd));
}
if (part->pd2 && part->pd2->forcefield && (!for_simulation || weights->weight[part->pd2->forcefield] != 0.0f)) {
- if (*effectors == NULL)
+ if (*effectors == NULL) {
*effectors = MEM_callocN(sizeof(ListBase), "effectors list");
-
+ }
BLI_addtail(*effectors, new_effector_cache(scene, ob, psys, part->pd2));
}
}
/* returns ListBase handle with objects taking part in the effecting */
-ListBase *pdInitEffectors(Scene *scene, Object *ob_src, ParticleSystem *psys_src,
- EffectorWeights *weights, bool for_simulation)
+ListBase *pdInitEffectors(
+ Scene *scene, Object *ob_src, ParticleSystem *psys_src,
+ EffectorWeights *weights, bool for_simulation)
{
- Base *base;
- unsigned int layer= ob_src->lay;
+ const uint layer = ob_src->lay;
ListBase *effectors = NULL;
if (weights->group) {
- GroupObject *go;
-
- for (go= weights->group->gobject.first; go; go= go->next) {
- if ( (go->ob->lay & layer) ) {
- if ( go->ob->pd && go->ob->pd->forcefield )
+ for (GroupObject *go = weights->group->gobject.first; go; go = go->next) {
+ if ((go->ob->lay & layer)) {
+ if (go->ob->pd && go->ob->pd->forcefield) {
add_object_to_effectors(&effectors, scene, weights, go->ob, ob_src, for_simulation);
+ }
- if ( go->ob->particlesystem.first ) {
- ParticleSystem *psys= go->ob->particlesystem.first;
-
- for ( ; psys; psys=psys->next )
+ if (go->ob->particlesystem.first) {
+ for (ParticleSystem *psys = go->ob->particlesystem.first; psys; psys = psys->next) {
add_particles_to_effectors(&effectors, scene, weights, go->ob, psys, psys_src, for_simulation);
+ }
}
}
}
}
else {
- for (base = scene->base.first; base; base= base->next) {
- if ( (base->lay & layer) ) {
- if ( base->object->pd && base->object->pd->forcefield )
+ for (Base *base = scene->base.first; base; base = base->next) {
+ if ((base->lay & layer)) {
+ if (base->object->pd && base->object->pd->forcefield) {
add_object_to_effectors(&effectors, scene, weights, base->object, ob_src, for_simulation);
-
- if ( base->object->particlesystem.first ) {
- ParticleSystem *psys= base->object->particlesystem.first;
-
- for ( ; psys; psys=psys->next )
+ }
+ if (base->object->particlesystem.first) {
+ for (ParticleSystem *psys = base->object->particlesystem.first; psys; psys = psys->next) {
add_particles_to_effectors(&effectors, scene, weights, base->object, psys, psys_src, for_simulation);
+ }
}
}
}
}
- if (for_simulation)
+ if (for_simulation) {
pdPrecalculateEffectors(effectors);
+ }
return effectors;
}
@@ -255,11 +257,10 @@ ListBase *pdInitEffectors(Scene *scene, Object *ob_src, ParticleSystem *psys_src
void pdEndEffectors(ListBase **effectors)
{
if (*effectors) {
- EffectorCache *eff = (*effectors)->first;
-
- for (; eff; eff=eff->next) {
- if (eff->guide_data)
+ for (EffectorCache *eff = (*effectors)->first; eff; eff = eff->next) {
+ if (eff->guide_data) {
MEM_freeN(eff->guide_data);
+ }
}
BLI_freelistN(*effectors);
@@ -270,17 +271,23 @@ void pdEndEffectors(ListBase **effectors)
static void precalculate_effector(EffectorCache *eff)
{
- unsigned int cfra = (unsigned int)(eff->scene->r.cfra >= 0 ? eff->scene->r.cfra : -eff->scene->r.cfra);
- if (!eff->pd->rng)
+ uint cfra = (uint)(eff->scene->r.cfra >= 0 ? eff->scene->r.cfra : -eff->scene->r.cfra);
+ if (!eff->pd->rng) {
eff->pd->rng = BLI_rng_new(eff->pd->seed + cfra);
- else
+ }
+ else {
BLI_rng_srandom(eff->pd->rng, eff->pd->seed + cfra);
+ }
- if (eff->pd->forcefield == PFIELD_GUIDE && eff->ob->type==OB_CURVE) {
- Curve *cu= eff->ob->data;
+ if (eff->pd->forcefield == PFIELD_GUIDE && eff->ob->type == OB_CURVE) {
+ Curve *cu = eff->ob->data;
if (cu->flag & CU_PATH) {
- if (eff->ob->curve_cache == NULL || eff->ob->curve_cache->path==NULL || eff->ob->curve_cache->path->data==NULL)
+ if ((eff->ob->curve_cache == NULL) ||
+ (eff->ob->curve_cache->path == NULL) ||
+ (eff->ob->curve_cache->path->data == NULL))
+ {
BKE_displist_make_curveTypes(eff->scene, eff->ob, 0);
+ }
if (eff->ob->curve_cache->path && eff->ob->curve_cache->path->data) {
where_on_path(eff->ob, 0.0, eff->guide_loc, eff->guide_dir, NULL, &eff->guide_radius, NULL);
@@ -290,12 +297,14 @@ static void precalculate_effector(EffectorCache *eff)
}
}
else if (eff->pd->shape == PFIELD_SHAPE_SURFACE) {
- eff->surmd = (SurfaceModifierData *)modifiers_findByType( eff->ob, eModifierType_Surface );
- if (eff->ob->type == OB_CURVE)
+ eff->surmd = (SurfaceModifierData *)modifiers_findByType(eff->ob, eModifierType_Surface);
+ if (eff->ob->type == OB_CURVE) {
eff->flag |= PE_USE_NORMAL_DATA;
+ }
}
- else if (eff->psys)
+ else if (eff->psys) {
psys_update_particle_tree(eff->psys, eff->scene->r.cfra);
+ }
/* Store object velocity */
if (eff->ob) {
@@ -311,9 +320,9 @@ static void precalculate_effector(EffectorCache *eff)
void pdPrecalculateEffectors(ListBase *effectors)
{
if (effectors) {
- EffectorCache *eff = effectors->first;
- for (; eff; eff=eff->next)
+ for (EffectorCache *eff = effectors->first; eff; eff = eff->next) {
precalculate_effector(eff);
+ }
}
}
@@ -400,14 +409,15 @@ static float eff_calc_visibility(ListBase *colliders, EffectorCache *eff, Effect
float norm[3], len = 0.0;
float visibility = 1.0, absorption = 0.0;
- if (!(eff->pd->flag & PFIELD_VISIBILITY))
+ if (!(eff->pd->flag & PFIELD_VISIBILITY)) {
return visibility;
-
- if (!colls)
+ }
+ if (!colls) {
colls = get_collider_cache(eff->scene, eff->ob, NULL);
-
- if (!colls)
+ }
+ if (!colls) {
return visibility;
+ }
negate_v3_v3(norm, efd->vec_to_point);
len = normalize_v3(norm);
@@ -416,9 +426,9 @@ static float eff_calc_visibility(ListBase *colliders, EffectorCache *eff, Effect
for (col = colls->first; col; col = col->next) {
CollisionModifierData *collmd = col->collmd;
- if (col->ob == eff->ob)
+ if (col->ob == eff->ob) {
continue;
-
+ }
if (collmd->bvhtree) {
BVHTreeRayHit hit;
@@ -430,13 +440,14 @@ static float eff_calc_visibility(ListBase *colliders, EffectorCache *eff, Effect
collmd->bvhtree, point->loc, norm, 0.0f, &hit,
eff_tri_ray_hit, NULL, raycast_flag) != -1)
{
- absorption= col->ob->pd->absorption;
+ absorption = col->ob->pd->absorption;
/* visibility is only between 0 and 1, calculated from 1-absorption */
- visibility *= CLAMPIS(1.0f-absorption, 0.0f, 1.0f);
+ visibility *= CLAMPIS(1.0f - absorption, 0.0f, 1.0f);
- if (visibility <= 0.0f)
+ if (visibility <= 0.0f) {
break;
+ }
}
}
}
@@ -450,14 +461,15 @@ static float eff_calc_visibility(ListBase *colliders, EffectorCache *eff, Effect
// noise function for wind e.g.
static float wind_func(struct RNG *rng, float strength)
{
- int random = (BLI_rng_get_int(rng)+1) % 128; // max 2357
+ int random = (BLI_rng_get_int(rng) + 1) % 128; /* max 2357 */
float force = BLI_rng_get_float(rng) + 1.0f;
float ret;
float sign = 0;
- sign = ((float)random > 64.0f) ? 1.0f: -1.0f; // dividing by 2 is not giving equal sign distribution
+ /* Dividing by 2 is not giving equal sign distribution. */
+ sign = ((float)random > 64.0f) ? 1.0f : -1.0f;
- ret = sign*((float)random / force)*strength/128.0f;
+ ret = sign * ((float)random / force) * strength / 128.0f;
return ret;
}
@@ -477,17 +489,17 @@ static float falloff_func(float fac, int usemin, float mindist, int usemax, floa
if (!usemin)
mindist = 0.0;
- return pow((double)(1.0f+fac-mindist), (double)(-power));
+ return pow((double)(1.0f + fac - mindist), (double)(-power));
}
static float falloff_func_dist(PartDeflect *pd, float fac)
{
- return falloff_func(fac, pd->flag&PFIELD_USEMIN, pd->mindist, pd->flag&PFIELD_USEMAX, pd->maxdist, pd->f_power);
+ return falloff_func(fac, pd->flag & PFIELD_USEMIN, pd->mindist, pd->flag & PFIELD_USEMAX, pd->maxdist, pd->f_power);
}
static float falloff_func_rad(PartDeflect *pd, float fac)
{
- return falloff_func(fac, pd->flag&PFIELD_USEMINR, pd->minrad, pd->flag&PFIELD_USEMAXR, pd->maxrad, pd->f_power_r);
+ return falloff_func(fac, pd->flag & PFIELD_USEMINR, pd->minrad, pd->flag & PFIELD_USEMAXR, pd->maxrad, pd->f_power_r);
}
float effector_falloff(EffectorCache *eff, EffectorData *efd, EffectedPoint *UNUSED(point), EffectorWeights *weights)
@@ -499,31 +511,31 @@ float effector_falloff(EffectorCache *eff, EffectorData *efd, EffectedPoint *UNU
fac = dot_v3v3(efd->nor, efd->vec_to_point2);
if (eff->pd->zdir == PFIELD_Z_POS && fac < 0.0f)
- falloff=0.0f;
+ falloff = 0.0f;
else if (eff->pd->zdir == PFIELD_Z_NEG && fac > 0.0f)
- falloff=0.0f;
+ falloff = 0.0f;
else {
switch (eff->pd->falloff) {
case PFIELD_FALL_SPHERE:
- falloff*= falloff_func_dist(eff->pd, efd->distance);
+ falloff *= falloff_func_dist(eff->pd, efd->distance);
break;
case PFIELD_FALL_TUBE:
- falloff*= falloff_func_dist(eff->pd, ABS(fac));
+ falloff *= falloff_func_dist(eff->pd, ABS(fac));
if (falloff == 0.0f)
break;
madd_v3_v3v3fl(temp, efd->vec_to_point2, efd->nor, -fac);
- r_fac= len_v3(temp);
- falloff*= falloff_func_rad(eff->pd, r_fac);
+ r_fac = len_v3(temp);
+ falloff *= falloff_func_rad(eff->pd, r_fac);
break;
case PFIELD_FALL_CONE:
- falloff*= falloff_func_dist(eff->pd, ABS(fac));
+ falloff *= falloff_func_dist(eff->pd, ABS(fac));
if (falloff == 0.0f)
break;
- r_fac= RAD2DEGF(saacos(fac/len_v3(efd->vec_to_point)));
- falloff*= falloff_func_rad(eff->pd, r_fac);
+ r_fac = RAD2DEGF(saacos(fac / len_v3(efd->vec_to_point)));
+ falloff *= falloff_func_rad(eff->pd, r_fac);
break;
}
@@ -570,7 +582,7 @@ int get_effector_data(EffectorCache *eff, EffectorData *efd, EffectedPoint *poin
/* In case surface object is in Edit mode when loading the .blend, surface modifier is never executed
* and bvhtree never built, see T48415. */
- if (eff->pd && eff->pd->shape==PFIELD_SHAPE_SURFACE && eff->surmd && eff->surmd->bvhtree) {
+ if (eff->pd && eff->pd->shape == PFIELD_SHAPE_SURFACE && eff->surmd && eff->surmd->bvhtree) {
/* closest point in the object surface is an effector */
float vec[3];
@@ -583,7 +595,7 @@ int get_effector_data(EffectorCache *eff, EffectorData *efd, EffectedPoint *poin
efd->size = 0.0f;
}
- else if (eff->pd && eff->pd->shape==PFIELD_SHAPE_POINTS) {
+ else if (eff->pd && eff->pd->shape == PFIELD_SHAPE_POINTS) {
if (eff->ob->derivedFinal) {
DerivedMesh *dm = eff->ob->derivedFinal;
@@ -611,10 +623,10 @@ int get_effector_data(EffectorCache *eff, EffectorData *efd, EffectedPoint *poin
/* pass */
}
else {
- ParticleSimulationData sim= {NULL};
- sim.scene= eff->scene;
- sim.ob= eff->ob;
- sim.psys= eff->psys;
+ ParticleSimulationData sim = {NULL};
+ sim.scene = eff->scene;
+ sim.ob = eff->ob;
+ sim.psys = eff->psys;
/* TODO: time from actual previous calculated frame (step might not be 1) */
state.time = cfra - 1.0f;
@@ -633,9 +645,9 @@ int get_effector_data(EffectorCache *eff, EffectorData *efd, EffectedPoint *poin
efd->nor[1] = efd->nor[2] = 0.f;
mul_qt_v3(state.rot, efd->nor);
- if (real_velocity)
+ if (real_velocity) {
copy_v3_v3(efd->vel, state.vel);
-
+ }
efd->size = pa->size;
}
}
@@ -652,18 +664,20 @@ int get_effector_data(EffectorCache *eff, EffectorData *efd, EffectedPoint *poin
project_v3_v3v3(translate, temp, efd->nor);
/* for vortex the shape chooses between old / new force */
- if (eff->pd->forcefield == PFIELD_VORTEX)
+ if (eff->pd->forcefield == PFIELD_VORTEX) {
add_v3_v3v3(efd->loc, ob->obmat[3], translate);
- else /* normally efd->loc is closest point on effector xy-plane */
+ }
+ else { /* normally efd->loc is closest point on effector xy-plane */
sub_v3_v3v3(efd->loc, point->loc, translate);
+ }
}
else {
copy_v3_v3(efd->loc, ob->obmat[3]);
}
- if (real_velocity)
+ if (real_velocity) {
copy_v3_v3(efd->vel, eff->velocity);
-
+ }
efd->size = 0.0f;
ret = 1;
@@ -675,7 +689,7 @@ int get_effector_data(EffectorCache *eff, EffectorData *efd, EffectedPoint *poin
/* rest length for harmonic effector, will have to see later if this could be extended to other effectors */
if (eff->pd && eff->pd->forcefield == PFIELD_HARMONIC && eff->pd->f_size)
- mul_v3_fl(efd->vec_to_point, (efd->distance-eff->pd->f_size)/efd->distance);
+ mul_v3_fl(efd->vec_to_point, (efd->distance - eff->pd->f_size) / efd->distance);
if (eff->flag & PE_USE_NORMAL_DATA) {
copy_v3_v3(efd->vec_to_point2, efd->vec_to_point);
@@ -700,7 +714,7 @@ static void get_effector_tot(EffectorCache *eff, EffectorData *efd, EffectedPoin
if (*tot && eff->pd->forcefield == PFIELD_HARMONIC && point->index >= 0) {
*p = point->index % *tot;
- *tot = *p+1;
+ *tot = *p + 1;
}
}
else if (eff->psys) {
@@ -715,17 +729,17 @@ static void get_effector_tot(EffectorCache *eff, EffectorData *efd, EffectedPoin
*/
efd->charge = eff->pd->f_strength;
}
- else if (eff->pd->forcefield == PFIELD_HARMONIC && (eff->pd->flag & PFIELD_MULTIPLE_SPRINGS)==0) {
+ else if (eff->pd->forcefield == PFIELD_HARMONIC && (eff->pd->flag & PFIELD_MULTIPLE_SPRINGS) == 0) {
/* every particle is mapped to only one harmonic effector particle */
- *p= point->index % eff->psys->totpart;
- *tot= *p + 1;
+ *p = point->index % eff->psys->totpart;
+ *tot = *p + 1;
}
if (eff->psys->part->effector_amount) {
int totpart = eff->psys->totpart;
int amount = eff->psys->part->effector_amount;
- *step = (totpart > amount) ? totpart/amount : 1;
+ *step = (totpart > amount) ? totpart / amount : 1;
}
}
else {
@@ -746,7 +760,7 @@ static void do_texture_effector(EffectorCache *eff, EffectorData *efd, EffectedP
result[0].nor = result[1].nor = result[2].nor = result[3].nor = NULL;
- strength= eff->pd->f_strength * efd->falloff;
+ strength = eff->pd->f_strength * efd->falloff;
copy_v3_v3(tex_co, point->loc);
@@ -757,7 +771,7 @@ static void do_texture_effector(EffectorCache *eff, EffectorData *efd, EffectedP
tex_co[2] = 0.0f;
}
else if (eff->pd->flag & PFIELD_TEX_2D) {
- float fac=-dot_v3v3(tex_co, efd->nor);
+ float fac = -dot_v3v3(tex_co, efd->nor);
madd_v3_v3fl(tex_co, efd->nor, fac);
}
@@ -765,31 +779,31 @@ static void do_texture_effector(EffectorCache *eff, EffectorData *efd, EffectedP
hasrgb = multitex_ext(eff->pd->tex, tex_co, NULL, NULL, 0, result, 0, NULL, scene_color_manage, false);
- if (hasrgb && mode==PFIELD_TEX_RGB) {
+ if (hasrgb && mode == PFIELD_TEX_RGB) {
force[0] = (0.5f - result->tr) * strength;
force[1] = (0.5f - result->tg) * strength;
force[2] = (0.5f - result->tb) * strength;
}
else if (nabla != 0) {
- strength/=nabla;
+ strength /= nabla;
tex_co[0] += nabla;
- multitex_ext(eff->pd->tex, tex_co, NULL, NULL, 0, result+1, 0, NULL, scene_color_manage, false);
+ multitex_ext(eff->pd->tex, tex_co, NULL, NULL, 0, result + 1, 0, NULL, scene_color_manage, false);
tex_co[0] -= nabla;
tex_co[1] += nabla;
- multitex_ext(eff->pd->tex, tex_co, NULL, NULL, 0, result+2, 0, NULL, scene_color_manage, false);
+ multitex_ext(eff->pd->tex, tex_co, NULL, NULL, 0, result + 2, 0, NULL, scene_color_manage, false);
tex_co[1] -= nabla;
tex_co[2] += nabla;
- multitex_ext(eff->pd->tex, tex_co, NULL, NULL, 0, result+3, 0, NULL, scene_color_manage, false);
+ multitex_ext(eff->pd->tex, tex_co, NULL, NULL, 0, result + 3, 0, NULL, scene_color_manage, false);
if (mode == PFIELD_TEX_GRAD || !hasrgb) { /* if we don't have rgb fall back to grad */
/* generate intensity if texture only has rgb value */
if (hasrgb & TEX_RGB) {
- int i;
- for (i=0; i<4; i++)
+ for (int i = 0; i < 4; i++) {
result[i].tin = (1.0f / 3.0f) * (result[i].tr + result[i].tg + result[i].tb);
+ }
}
force[0] = (result[0].tin - result[1].tin) * strength;
force[1] = (result[0].tin - result[2].tin) * strength;
@@ -835,8 +849,9 @@ static void do_physical_effector(EffectorCache *eff, EffectorData *efd, Effected
if (noise_factor > 0.0f) {
strength += wind_func(rng, noise_factor);
- if (ELEM(pd->forcefield, PFIELD_HARMONIC, PFIELD_DRAG))
+ if (ELEM(pd->forcefield, PFIELD_HARMONIC, PFIELD_DRAG)) {
damp += wind_func(rng, noise_factor);
+ }
}
copy_v3_v3(force, efd->vec_to_point);
@@ -848,8 +863,8 @@ static void do_physical_effector(EffectorCache *eff, EffectorData *efd, Effected
break;
case PFIELD_FORCE:
normalize_v3(force);
- if (pd->flag & PFIELD_GRAVITATION){ /* Option: Multiply by 1/distance^2 */
- if (efd->distance < FLT_EPSILON){
+ if (pd->flag & PFIELD_GRAVITATION) { /* Option: Multiply by 1/distance^2 */
+ if (efd->distance < FLT_EPSILON) {
strength = 0.0f;
}
else {
@@ -901,10 +916,10 @@ static void do_physical_effector(EffectorCache *eff, EffectorData *efd, Effected
case PFIELD_LENNARDJ:
fac = pow((efd->size + point->size) / efd->distance, 6.0);
- fac = - fac * (1.0f - fac) / efd->distance;
+ fac = -fac * (1.0f - fac) / efd->distance;
/* limit the repulsive term drastically to avoid huge forces */
- fac = ((fac>2.0f) ? 2.0f : fac);
+ fac = ((fac > 2.0f) ? 2.0f : fac);
mul_v3_fl(force, strength * fac);
break;
@@ -938,8 +953,9 @@ static void do_physical_effector(EffectorCache *eff, EffectorData *efd, Effected
float density;
if ((density = smoke_get_velocity_at(pd->f_source, point->loc, force)) >= 0.0f) {
float influence = strength * efd->falloff;
- if (pd->flag & PFIELD_SMOKE_DENSITY)
+ if (pd->flag & PFIELD_SMOKE_DENSITY) {
influence *= density;
+ }
mul_v3_fl(force, influence);
/* apply flow */
madd_v3_v3fl(total_force, point->vel, -pd->f_flow * influence);
@@ -950,15 +966,16 @@ static void do_physical_effector(EffectorCache *eff, EffectorData *efd, Effected
}
if (pd->flag & PFIELD_DO_LOCATION) {
- madd_v3_v3fl(total_force, force, 1.0f/point->vel_to_sec);
+ madd_v3_v3fl(total_force, force, 1.0f / point->vel_to_sec);
- if (ELEM(pd->forcefield, PFIELD_HARMONIC, PFIELD_DRAG, PFIELD_SMOKEFLOW)==0 && pd->f_flow != 0.0f) {
+ if (ELEM(pd->forcefield, PFIELD_HARMONIC, PFIELD_DRAG, PFIELD_SMOKEFLOW) == 0 && pd->f_flow != 0.0f) {
madd_v3_v3fl(total_force, point->vel, -pd->f_flow * efd->falloff);
}
}
- if (point->ave)
+ if (point->ave) {
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];
@@ -1001,45 +1018,47 @@ void pdDoEffectors(ListBase *effectors, ListBase *colliders, EffectorWeights *we
*/
EffectorCache *eff;
EffectorData efd;
- int p=0, tot = 1, step = 1;
+ int p = 0, tot = 1, step = 1;
/* Cycle through collected objects, get total of (1/(gravity_strength * dist^gravity_power)) */
/* Check for min distance here? (yes would be cool to add that, ton) */
- if (effectors) for (eff = effectors->first; eff; eff=eff->next) {
- /* object effectors were fully checked to be OK to evaluate! */
-
- get_effector_tot(eff, &efd, point, &tot, &p, &step);
+ if (effectors) {
+ for (eff = effectors->first; eff; eff = eff->next) {
+ /* object effectors were fully checked to be OK to evaluate! */
- for (; p<tot; p+=step) {
- if (get_effector_data(eff, &efd, point, 0)) {
- efd.falloff= effector_falloff(eff, &efd, point, weights);
+ get_effector_tot(eff, &efd, point, &tot, &p, &step);
- if (efd.falloff > 0.0f)
- efd.falloff *= eff_calc_visibility(colliders, eff, &efd, point);
+ for (; p < tot; p += step) {
+ if (get_effector_data(eff, &efd, point, 0)) {
+ efd.falloff = effector_falloff(eff, &efd, point, weights);
- if (efd.falloff <= 0.0f) {
- /* don't do anything */
- }
- else if (eff->pd->forcefield == PFIELD_TEXTURE) {
- do_texture_effector(eff, &efd, point, force);
- }
- else {
- float temp1[3] = {0, 0, 0}, temp2[3];
- copy_v3_v3(temp1, force);
+ if (efd.falloff > 0.0f) {
+ efd.falloff *= eff_calc_visibility(colliders, eff, &efd, point);
+ }
+ if (efd.falloff <= 0.0f) {
+ /* don't do anything */
+ }
+ else if (eff->pd->forcefield == PFIELD_TEXTURE) {
+ do_texture_effector(eff, &efd, point, force);
+ }
+ else {
+ float temp1[3] = {0, 0, 0}, temp2[3];
+ copy_v3_v3(temp1, force);
- do_physical_effector(eff, &efd, point, force);
+ do_physical_effector(eff, &efd, point, force);
- /* for softbody backward compatibility */
- if (point->flag & PE_WIND_AS_SPEED && impulse) {
- sub_v3_v3v3(temp2, force, temp1);
- sub_v3_v3v3(impulse, impulse, temp2);
+ /* for softbody backward compatibility */
+ if (point->flag & PE_WIND_AS_SPEED && impulse) {
+ sub_v3_v3v3(temp2, force, temp1);
+ sub_v3_v3v3(impulse, impulse, temp2);
+ }
}
}
- }
- else if (eff->flag & PE_VELOCITY_TO_IMPULSE && impulse) {
- /* special case for harmonic effector */
- add_v3_v3v3(impulse, impulse, efd.vel);
+ else if (eff->flag & PE_VELOCITY_TO_IMPULSE && impulse) {
+ /* special case for harmonic effector */
+ add_v3_v3v3(impulse, impulse, efd.vel);
+ }
}
}
}
@@ -1049,35 +1068,35 @@ void pdDoEffectors(ListBase *effectors, ListBase *colliders, EffectorWeights *we
SimDebugData *_sim_debug_data = NULL;
-unsigned int BKE_sim_debug_data_hash(int i)
+uint BKE_sim_debug_data_hash(int i)
{
- return BLI_ghashutil_uinthash((unsigned int)i);
+ return BLI_ghashutil_uinthash((uint)i);
}
-unsigned int BKE_sim_debug_data_hash_combine(unsigned int kx, unsigned int ky)
+uint BKE_sim_debug_data_hash_combine(uint kx, uint ky)
{
-#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
+#define rot(x, k) (((x) << (k)) | ((x) >> (32 - (k))))
- unsigned int a, b, c;
+ uint a, b, c;
a = b = c = 0xdeadbeef + (2 << 2) + 13;
a += kx;
b += ky;
- c ^= b; c -= rot(b,14);
- a ^= c; a -= rot(c,11);
- b ^= a; b -= rot(a,25);
- c ^= b; c -= rot(b,16);
- a ^= c; a -= rot(c,4);
- b ^= a; b -= rot(a,14);
- c ^= b; c -= rot(b,24);
+ c ^= b; c -= rot(b, 14);
+ a ^= c; a -= rot(c, 11);
+ b ^= a; b -= rot(a, 25);
+ c ^= b; c -= rot(b, 16);
+ a ^= c; a -= rot(c, 4);
+ b ^= a; b -= rot(a, 14);
+ c ^= b; c -= rot(b, 24);
return c;
#undef rot
}
-static unsigned int debug_element_hash(const void *key)
+static uint debug_element_hash(const void *key)
{
const SimDebugElement *elem = key;
return elem->hash;
@@ -1121,8 +1140,9 @@ bool BKE_sim_debug_data_get_enabled(void)
void BKE_sim_debug_data_free(void)
{
if (_sim_debug_data) {
- if (_sim_debug_data->gh)
+ if (_sim_debug_data->gh) {
BLI_ghash_free(_sim_debug_data->gh, NULL, debug_element_free);
+ }
MEM_freeN(_sim_debug_data);
}
}
@@ -1134,20 +1154,23 @@ static void debug_data_insert(SimDebugData *debug_data, SimDebugElement *elem)
*old_elem = *elem;
MEM_freeN(elem);
}
- else
+ else {
BLI_ghash_insert(debug_data->gh, elem, elem);
+ }
}
-void BKE_sim_debug_data_add_element(int type, const float v1[3], const float v2[3], const char *str, float r, float g, float b, const char *category, unsigned int hash)
+void BKE_sim_debug_data_add_element(int type, const float v1[3], const float v2[3], const char *str, float r, float g, float b, const char *category, uint hash)
{
- unsigned int category_hash = BLI_ghashutil_strhash_p(category);
+ uint category_hash = BLI_ghashutil_strhash_p(category);
SimDebugElement *elem;
if (!_sim_debug_data) {
- if (G.debug & G_DEBUG_SIMDATA)
+ if (G.debug & G_DEBUG_SIMDATA) {
BKE_sim_debug_data_set_enabled(true);
- else
+ }
+ else {
return;
+ }
}
elem = MEM_callocN(sizeof(SimDebugElement), "sim debug data element");
@@ -1157,47 +1180,55 @@ void BKE_sim_debug_data_add_element(int type, const float v1[3], const float v2[
elem->color[0] = r;
elem->color[1] = g;
elem->color[2] = b;
- if (v1)
+ if (v1) {
copy_v3_v3(elem->v1, v1);
- else
+ }
+ else {
zero_v3(elem->v1);
- if (v2)
+ }
+ if (v2) {
copy_v3_v3(elem->v2, v2);
- else
+ }
+ else {
zero_v3(elem->v2);
- if (str)
+ }
+ if (str) {
BLI_strncpy(elem->str, str, sizeof(elem->str));
- else
+ }
+ else {
elem->str[0] = '\0';
+ }
debug_data_insert(_sim_debug_data, elem);
}
-void BKE_sim_debug_data_remove_element(unsigned int hash)
+void BKE_sim_debug_data_remove_element(uint hash)
{
SimDebugElement dummy;
- if (!_sim_debug_data)
+ if (!_sim_debug_data) {
return;
-
+ }
dummy.hash = hash;
BLI_ghash_remove(_sim_debug_data->gh, &dummy, NULL, debug_element_free);
}
void BKE_sim_debug_data_clear(void)
{
- if (!_sim_debug_data)
+ if (!_sim_debug_data) {
return;
-
- if (_sim_debug_data->gh)
+ }
+ if (_sim_debug_data->gh) {
BLI_ghash_clear(_sim_debug_data->gh, NULL, debug_element_free);
+ }
}
void BKE_sim_debug_data_clear_category(const char *category)
{
int category_hash = (int)BLI_ghashutil_strhash_p(category);
- if (!_sim_debug_data)
+ if (!_sim_debug_data) {
return;
+ }
if (_sim_debug_data->gh) {
GHashIterator iter;
@@ -1206,8 +1237,9 @@ void BKE_sim_debug_data_clear_category(const char *category)
const SimDebugElement *elem = BLI_ghashIterator_getValue(&iter);
BLI_ghashIterator_step(&iter); /* removing invalidates the current iterator, so step before removing */
- if (elem->category_hash == category_hash)
+ if (elem->category_hash == category_hash) {
BLI_ghash_remove(_sim_debug_data->gh, elem, NULL, debug_element_free);
+ }
}
}
}