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:
authorGermano Cavalcante <germano.costa@ig.com.br>2020-08-12 23:57:26 +0300
committerGermano Cavalcante <germano.costa@ig.com.br>2020-08-13 00:25:45 +0300
commit7d16db417b45266c6f8245465ccb40ffd7573bb5 (patch)
tree502fb64c8dab154ae659de2efa1c9ec7c816b658 /source/blender/blenkernel/intern/collision.c
parent6d9358d453966ccb139fcbfe93cbbd1adcd86cd7 (diff)
Cleanup: move assignment out of loop
Diffstat (limited to 'source/blender/blenkernel/intern/collision.c')
-rw-r--r--source/blender/blenkernel/intern/collision.c24
1 files changed, 11 insertions, 13 deletions
diff --git a/source/blender/blenkernel/intern/collision.c b/source/blender/blenkernel/intern/collision.c
index 1a55135ccfb..467f15201fc 100644
--- a/source/blender/blenkernel/intern/collision.c
+++ b/source/blender/blenkernel/intern/collision.c
@@ -684,16 +684,17 @@ static int cloth_collision_response_static(ClothModifierData *clmd,
float w1, w2, w3, u1, u2, u3;
float v1[3], v2[3], relativeVelocity[3];
float magrelVel;
- float epsilon2 = BLI_bvhtree_get_epsilon(collmd->bvhtree);
- const bool is_hair = (clmd->hairdata != NULL);
+ const float clamp_sq = square_f(clmd->coll_parms->self_clamp * dt);
+ const float time_multiplier = 1.0f / (clmd->sim_parms->dt * clmd->sim_parms->timescale);
+ const float epsilon2 = BLI_bvhtree_get_epsilon(collmd->bvhtree);
+ const float min_distance = (clmd->coll_parms->epsilon + epsilon2) * (8.0f / 9.0f);
+ const bool is_hair = (clmd->hairdata != NULL);
for (int i = 0; i < collision_count; i++, collpair++) {
- float i1[3], i2[3], i3[3], time_multiplier, d;
+ float i1[3], i2[3], i3[3];
zero_v3(i1);
zero_v3(i2);
zero_v3(i3);
- time_multiplier = 1.0f / (clmd->sim_parms->dt * clmd->sim_parms->timescale);
- d = clmd->coll_parms->epsilon * 8.0f / 9.0f + epsilon2 * 8.0f / 9.0f - collpair->distance;
/* Only handle static collisions here. */
if (collpair->flag & (COLLISION_IN_FUTURE | COLLISION_INACTIVE)) {
@@ -748,6 +749,7 @@ static int cloth_collision_response_static(ClothModifierData *clmd,
/* Calculate the normal component of the relative velocity
* (actually only the magnitude - the direction is stored in 'normal'). */
magrelVel = dot_v3v3(relativeVelocity, collpair->normal);
+ const float d = min_distance - collpair->distance;
/* If magrelVel < 0 the edges are approaching each other. */
if (magrelVel > 0.0f) {
@@ -827,8 +829,6 @@ static int cloth_collision_response_static(ClothModifierData *clmd,
}
if (result) {
- float clamp_sq = clmd->coll_parms->clamp * dt;
- clamp_sq *= clamp_sq;
cloth_selfcollision_impulse_vert(clamp_sq, i1, &cloth->verts[collpair->ap1]);
cloth_selfcollision_impulse_vert(clamp_sq, i2, &cloth->verts[collpair->ap2]);
cloth_selfcollision_impulse_vert(clamp_sq, i3, &cloth->verts[collpair->ap3]);
@@ -848,12 +848,13 @@ static int cloth_selfcollision_response_static(ClothModifierData *clmd,
float w1, w2, w3, u1, u2, u3;
float v1[3], v2[3], relativeVelocity[3];
float magrelVel;
+ const float clamp_sq = square_f(clmd->coll_parms->self_clamp * dt);
+ const float time_multiplier = 1.0f / (clmd->sim_parms->dt * clmd->sim_parms->timescale);
+ const float min_distance = (2.0f * clmd->coll_parms->selfepsilon) * (8.0f / 9.0f);
for (int i = 0; i < collision_count; i++, collpair++) {
float ia[3][3] = {{0.0f}};
float ib[3][3] = {{0.0f}};
- float time_multiplier = 1.0f / (clmd->sim_parms->dt * clmd->sim_parms->timescale);
- float d = clmd->coll_parms->selfepsilon * 8.0f / 9.0f * 2.0f - collpair->distance;
/* Only handle static collisions here. */
if (collpair->flag & (COLLISION_IN_FUTURE | COLLISION_INACTIVE)) {
@@ -899,6 +900,7 @@ static int cloth_selfcollision_response_static(ClothModifierData *clmd,
/* Calculate the normal component of the relative velocity
* (actually only the magnitude - the direction is stored in 'normal'). */
magrelVel = dot_v3v3(relativeVelocity, collpair->normal);
+ const float d = min_distance - collpair->distance;
/* TODO: Impulses should be weighed by mass as this is self col,
* this has to be done after mass distribution is implemented. */
@@ -955,7 +957,6 @@ static int cloth_selfcollision_response_static(ClothModifierData *clmd,
}
repulse = max_ff(impulse, repulse);
-
impulse = repulse / 1.5f;
VECADDMUL(ia[0], collpair->normal, w1 * impulse);
@@ -986,9 +987,6 @@ static int cloth_selfcollision_response_static(ClothModifierData *clmd,
}
if (result) {
- float clamp_sq = clmd->coll_parms->self_clamp * dt;
- clamp_sq *= clamp_sq;
-
cloth_selfcollision_impulse_vert(clamp_sq, ia[0], &cloth->verts[collpair->ap1]);
cloth_selfcollision_impulse_vert(clamp_sq, ia[1], &cloth->verts[collpair->ap2]);
cloth_selfcollision_impulse_vert(clamp_sq, ia[2], &cloth->verts[collpair->ap3]);