diff options
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/intern/particle_distribute.c | 28 | ||||
-rw-r--r-- | source/blender/blenlib/intern/system.c | 6 | ||||
-rw-r--r-- | source/blender/depsgraph/DEG_depsgraph.h | 12 | ||||
-rw-r--r-- | source/blender/editors/uvedit/uvedit_parametrizer.c | 2 | ||||
-rw-r--r-- | source/blender/physics/intern/BPH_mass_spring.cpp | 50 | ||||
-rw-r--r-- | source/blender/physics/intern/eigen_utils.h | 10 | ||||
-rw-r--r-- | source/blender/physics/intern/hair_volume.cpp | 232 | ||||
-rw-r--r-- | source/blender/physics/intern/implicit.h | 8 | ||||
-rw-r--r-- | source/blender/physics/intern/implicit_blender.c | 170 | ||||
-rw-r--r-- | source/blender/physics/intern/implicit_eigen.cpp | 68 |
10 files changed, 298 insertions, 288 deletions
diff --git a/source/blender/blenkernel/intern/particle_distribute.c b/source/blender/blenkernel/intern/particle_distribute.c index 8a3b1312590..8b4b39710f8 100644 --- a/source/blender/blenkernel/intern/particle_distribute.c +++ b/source/blender/blenkernel/intern/particle_distribute.c @@ -479,7 +479,7 @@ static void distribute_from_verts_exec(ParticleTask *thread, ParticleData *pa, i int w, maxw; psys_particle_on_dm(ctx->dm,from,pa->num,pa->num_dmcache,pa->fuv,pa->foffset,co1,0,0,0,orco1,0); - BKE_mesh_orco_verts_transform((Mesh*)ob->data, &orco1, 1, 1); + BKE_mesh_orco_verts_transform((Mesh *)ob->data, &orco1, 1, 1); maxw = BLI_kdtree_find_nearest_n(ctx->tree,orco1,ptn,3); for (w=0; w<maxw; w++) { @@ -665,7 +665,7 @@ static void distribute_children_exec(ParticleTask *thread, ChildParticle *cpa, i float pweight[10]; psys_particle_on_dm(dm,cfrom,cpa->num,DMCACHE_ISCHILD,cpa->fuv,cpa->foffset,co1,nor1,NULL,NULL,orco1,NULL); - BKE_mesh_orco_verts_transform((Mesh*)ob->data, &orco1, 1, 1); + BKE_mesh_orco_verts_transform((Mesh *)ob->data, &orco1, 1, 1); maxw = BLI_kdtree_find_nearest_n(ctx->tree,orco1,ptn,3); maxd=ptn[maxw-1].dist; @@ -865,7 +865,7 @@ static int psys_thread_context_init_distribute(ParticleThreadContext *ctx, Parti dm = finaldm; } else { - dm = CDDM_from_mesh((Mesh*)ob->data); + dm = CDDM_from_mesh((Mesh *)ob->data); } DM_ensure_tessface(dm); @@ -894,7 +894,7 @@ static int psys_thread_context_init_distribute(ParticleThreadContext *ctx, Parti for (p=0,pa=psys->particles; p<totpart; p++,pa++) { psys_particle_on_dm(dm,part->from,pa->num,pa->num_dmcache,pa->fuv,pa->foffset,co,nor,0,0,orco,NULL); - BKE_mesh_orco_verts_transform((Mesh*)ob->data, &orco, 1, 1); + BKE_mesh_orco_verts_transform((Mesh *)ob->data, &orco, 1, 1); BLI_kdtree_insert(tree, p, orco); } @@ -910,7 +910,7 @@ static int psys_thread_context_init_distribute(ParticleThreadContext *ctx, Parti if (psys->part->use_modifier_stack) dm = finaldm; else - dm= CDDM_from_mesh((Mesh*)ob->data); + dm= CDDM_from_mesh((Mesh *)ob->data); DM_ensure_tessface(dm); @@ -928,7 +928,7 @@ static int psys_thread_context_init_distribute(ParticleThreadContext *ctx, Parti for (p=0; p<totvert; p++) { if (orcodata) { copy_v3_v3(co,orcodata[p]); - BKE_mesh_orco_verts_transform((Mesh*)ob->data, &co, 1, 1); + BKE_mesh_orco_verts_transform((Mesh *)ob->data, &co, 1, 1); } else copy_v3_v3(co,mv[p].co); @@ -974,23 +974,23 @@ static int psys_thread_context_init_distribute(ParticleThreadContext *ctx, Parti copy_v3_v3(co1, orcodata[mf->v1]); copy_v3_v3(co2, orcodata[mf->v2]); copy_v3_v3(co3, orcodata[mf->v3]); - BKE_mesh_orco_verts_transform((Mesh*)ob->data, &co1, 1, 1); - BKE_mesh_orco_verts_transform((Mesh*)ob->data, &co2, 1, 1); - BKE_mesh_orco_verts_transform((Mesh*)ob->data, &co3, 1, 1); + BKE_mesh_orco_verts_transform((Mesh *)ob->data, &co1, 1, 1); + BKE_mesh_orco_verts_transform((Mesh *)ob->data, &co2, 1, 1); + BKE_mesh_orco_verts_transform((Mesh *)ob->data, &co3, 1, 1); if (mf->v4) { copy_v3_v3(co4, orcodata[mf->v4]); - BKE_mesh_orco_verts_transform((Mesh*)ob->data, &co4, 1, 1); + BKE_mesh_orco_verts_transform((Mesh *)ob->data, &co4, 1, 1); } } else { - v1= (MVert*)dm->getVertData(dm,mf->v1,CD_MVERT); - v2= (MVert*)dm->getVertData(dm,mf->v2,CD_MVERT); - v3= (MVert*)dm->getVertData(dm,mf->v3,CD_MVERT); + v1= (MVert *)dm->getVertData(dm,mf->v1,CD_MVERT); + v2= (MVert *)dm->getVertData(dm,mf->v2,CD_MVERT); + v3= (MVert *)dm->getVertData(dm,mf->v3,CD_MVERT); copy_v3_v3(co1, v1->co); copy_v3_v3(co2, v2->co); copy_v3_v3(co3, v3->co); if (mf->v4) { - v4= (MVert*)dm->getVertData(dm,mf->v4,CD_MVERT); + v4= (MVert *)dm->getVertData(dm,mf->v4,CD_MVERT); copy_v3_v3(co4, v4->co); } } diff --git a/source/blender/blenlib/intern/system.c b/source/blender/blenlib/intern/system.c index 38fe2c7a9eb..fca168dce69 100644 --- a/source/blender/blenlib/intern/system.c +++ b/source/blender/blenlib/intern/system.c @@ -167,9 +167,9 @@ char *BLI_cpu_brand_string(void) int result[4] = { 0 }; __cpuid(result, 0x80000000); if (result[0] >= (int)0x80000004) { - __cpuid((int*)(buf + 0), 0x80000002); - __cpuid((int*)(buf + 16), 0x80000003); - __cpuid((int*)(buf + 32), 0x80000004); + __cpuid((int *)(buf + 0), 0x80000002); + __cpuid((int *)(buf + 16), 0x80000003); + __cpuid((int *)(buf + 32), 0x80000004); char *brand = BLI_strdup(buf); /* TODO(sergey): Make it a bit more presentable by removing trademark. */ return brand; diff --git a/source/blender/depsgraph/DEG_depsgraph.h b/source/blender/depsgraph/DEG_depsgraph.h index d9672732ffc..fd272d7363d 100644 --- a/source/blender/depsgraph/DEG_depsgraph.h +++ b/source/blender/depsgraph/DEG_depsgraph.h @@ -210,9 +210,9 @@ void DEG_editors_update_pre(struct Main *bmain, struct Scene *scene, bool time); /* Evaluation Debug ------------------------------ */ -void DEG_debug_print_eval(const char* function_name, - const char* object_name, - const void* object_address); +void DEG_debug_print_eval(const char *function_name, + const char *object_name, + const void *object_address); void DEG_debug_print_eval_subdata(const char *function_name, const char *object_name, @@ -229,9 +229,9 @@ void DEG_debug_print_eval_subdata_index(const char *function_name, const void *subdata_address, const int subdata_index); -void DEG_debug_print_eval_time(const char* function_name, - const char* object_name, - const void* object_address, +void DEG_debug_print_eval_time(const char *function_name, + const char *object_name, + const void *object_address, float time); #ifdef __cplusplus diff --git a/source/blender/editors/uvedit/uvedit_parametrizer.c b/source/blender/editors/uvedit/uvedit_parametrizer.c index 352bfbf9a9e..412d68a5d4d 100644 --- a/source/blender/editors/uvedit/uvedit_parametrizer.c +++ b/source/blender/editors/uvedit/uvedit_parametrizer.c @@ -4189,7 +4189,7 @@ static void p_add_ngon(ParamHandle *handle, ParamKey key, int nverts, float normal[3]; zero_v3(normal); - const float *co_curr, *co_prev = co[nverts-1]; + const float *co_curr, *co_prev = co[nverts - 1]; for (int j = 0; j < nverts; j++) { co_curr = co[j]; add_newell_cross_v3_v3v3(normal, co_prev, co_curr); diff --git a/source/blender/physics/intern/BPH_mass_spring.cpp b/source/blender/physics/intern/BPH_mass_spring.cpp index 451959766cb..1b8b05ac752 100644 --- a/source/blender/physics/intern/BPH_mass_spring.cpp +++ b/source/blender/physics/intern/BPH_mass_spring.cpp @@ -149,7 +149,7 @@ static bool collision_response(ClothModifierData *clmd, CollisionModifierData *c return false; /* XXX tested before already? */ /* only handle static collisions here */ - if ( collpair->flag & COLLISION_IN_FUTURE ) + if (collpair->flag & COLLISION_IN_FUTURE) return false; /* velocity */ @@ -260,8 +260,8 @@ static void cloth_setup_constraints(ClothModifierData *clmd, ColliderContacts *c * collisions*/ static int UNUSED_FUNCTION(cloth_calc_helper_forces)(Object *UNUSED(ob), ClothModifierData *clmd, float (*initial_cos)[3], float UNUSED(step), float dt) { - Cloth *cloth= clmd->clothObject; - float (*cos)[3] = (float (*)[3])MEM_callocN(sizeof(float[3]) * cloth->mvert_num, "cos cloth_calc_helper_forces"); + Cloth *cloth = clmd->clothObject; + float(*cos)[3] = (float(*)[3])MEM_callocN(sizeof(float[3]) * cloth->mvert_num, "cos cloth_calc_helper_forces"); float *masses = (float *)MEM_callocN(sizeof(float) * cloth->mvert_num, "cos cloth_calc_helper_forces"); LinkNode *node; ClothSpring *spring; @@ -281,8 +281,8 @@ static int UNUSED_FUNCTION(cloth_calc_helper_forces)(Object *UNUSED(ob), ClothMo } steps = 55; - for (i=0; i<steps; i++) { - for (node=cloth->springs; node; node=node->next) { + for (i = 0; i < steps; i++) { + for (node = cloth->springs; node; node = node->next) { /* ClothVertex *cv1, *cv2; */ /* UNUSED */ int v1, v2; float len, c, l, vec[3]; @@ -322,7 +322,7 @@ static int UNUSED_FUNCTION(cloth_calc_helper_forces)(Object *UNUSED(ob), ClothMo /*compute forces*/ sub_v3_v3v3(vec, cos[i], cv->tx); - mul_v3_fl(vec, cv->mass*dt*20.0f); + mul_v3_fl(vec, cv->mass * dt * 20.0f); add_v3_v3(cv->tv, vec); //copy_v3_v3(cv->tx, cos[i]); } @@ -438,10 +438,10 @@ static void cloth_calc_force(ClothModifierData *clmd, float UNUSED(frame), ListB /* Collect forces and derivatives: F, dFdX, dFdV */ Cloth *cloth = clmd->clothObject; Implicit_Data *data = cloth->implicit; - unsigned int i = 0; - float drag = clmd->sim_parms->Cvi * 0.01f; /* viscosity of air scaled in percent */ - float gravity[3] = {0.0f, 0.0f, 0.0f}; - const MVertTri *tri = cloth->tri; + unsigned int i = 0; + float drag = clmd->sim_parms->Cvi * 0.01f; /* viscosity of air scaled in percent */ + float gravity[3] = {0.0f, 0.0f, 0.0f}; + const MVertTri *tri = cloth->tri; unsigned int mvert_num = cloth->mvert_num; ClothVertex *vert; @@ -481,7 +481,7 @@ static void cloth_calc_force(ClothModifierData *clmd, float UNUSED(frame), ListB /* handle external forces like wind */ if (effectors) { /* cache per-vertex forces to avoid redundant calculation */ - float (*winvec)[3] = (float (*)[3])MEM_callocN(sizeof(float[3]) * mvert_num, "effector forces"); + float(*winvec)[3] = (float(*)[3])MEM_callocN(sizeof(float[3]) * mvert_num, "effector forces"); for (i = 0; i < cloth->mvert_num; i++) { float x[3], v[3]; EffectedPoint epoint; @@ -526,8 +526,8 @@ static void cloth_calc_force(ClothModifierData *clmd, float UNUSED(frame), ListB else BPH_mass_spring_force_vertex_wind(data, i, 1.0f, winvec); } - } #endif + } MEM_freeN(winvec); } @@ -576,7 +576,7 @@ BLI_INLINE LinkNode *hair_spring_next(LinkNode *spring_link) static LinkNode *cloth_continuum_add_hair_segments(HairGrid *grid, const float cell_scale, const float cell_offset[3], Cloth *cloth, LinkNode *spring_link) { Implicit_Data *data = cloth->implicit; - LinkNode *next_spring_link = NULL; /* return value */ + LinkNode *next_spring_link = NULL; /* return value */ ClothSpring *spring1, *spring2, *spring3; // ClothVertex *verts = cloth->verts; // ClothVertex *vert3, *vert4; @@ -686,7 +686,7 @@ static void cloth_continuum_step(ClothModifierData *clmd, float dt) int mvert_num = cloth->mvert_num; ClothVertex *vert; - const float fluid_factor = 0.95f; /* blend between PIC and FLIP methods */ + const float fluid_factor = 0.95f; /* blend between PIC and FLIP methods */ float smoothfac = parms->velocity_smooth; /* XXX FIXME arbitrary factor!!! this should be based on some intuitive value instead, * like number of hairs per cell and time decay instead of "strength" @@ -744,16 +744,16 @@ static void cloth_continuum_step(ClothModifierData *clmd, float dt) zero_v3(b); offset[axis] = shift * clmd->hair_grid_cellsize; - a[(axis+1) % 3] = clmd->hair_grid_max[(axis+1) % 3] - clmd->hair_grid_min[(axis+1) % 3]; - b[(axis+2) % 3] = clmd->hair_grid_max[(axis+2) % 3] - clmd->hair_grid_min[(axis+2) % 3]; + a[(axis + 1) % 3] = clmd->hair_grid_max[(axis + 1) % 3] - clmd->hair_grid_min[(axis + 1) % 3]; + b[(axis + 2) % 3] = clmd->hair_grid_max[(axis + 2) % 3] - clmd->hair_grid_min[(axis + 2) % 3]; BKE_sim_debug_data_clear_category(clmd->debug_data, "grid velocity"); for (j = 0; j < size; ++j) { for (i = 0; i < size; ++i) { float x[3], v[3], gvel[3], gvel_smooth[3], gdensity; - madd_v3_v3v3fl(x, offset, a, (float)i / (float)(size-1)); - madd_v3_v3fl(x, b, (float)j / (float)(size-1)); + madd_v3_v3v3fl(x, offset, a, (float)i / (float)(size - 1)); + madd_v3_v3fl(x, b, (float)j / (float)(size - 1)); zero_v3(v); BPH_hair_volume_grid_interpolate(grid, x, &gdensity, gvel, gvel_smooth, NULL, NULL); @@ -872,7 +872,7 @@ static void cloth_collision_solve_extra(Object *ob, ClothModifierData *clmd, Lis } #if 0 /* unused */ - for (i=0, cv=cloth->verts; i<cloth->mvert_num; i++, cv++) { + for (i = 0, cv = cloth->verts; i < cloth->mvert_num; i++, cv++) { copy_v3_v3(initial_cos[i], cv->tx); } #endif @@ -896,7 +896,7 @@ static void cloth_collision_solve_extra(Object *ob, ClothModifierData *clmd, Lis float newv[3]; - if ((clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_GOAL) && (verts [i].flags & CLOTH_VERT_FLAG_PINNED)) + if ((clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_GOAL) && (verts[i].flags & CLOTH_VERT_FLAG_PINNED)) continue; BPH_mass_spring_set_new_position(id, i, verts[i].tx); @@ -941,7 +941,7 @@ static void cloth_record_result(ClothModifierData *clmd, ImplicitSolverResult *r { ClothSolverResult *sres = clmd->solver_result; - if (sres->status) { /* already initialized ? */ + if (sres->status) { /* already initialized ? */ /* error only makes sense for successful iterations */ if (result->status == BPH_SOLVER_SUCCESS) { sres->min_error = min_ff(sres->min_error, result->error); @@ -975,10 +975,10 @@ int BPH_cloth_solve(Object *ob, float frame, ClothModifierData *clmd, ListBase * */ const bool is_hair = (clmd->hairdata != NULL); - unsigned int i=0; - float step=0.0f, tf=clmd->sim_parms->timescale; + unsigned int i = 0; + float step = 0.0f, tf = clmd->sim_parms->timescale; Cloth *cloth = clmd->clothObject; - ClothVertex *verts = cloth->verts/*, *cv*/; + ClothVertex *verts = cloth->verts /*, *cv*/; unsigned int mvert_num = cloth->mvert_num; float dt = clmd->sim_parms->timescale / clmd->sim_parms->stepsPerFrame; Implicit_Data *id = cloth->implicit; @@ -991,7 +991,7 @@ int BPH_cloth_solve(Object *ob, float frame, ClothModifierData *clmd, ListBase * clmd->solver_result = (ClothSolverResult *)MEM_callocN(sizeof(ClothSolverResult), "cloth solver result"); cloth_clear_result(clmd); - if (clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_GOAL) { /* do goal stuff */ + if (clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_GOAL) { /* do goal stuff */ for (i = 0; i < mvert_num; i++) { // update velocities with constrained velocities from pinned verts if (verts[i].flags & CLOTH_VERT_FLAG_PINNED) { diff --git a/source/blender/physics/intern/eigen_utils.h b/source/blender/physics/intern/eigen_utils.h index 4598d3ad3a7..511e2cea3b1 100644 --- a/source/blender/physics/intern/eigen_utils.h +++ b/source/blender/physics/intern/eigen_utils.h @@ -67,7 +67,7 @@ public: coeffRef(k) = v[k]; } - Vector3& operator = (const ctype &v) + Vector3& operator =(const ctype &v) { for (int k = 0; k < 3; ++k) coeffRef(k) = v[k]; @@ -98,7 +98,7 @@ public: coeffRef(l, k) = v[k][l]; } - Matrix3& operator = (const ctype &v) + Matrix3& operator =(const ctype &v) { for (int k = 0; k < 3; ++k) for (int l = 0; l < 3; ++l) @@ -126,18 +126,18 @@ public: } template <typename T> - lVector3f& operator = (T rhs) + lVector3f& operator =(T rhs) { base_t::operator=(rhs); return *this; } - float* v3(int vertex) + float *v3(int vertex) { return &coeffRef(3 * vertex); } - const float* v3(int vertex) const + const float *v3(int vertex) const { return &coeffRef(3 * vertex); } diff --git a/source/blender/physics/intern/hair_volume.cpp b/source/blender/physics/intern/hair_volume.cpp index cd869046cc1..8496d95855d 100644 --- a/source/blender/physics/intern/hair_volume.cpp +++ b/source/blender/physics/intern/hair_volume.cpp @@ -93,7 +93,7 @@ typedef struct HairGrid { float cellsize, inv_cellsize; } HairGrid; -#define HAIR_GRID_INDEX_AXIS(vec, res, gmin, scale, axis) ( min_ii( max_ii( (int)((vec[axis] - gmin[axis]) * scale), 0), res[axis]-2 ) ) +#define HAIR_GRID_INDEX_AXIS(vec, res, gmin, scale, axis) (min_ii(max_ii( (int)((vec[axis] - gmin[axis]) * scale), 0), res[axis] - 2) ) BLI_INLINE int hair_grid_offset(const float vec[3], const int res[3], const float gmin[3], float scale) { @@ -101,7 +101,7 @@ BLI_INLINE int hair_grid_offset(const float vec[3], const int res[3], const floa i = HAIR_GRID_INDEX_AXIS(vec, res, gmin, scale, 0); j = HAIR_GRID_INDEX_AXIS(vec, res, gmin, scale, 1); k = HAIR_GRID_INDEX_AXIS(vec, res, gmin, scale, 2); - return i + (j + k*res[1])*res[0]; + return i + (j + k * res[1]) * res[0]; } BLI_INLINE int hair_grid_interp_weights(const int res[3], const float gmin[3], float scale, const float vec[3], float uvw[3]) @@ -111,7 +111,7 @@ BLI_INLINE int hair_grid_interp_weights(const int res[3], const float gmin[3], f i = HAIR_GRID_INDEX_AXIS(vec, res, gmin, scale, 0); j = HAIR_GRID_INDEX_AXIS(vec, res, gmin, scale, 1); k = HAIR_GRID_INDEX_AXIS(vec, res, gmin, scale, 2); - offset = i + (j + k*res[1])*res[0]; + offset = i + (j + k * res[1]) * res[0]; uvw[0] = (vec[0] - gmin[0]) * scale - (float)i; uvw[1] = (vec[1] - gmin[1]) * scale - (float)j; @@ -124,8 +124,9 @@ BLI_INLINE int hair_grid_interp_weights(const int res[3], const float gmin[3], f return offset; } -BLI_INLINE void hair_grid_interpolate(const HairGridVert *grid, const int res[3], const float gmin[3], float scale, const float vec[3], - float *density, float velocity[3], float vel_smooth[3], float density_gradient[3], float velocity_gradient[3][3]) +BLI_INLINE void hair_grid_interpolate( + const HairGridVert *grid, const int res[3], const float gmin[3], float scale, const float vec[3], + float *density, float velocity[3], float vel_smooth[3], float density_gradient[3], float velocity_gradient[3][3]) { HairGridVert data[8]; float uvw[3], muvw[3]; @@ -137,57 +138,57 @@ BLI_INLINE void hair_grid_interpolate(const HairGridVert *grid, const int res[3] muvw[1] = 1.0f - uvw[1]; muvw[2] = 1.0f - uvw[2]; - data[0] = grid[offset ]; - data[1] = grid[offset +1]; - data[2] = grid[offset +res[0] ]; - data[3] = grid[offset +res[0]+1]; - data[4] = grid[offset+res2 ]; - data[5] = grid[offset+res2 +1]; - data[6] = grid[offset+res2+res[0] ]; - data[7] = grid[offset+res2+res[0]+1]; + data[0] = grid[offset ]; + data[1] = grid[offset + 1]; + data[2] = grid[offset + res[0] ]; + data[3] = grid[offset + res[0] + 1]; + data[4] = grid[offset + res2 ]; + data[5] = grid[offset + res2 + 1]; + data[6] = grid[offset + res2 + res[0] ]; + data[7] = grid[offset + res2 + res[0] + 1]; if (density) { - *density = muvw[2]*( muvw[1]*( muvw[0]*data[0].density + uvw[0]*data[1].density ) + - uvw[1]*( muvw[0]*data[2].density + uvw[0]*data[3].density ) ) + - uvw[2]*( muvw[1]*( muvw[0]*data[4].density + uvw[0]*data[5].density ) + - uvw[1]*( muvw[0]*data[6].density + uvw[0]*data[7].density ) ); + *density = muvw[2] * (muvw[1] * (muvw[0] * data[0].density + uvw[0] * data[1].density) + + uvw[1] * (muvw[0] * data[2].density + uvw[0] * data[3].density)) + + uvw[2] * (muvw[1] * (muvw[0] * data[4].density + uvw[0] * data[5].density) + + uvw[1] * (muvw[0] * data[6].density + uvw[0] * data[7].density)); } if (velocity) { int k; for (k = 0; k < 3; ++k) { - velocity[k] = muvw[2]*( muvw[1]*( muvw[0]*data[0].velocity[k] + uvw[0]*data[1].velocity[k] ) + - uvw[1]*( muvw[0]*data[2].velocity[k] + uvw[0]*data[3].velocity[k] ) ) + - uvw[2]*( muvw[1]*( muvw[0]*data[4].velocity[k] + uvw[0]*data[5].velocity[k] ) + - uvw[1]*( muvw[0]*data[6].velocity[k] + uvw[0]*data[7].velocity[k] ) ); + velocity[k] = muvw[2] * (muvw[1] * (muvw[0] * data[0].velocity[k] + uvw[0] * data[1].velocity[k]) + + uvw[1] * (muvw[0] * data[2].velocity[k] + uvw[0] * data[3].velocity[k]) ) + + uvw[2] * (muvw[1] * (muvw[0] * data[4].velocity[k] + uvw[0] * data[5].velocity[k]) + + uvw[1] * (muvw[0] * data[6].velocity[k] + uvw[0] * data[7].velocity[k]) ); } } if (vel_smooth) { int k; for (k = 0; k < 3; ++k) { - vel_smooth[k] = muvw[2]*( muvw[1]*( muvw[0]*data[0].velocity_smooth[k] + uvw[0]*data[1].velocity_smooth[k] ) + - uvw[1]*( muvw[0]*data[2].velocity_smooth[k] + uvw[0]*data[3].velocity_smooth[k] ) ) + - uvw[2]*( muvw[1]*( muvw[0]*data[4].velocity_smooth[k] + uvw[0]*data[5].velocity_smooth[k] ) + - uvw[1]*( muvw[0]*data[6].velocity_smooth[k] + uvw[0]*data[7].velocity_smooth[k] ) ); + vel_smooth[k] = muvw[2] * (muvw[1] * (muvw[0] * data[0].velocity_smooth[k] + uvw[0] * data[1].velocity_smooth[k]) + + uvw[1] * (muvw[0] * data[2].velocity_smooth[k] + uvw[0] * data[3].velocity_smooth[k]) ) + + uvw[2] * (muvw[1] * (muvw[0] * data[4].velocity_smooth[k] + uvw[0] * data[5].velocity_smooth[k]) + + uvw[1] * (muvw[0] * data[6].velocity_smooth[k] + uvw[0] * data[7].velocity_smooth[k]) ); } } if (density_gradient) { - density_gradient[0] = muvw[1] * muvw[2] * ( data[0].density - data[1].density ) + - uvw[1] * muvw[2] * ( data[2].density - data[3].density ) + - muvw[1] * uvw[2] * ( data[4].density - data[5].density ) + - uvw[1] * uvw[2] * ( data[6].density - data[7].density ); - - density_gradient[1] = muvw[2] * muvw[0] * ( data[0].density - data[2].density ) + - uvw[2] * muvw[0] * ( data[4].density - data[6].density ) + - muvw[2] * uvw[0] * ( data[1].density - data[3].density ) + - uvw[2] * uvw[0] * ( data[5].density - data[7].density ); - - density_gradient[2] = muvw[2] * muvw[0] * ( data[0].density - data[4].density ) + - uvw[2] * muvw[0] * ( data[1].density - data[5].density ) + - muvw[2] * uvw[0] * ( data[2].density - data[6].density ) + - uvw[2] * uvw[0] * ( data[3].density - data[7].density ); + density_gradient[0] = muvw[1] * muvw[2] * (data[0].density - data[1].density) + + uvw[1] * muvw[2] * (data[2].density - data[3].density) + + muvw[1] * uvw[2] * (data[4].density - data[5].density) + + uvw[1] * uvw[2] * (data[6].density - data[7].density); + + density_gradient[1] = muvw[2] * muvw[0] * (data[0].density - data[2].density) + + uvw[2] * muvw[0] * (data[4].density - data[6].density) + + muvw[2] * uvw[0] * (data[1].density - data[3].density) + + uvw[2] * uvw[0] * (data[5].density - data[7].density); + + density_gradient[2] = muvw[2] * muvw[0] * (data[0].density - data[4].density) + + uvw[2] * muvw[0] * (data[1].density - data[5].density) + + muvw[2] * uvw[0] * (data[2].density - data[6].density) + + uvw[2] * uvw[0] * (data[3].density - data[7].density); } if (velocity_gradient) { @@ -196,9 +197,10 @@ BLI_INLINE void hair_grid_interpolate(const HairGridVert *grid, const int res[3] } } -void BPH_hair_volume_vertex_grid_forces(HairGrid *grid, const float x[3], const float v[3], - float smoothfac, float pressurefac, float minpressure, - float f[3], float dfdx[3][3], float dfdv[3][3]) +void BPH_hair_volume_vertex_grid_forces( + HairGrid *grid, const float x[3], const float v[3], + float smoothfac, float pressurefac, float minpressure, + float f[3], float dfdx[3][3], float dfdv[3][3]) { float gdensity, gvelocity[3], ggrad[3], gvelgrad[3][3], gradlen; @@ -220,15 +222,17 @@ void BPH_hair_volume_vertex_grid_forces(HairGrid *grid, const float x[3], const mul_m3_fl(dfdv, smoothfac); } -void BPH_hair_volume_grid_interpolate(HairGrid *grid, const float x[3], - float *density, float velocity[3], float velocity_smooth[3], float density_gradient[3], float velocity_gradient[3][3]) +void BPH_hair_volume_grid_interpolate( + HairGrid *grid, const float x[3], + float *density, float velocity[3], float velocity_smooth[3], float density_gradient[3], float velocity_gradient[3][3]) { hair_grid_interpolate(grid->verts, grid->res, grid->gmin, grid->inv_cellsize, x, density, velocity, velocity_smooth, density_gradient, velocity_gradient); } -void BPH_hair_volume_grid_velocity(HairGrid *grid, const float x[3], const float v[3], - float fluid_factor, - float r_v[3]) +void BPH_hair_volume_grid_velocity( + HairGrid *grid, const float x[3], const float v[3], + float fluid_factor, + float r_v[3]) { float gdensity, gvelocity[3], gvel_smooth[3], ggrad[3], gvelgrad[3][3]; float v_pic[3], v_flip[3]; @@ -287,20 +291,20 @@ BLI_INLINE int hair_grid_weights(const int res[3], const float gmin[3], float sc i = HAIR_GRID_INDEX_AXIS(vec, res, gmin, scale, 0); j = HAIR_GRID_INDEX_AXIS(vec, res, gmin, scale, 1); k = HAIR_GRID_INDEX_AXIS(vec, res, gmin, scale, 2); - offset = i + (j + k*res[1])*res[0]; + offset = i + (j + k * res[1]) * res[0]; uvw[0] = (vec[0] - gmin[0]) * scale; uvw[1] = (vec[1] - gmin[1]) * scale; uvw[2] = (vec[2] - gmin[2]) * scale; - weights[0] = dist_tent_v3f3(uvw, (float)i , (float)j , (float)k ); - weights[1] = dist_tent_v3f3(uvw, (float)(i+1), (float)j , (float)k ); - weights[2] = dist_tent_v3f3(uvw, (float)i , (float)(j+1), (float)k ); - weights[3] = dist_tent_v3f3(uvw, (float)(i+1), (float)(j+1), (float)k ); - weights[4] = dist_tent_v3f3(uvw, (float)i , (float)j , (float)(k+1)); - weights[5] = dist_tent_v3f3(uvw, (float)(i+1), (float)j , (float)(k+1)); - weights[6] = dist_tent_v3f3(uvw, (float)i , (float)(j+1), (float)(k+1)); - weights[7] = dist_tent_v3f3(uvw, (float)(i+1), (float)(j+1), (float)(k+1)); + weights[0] = dist_tent_v3f3(uvw, (float)i , (float)j , (float)k ); + weights[1] = dist_tent_v3f3(uvw, (float)(i + 1), (float)j , (float)k ); + weights[2] = dist_tent_v3f3(uvw, (float)i , (float)(j + 1), (float)k ); + weights[3] = dist_tent_v3f3(uvw, (float)(i + 1), (float)(j + 1), (float)k ); + weights[4] = dist_tent_v3f3(uvw, (float)i , (float)j , (float)(k + 1)); + weights[5] = dist_tent_v3f3(uvw, (float)(i + 1), (float)j , (float)(k + 1)); + weights[6] = dist_tent_v3f3(uvw, (float)i , (float)(j + 1), (float)(k + 1)); + weights[7] = dist_tent_v3f3(uvw, (float)(i + 1), (float)(j + 1), (float)(k + 1)); // BLI_assert(fabsf(weights_sum(weights) - 1.0f) < 0.0001f); @@ -329,8 +333,8 @@ void BPH_hair_volume_add_vertex(HairGrid *grid, const float x[3], const float v[ for (di = 0; di < 2; ++di) { for (dj = 0; dj < 2; ++dj) { for (dk = 0; dk < 2; ++dk) { - int voffset = offset + di + (dj + dk*res[1])*res[0]; - int iw = di + dj*2 + dk*4; + int voffset = offset + di + (dj + dk * res[1]) * res[0]; + int iw = di + dj * 2 + dk * 4; grid->verts[voffset].density += weights[iw]; madd_v3_v3fl(grid->verts[voffset].velocity, v, weights[iw]); @@ -340,8 +344,9 @@ void BPH_hair_volume_add_vertex(HairGrid *grid, const float x[3], const float v[ } #if 0 -BLI_INLINE void hair_volume_eval_grid_vertex(HairGridVert *vert, const float loc[3], float radius, float dist_scale, - const float x2[3], const float v2[3], const float x3[3], const float v3[3]) +BLI_INLINE void hair_volume_eval_grid_vertex( + HairGridVert *vert, const float loc[3], float radius, float dist_scale, + const float x2[3], const float v2[3], const float x3[3], const float v3[3]) { float closest[3], lambda, dist, weight; @@ -368,13 +373,14 @@ BLI_INLINE int major_axis_v3(const float v[3]) return a > b ? (a > c ? 0 : 2) : (b > c ? 1 : 2); } -BLI_INLINE void hair_volume_add_segment_2D(HairGrid *grid, - const float UNUSED(x1[3]), const float UNUSED(v1[3]), const float x2[3], const float v2[3], - const float x3[3], const float v3[3], const float UNUSED(x4[3]), const float UNUSED(v4[3]), - const float UNUSED(dir1[3]), const float dir2[3], const float UNUSED(dir3[3]), - int resj, int resk, int jmin, int jmax, int kmin, int kmax, - HairGridVert *vert, int stride_j, int stride_k, const float loc[3], int axis_j, int axis_k, - int debug_i) +BLI_INLINE void hair_volume_add_segment_2D( + HairGrid *grid, + const float UNUSED(x1[3]), const float UNUSED(v1[3]), const float x2[3], const float v2[3], + const float x3[3], const float v3[3], const float UNUSED(x4[3]), const float UNUSED(v4[3]), + const float UNUSED(dir1[3]), const float dir2[3], const float UNUSED(dir3[3]), + int resj, int resk, int jmin, int jmax, int kmin, int kmax, + HairGridVert *vert, int stride_j, int stride_k, const float loc[3], int axis_j, int axis_k, + int debug_i) { const float radius = 1.5f; const float dist_scale = grid->inv_cellsize; @@ -383,9 +389,9 @@ BLI_INLINE void hair_volume_add_segment_2D(HairGrid *grid, /* boundary checks to be safe */ CLAMP_MIN(jmin, 0); - CLAMP_MAX(jmax, resj-1); + CLAMP_MAX(jmax, resj - 1); CLAMP_MIN(kmin, 0); - CLAMP_MAX(kmax, resk-1); + CLAMP_MAX(kmax, resk - 1); HairGridVert *vert_j = vert + jmin * stride_j; float loc_j[3] = { loc[0], loc[1], loc[2] }; @@ -429,10 +435,11 @@ BLI_INLINE void hair_volume_add_segment_2D(HairGrid *grid, * * */ -void BPH_hair_volume_add_segment(HairGrid *grid, - const float x1[3], const float v1[3], const float x2[3], const float v2[3], - const float x3[3], const float v3[3], const float x4[3], const float v4[3], - const float dir1[3], const float dir2[3], const float dir3[3]) +void BPH_hair_volume_add_segment( + HairGrid *grid, + const float x1[3], const float v1[3], const float x2[3], const float v2[3], + const float x3[3], const float v3[3], const float x4[3], const float v4[3], + const float dir1[3], const float dir2[3], const float dir3[3]) { const int res[3] = { grid->res[0], grid->res[1], grid->res[2] }; @@ -461,7 +468,7 @@ void BPH_hair_volume_add_segment(HairGrid *grid, /* range along primary direction */ const int imin = max_ii(floor_int(start[axis0]) - 1, 0); - const int imax = min_ii(floor_int(end[axis0]) + 2, res[axis0]-1); + const int imax = min_ii(floor_int(end[axis0]) + 2, res[axis0] - 1); float h = 0.0f; HairGridVert *vert0; @@ -500,15 +507,17 @@ void BPH_hair_volume_add_segment(HairGrid *grid, loc0[axis1] = 0.0f; loc0[axis2] = 0.0f; - hair_volume_add_segment_2D(grid, x1, v1, x2, v2, x3, v3, x4, v4, dir1, dir2, dir3, - res[axis1], res[axis2], jmin-1, jmax+2, kmin-1, kmax+2, - vert0, stride1, stride2, loc0, axis1, axis2, - i); + hair_volume_add_segment_2D( + grid, x1, v1, x2, v2, x3, v3, x4, v4, dir1, dir2, dir3, + res[axis1], res[axis2], jmin - 1, jmax + 2, kmin - 1, kmax + 2, + vert0, stride1, stride2, loc0, axis1, axis2, + i); } } #else -BLI_INLINE void hair_volume_eval_grid_vertex_sample(HairGridVert *vert, const float loc[3], float radius, float dist_scale, - const float x[3], const float v[3]) +BLI_INLINE void hair_volume_eval_grid_vertex_sample( + HairGridVert *vert, const float loc[3], float radius, float dist_scale, + const float x[3], const float v[3]) { float dist, weight; @@ -526,10 +535,11 @@ BLI_INLINE void hair_volume_eval_grid_vertex_sample(HairGridVert *vert, const fl /* XXX simplified test implementation using a series of discrete sample along the segment, * instead of finding the closest point for all affected grid vertices. */ -void BPH_hair_volume_add_segment(HairGrid *grid, - const float UNUSED(x1[3]), const float UNUSED(v1[3]), const float x2[3], const float v2[3], - const float x3[3], const float v3[3], const float UNUSED(x4[3]), const float UNUSED(v4[3]), - const float UNUSED(dir1[3]), const float UNUSED(dir2[3]), const float UNUSED(dir3[3])) +void BPH_hair_volume_add_segment( + HairGrid *grid, + const float UNUSED(x1[3]), const float UNUSED(v1[3]), const float x2[3], const float v2[3], + const float x3[3], const float v3[3], const float UNUSED(x4[3]), const float UNUSED(v4[3]), + const float UNUSED(dir1[3]), const float UNUSED(dir2[3]), const float UNUSED(dir3[3])) { const float radius = 1.5f; const float dist_scale = grid->inv_cellsize; @@ -544,16 +554,16 @@ void BPH_hair_volume_add_segment(HairGrid *grid, float x[3], v[3]; int i, j, k; - float f = (float)s / (float)(num_samples-1); + float f = (float)s / (float)(num_samples - 1); interp_v3_v3v3(x, x2, x3, f); interp_v3_v3v3(v, v2, v3, f); int imin = max_ii(floor_int(x[0]) - 2, 0); - int imax = min_ii(floor_int(x[0]) + 2, res[0]-1); + int imax = min_ii(floor_int(x[0]) + 2, res[0] - 1); int jmin = max_ii(floor_int(x[1]) - 2, 0); - int jmax = min_ii(floor_int(x[1]) + 2, res[1]-1); + int jmax = min_ii(floor_int(x[1]) + 2, res[1] - 1); int kmin = max_ii(floor_int(x[2]) - 2, 0); - int kmax = min_ii(floor_int(x[2]) + 2, res[2]-1); + int kmax = min_ii(floor_int(x[2]) + 2, res[2] - 1); for (k = kmin; k <= kmax; ++k) { for (j = jmin; j <= jmax; ++j) { @@ -576,7 +586,7 @@ void BPH_hair_volume_normalize_vertex_grid(HairGrid *grid) for (i = 0; i < size; i++) { float density = grid->verts[i].density; if (density > 0.0f) - mul_v3_fl(grid->verts[i].velocity, 1.0f/density); + mul_v3_fl(grid->verts[i].velocity, 1.0f / density); } } @@ -620,16 +630,16 @@ bool BPH_hair_volume_solve_divergence(HairGrid *grid, float /*dt*/, float target #define MARGIN_i0 (i < 1) #define MARGIN_j0 (j < 1) #define MARGIN_k0 (k < 1) -#define MARGIN_i1 (i >= resA[0]-1) -#define MARGIN_j1 (j >= resA[1]-1) -#define MARGIN_k1 (k >= resA[2]-1) +#define MARGIN_i1 (i >= resA[0] - 1) +#define MARGIN_j1 (j >= resA[1] - 1) +#define MARGIN_k1 (k >= resA[2] - 1) #define NEIGHBOR_MARGIN_i0 (i < 2) #define NEIGHBOR_MARGIN_j0 (j < 2) #define NEIGHBOR_MARGIN_k0 (k < 2) -#define NEIGHBOR_MARGIN_i1 (i >= resA[0]-2) -#define NEIGHBOR_MARGIN_j1 (j >= resA[1]-2) -#define NEIGHBOR_MARGIN_k1 (k >= resA[2]-2) +#define NEIGHBOR_MARGIN_i1 (i >= resA[0] - 2) +#define NEIGHBOR_MARGIN_j1 (j >= resA[1] - 2) +#define NEIGHBOR_MARGIN_k1 (k >= resA[2] - 2) BLI_assert(num_cells >= 1); @@ -895,18 +905,18 @@ BLI_INLINE void hair_volume_filter_box_convolute(HairVertexGrid *grid, float inv { int res = grid->res; int p, q, r; - int minp = max_ii(i - kernel_size[0], 0), maxp = min_ii(i + kernel_size[0], res-1); - int minq = max_ii(j - kernel_size[1], 0), maxq = min_ii(j + kernel_size[1], res-1); - int minr = max_ii(k - kernel_size[2], 0), maxr = min_ii(k + kernel_size[2], res-1); + int minp = max_ii(i - kernel_size[0], 0), maxp = min_ii(i + kernel_size[0], res - 1); + int minq = max_ii(j - kernel_size[1], 0), maxq = min_ii(j + kernel_size[1], res - 1); + int minr = max_ii(k - kernel_size[2], 0), maxr = min_ii(k + kernel_size[2], res - 1); int offset, kernel_offset, kernel_dq, kernel_dr; HairGridVert *verts; float *vel_smooth; - offset = i + (j + k*res)*res; + offset = i + (j + k * res) * res; verts = grid->verts; vel_smooth = verts[offset].velocity_smooth; - kernel_offset = minp + (minq + minr*res)*res; + kernel_offset = minp + (minq + minr * res) * res; kernel_dq = res; kernel_dr = res * res; for (r = minr; r <= maxr; ++r) { @@ -935,7 +945,7 @@ void BPH_hair_volume_vertex_grid_filter_box(HairVertexGrid *grid, int kernel_siz return; tot = kernel_size * 2 + 1; - invD = 1.0f / (float)(tot*tot*tot); + invD = 1.0f / (float)(tot * tot * tot); /* clear values for convolution */ for (i = 0; i < size; ++i) { @@ -1039,8 +1049,8 @@ static HairGridVert *hair_volume_create_collision_grid(ClothModifierData *clmd, float gmin[3], gmax[3], scale[3]; /* 2.0f is an experimental value that seems to give good results */ float collfac = 2.0f * clmd->sim_parms->collider_friction; - unsigned int v = 0; - int i = 0; + unsigned int v = 0; + int i = 0; hair_volume_get_boundbox(lX, numverts, gmin, gmax); hair_grid_get_scale(res, gmin, gmax, scale); @@ -1063,7 +1073,7 @@ static HairGridVert *hair_volume_create_collision_grid(ClothModifierData *clmd, float weights[8]; int di, dj, dk; - for (v=0; v < col->collmd->numverts; v++, loc0++, loc1++) { + for (v = 0; v < col->collmd->numverts; v++, loc0++, loc1++) { int offset; if (!hair_grid_point_valid(loc1->co, gmin, gmax)) @@ -1076,8 +1086,8 @@ static HairGridVert *hair_volume_create_collision_grid(ClothModifierData *clmd, for (di = 0; di < 2; ++di) { for (dj = 0; dj < 2; ++dj) { for (dk = 0; dk < 2; ++dk) { - int voffset = offset + di + (dj + dk*res)*res; - int iw = di + dj*2 + dk*4; + int voffset = offset + di + (dj + dk * res) * res; + int iw = di + dj * 2 + dk * 4; collgrid[voffset].density += weights[iw]; madd_v3_v3fl(collgrid[voffset].velocity, vel, weights[iw]); @@ -1093,7 +1103,7 @@ static HairGridVert *hair_volume_create_collision_grid(ClothModifierData *clmd, for (i = 0; i < size; i++) { float density = collgrid[i].density; if (density > 0.0f) - mul_v3_fl(collgrid[i].velocity, 1.0f/density); + mul_v3_fl(collgrid[i].velocity, 1.0f / density); } return collgrid; @@ -1134,10 +1144,10 @@ bool BPH_hair_volume_get_texture_data(HairGrid *grid, VoxelData *vd) break; case TEX_VD_HAIRVELOCITY: { - vd->dataset[i + 0*totres] = grid->verts[i].velocity[0]; - vd->dataset[i + 1*totres] = grid->verts[i].velocity[1]; - vd->dataset[i + 2*totres] = grid->verts[i].velocity[2]; - vd->dataset[i + 3*totres] = len_v3(grid->verts[i].velocity); + vd->dataset[i + 0 * totres] = grid->verts[i].velocity[0]; + vd->dataset[i + 1 * totres] = grid->verts[i].velocity[1]; + vd->dataset[i + 2 * totres] = grid->verts[i].velocity[2]; + vd->dataset[i + 3 * totres] = len_v3(grid->verts[i].velocity); break; } case TEX_VD_HAIRENERGY: diff --git a/source/blender/physics/intern/implicit.h b/source/blender/physics/intern/implicit.h index e2ac6c306b6..477bc704aff 100644 --- a/source/blender/physics/intern/implicit.h +++ b/source/blender/physics/intern/implicit.h @@ -69,7 +69,7 @@ typedef struct ImplicitSolverResult { BLI_INLINE void implicit_print_matrix_elem(float v) { - printf("%-8.3f", v); + printf("%-8.3f", v); } void BPH_mass_spring_set_vertex_mass(struct Implicit_Data *data, int index, float mass); @@ -107,11 +107,11 @@ void BPH_mass_spring_force_drag(struct Implicit_Data *data, float drag); /* Custom external force */ void BPH_mass_spring_force_extern(struct Implicit_Data *data, int i, const float f[3], float dfdx[3][3], float dfdv[3][3]); /* Wind force, acting on a face */ -void BPH_mass_spring_force_face_wind(struct Implicit_Data *data, int v1, int v2, int v3, const float (*winvec)[3]); +void BPH_mass_spring_force_face_wind(struct Implicit_Data *data, int v1, int v2, int v3, const float(*winvec)[3]); /* Wind force, acting on an edge */ -void BPH_mass_spring_force_edge_wind(struct Implicit_Data *data, int v1, int v2, float radius1, float radius2, const float (*winvec)[3]); +void BPH_mass_spring_force_edge_wind(struct Implicit_Data *data, int v1, int v2, float radius1, float radius2, const float(*winvec)[3]); /* Wind force, acting on a vertex */ -void BPH_mass_spring_force_vertex_wind(struct Implicit_Data *data, int v, float radius, const float (*winvec)[3]); +void BPH_mass_spring_force_vertex_wind(struct Implicit_Data *data, int v, float radius, const float(*winvec)[3]); /* Linear spring force between two points */ bool BPH_mass_spring_force_spring_linear(struct Implicit_Data *data, int i, int j, float restlen, float stiffness, float damping, bool no_compress, float clamp_force); diff --git a/source/blender/physics/intern/implicit_blender.c b/source/blender/physics/intern/implicit_blender.c index 45030524566..8ee9513e81b 100644 --- a/source/blender/physics/intern/implicit_blender.c +++ b/source/blender/physics/intern/implicit_blender.c @@ -62,7 +62,7 @@ //#define DEBUG_TIME #ifdef DEBUG_TIME -# include "PIL_time.h" +# include "PIL_time.h" #endif static float I[3][3] = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}; @@ -135,7 +135,7 @@ static void print_fvector(float m3[3]) // long float vector float (*)[3] /////////////////////////// /* print long vector on console: for debug output */ -DO_INLINE void print_lfvector(float (*fLongVector)[3], unsigned int verts) +DO_INLINE void print_lfvector(float(*fLongVector)[3], unsigned int verts) { unsigned int i = 0; for (i = 0; i < verts; i++) { @@ -148,11 +148,11 @@ DO_INLINE void print_lfvector(float (*fLongVector)[3], unsigned int verts) DO_INLINE lfVector *create_lfvector(unsigned int verts) { /* TODO: check if memory allocation was successful */ - return (lfVector *)MEM_callocN(verts * sizeof(lfVector), "cloth_implicit_alloc_vector"); + return (lfVector *)MEM_callocN(verts * sizeof(lfVector), "cloth_implicit_alloc_vector"); // return (lfVector *)cloth_aligned_malloc(&MEMORY_BASE, verts * sizeof(lfVector)); } /* delete long vector */ -DO_INLINE void del_lfvector(float (*fLongVector)[3]) +DO_INLINE void del_lfvector(float(*fLongVector)[3]) { if (fLongVector != NULL) { MEM_freeN(fLongVector); @@ -160,12 +160,12 @@ DO_INLINE void del_lfvector(float (*fLongVector)[3]) } } /* copy long vector */ -DO_INLINE void cp_lfvector(float (*to)[3], float (*from)[3], unsigned int verts) +DO_INLINE void cp_lfvector(float(*to)[3], float(*from)[3], unsigned int verts) { memcpy(to, from, verts * sizeof(lfVector)); } /* init long vector with float[3] */ -DO_INLINE void init_lfvector(float (*fLongVector)[3], float vector[3], unsigned int verts) +DO_INLINE void init_lfvector(float(*fLongVector)[3], float vector[3], unsigned int verts) { unsigned int i = 0; for (i = 0; i < verts; i++) { @@ -173,12 +173,12 @@ DO_INLINE void init_lfvector(float (*fLongVector)[3], float vector[3], unsigned } } /* zero long vector with float[3] */ -DO_INLINE void zero_lfvector(float (*to)[3], unsigned int verts) +DO_INLINE void zero_lfvector(float(*to)[3], unsigned int verts) { memset(to, 0.0f, verts * sizeof(lfVector)); } /* multiply long vector with scalar*/ -DO_INLINE void mul_lfvectorS(float (*to)[3], float (*fLongVector)[3], float scalar, unsigned int verts) +DO_INLINE void mul_lfvectorS(float(*to)[3], float(*fLongVector)[3], float scalar, unsigned int verts) { unsigned int i = 0; @@ -188,7 +188,7 @@ DO_INLINE void mul_lfvectorS(float (*to)[3], float (*fLongVector)[3], float scal } /* multiply long vector with scalar*/ /* A -= B * float */ -DO_INLINE void submul_lfvectorS(float (*to)[3], float (*fLongVector)[3], float scalar, unsigned int verts) +DO_INLINE void submul_lfvectorS(float(*to)[3], float(*fLongVector)[3], float scalar, unsigned int verts) { unsigned int i = 0; for (i = 0; i < verts; i++) { @@ -196,7 +196,7 @@ DO_INLINE void submul_lfvectorS(float (*to)[3], float (*fLongVector)[3], float s } } /* dot product for big vector */ -DO_INLINE float dot_lfvector(float (*fLongVectorA)[3], float (*fLongVectorB)[3], unsigned int verts) +DO_INLINE float dot_lfvector(float(*fLongVectorA)[3], float(*fLongVectorB)[3], unsigned int verts) { long i = 0; float temp = 0.0; @@ -211,7 +211,7 @@ DO_INLINE float dot_lfvector(float (*fLongVectorA)[3], float (*fLongVectorB)[3], return temp; } /* A = B + C --> for big vector */ -DO_INLINE void add_lfvector_lfvector(float (*to)[3], float (*fLongVectorA)[3], float (*fLongVectorB)[3], unsigned int verts) +DO_INLINE void add_lfvector_lfvector(float(*to)[3], float(*fLongVectorA)[3], float(*fLongVectorB)[3], unsigned int verts) { unsigned int i = 0; @@ -221,7 +221,7 @@ DO_INLINE void add_lfvector_lfvector(float (*to)[3], float (*fLongVectorA)[3], f } /* A = B + C * float --> for big vector */ -DO_INLINE void add_lfvector_lfvectorS(float (*to)[3], float (*fLongVectorA)[3], float (*fLongVectorB)[3], float bS, unsigned int verts) +DO_INLINE void add_lfvector_lfvectorS(float(*to)[3], float(*fLongVectorA)[3], float(*fLongVectorB)[3], float bS, unsigned int verts) { unsigned int i = 0; @@ -231,7 +231,7 @@ DO_INLINE void add_lfvector_lfvectorS(float (*to)[3], float (*fLongVectorA)[3], } } /* A = B * float + C * float --> for big vector */ -DO_INLINE void add_lfvectorS_lfvectorS(float (*to)[3], float (*fLongVectorA)[3], float aS, float (*fLongVectorB)[3], float bS, unsigned int verts) +DO_INLINE void add_lfvectorS_lfvectorS(float(*to)[3], float(*fLongVectorA)[3], float aS, float(*fLongVectorB)[3], float bS, unsigned int verts) { unsigned int i = 0; @@ -240,7 +240,7 @@ DO_INLINE void add_lfvectorS_lfvectorS(float (*to)[3], float (*fLongVectorA)[3], } } /* A = B - C * float --> for big vector */ -DO_INLINE void sub_lfvector_lfvectorS(float (*to)[3], float (*fLongVectorA)[3], float (*fLongVectorB)[3], float bS, unsigned int verts) +DO_INLINE void sub_lfvector_lfvectorS(float(*to)[3], float(*fLongVectorA)[3], float(*fLongVectorB)[3], float bS, unsigned int verts) { unsigned int i = 0; for (i = 0; i < verts; i++) { @@ -249,7 +249,7 @@ DO_INLINE void sub_lfvector_lfvectorS(float (*to)[3], float (*fLongVectorA)[3], } /* A = B - C --> for big vector */ -DO_INLINE void sub_lfvector_lfvector(float (*to)[3], float (*fLongVectorA)[3], float (*fLongVectorB)[3], unsigned int verts) +DO_INLINE void sub_lfvector_lfvector(float(*to)[3], float(*fLongVectorA)[3], float(*fLongVectorB)[3], unsigned int verts) { unsigned int i = 0; @@ -302,7 +302,7 @@ static void print_bfmatrix(fmatrix3x3 *m) { int tot = m[0].vcount + m[0].scount; int size = m[0].vcount * 3; - float *t = MEM_callocN(sizeof(float) * size*size, "bfmatrix"); + float *t = MEM_callocN(sizeof(float) * size * size, "bfmatrix"); int q, i, j; for (q = 0; q < tot; ++q) { @@ -365,8 +365,8 @@ DO_INLINE void initdiag_fmatrixS(float to[3][3], float aS) /* calculate determinant of 3x3 matrix */ DO_INLINE float det_fmatrix(float m[3][3]) { - return m[0][0]*m[1][1]*m[2][2] + m[1][0]*m[2][1]*m[0][2] + m[0][1]*m[1][2]*m[2][0] - - m[0][0]*m[1][2]*m[2][1] - m[0][1]*m[1][0]*m[2][2] - m[2][0]*m[1][1]*m[0][2]; + return m[0][0] * m[1][1] * m[2][2] + m[1][0] * m[2][1] * m[0][2] + m[0][1] * m[1][2] * m[2][0] - + m[0][0] * m[1][2] * m[2][1] - m[0][1] * m[1][0] * m[2][2] - m[2][0] * m[1][1] * m[0][2]; } DO_INLINE void inverse_fmatrix(float to[3][3], float from[3][3]) @@ -374,18 +374,18 @@ DO_INLINE void inverse_fmatrix(float to[3][3], float from[3][3]) unsigned int i, j; float d; - if ((d=det_fmatrix(from)) == 0) { + if ((d = det_fmatrix(from)) == 0) { printf("can't build inverse"); exit(0); } - for (i=0;i<3;i++) { - for (j=0;j<3;j++) { - int i1=(i+1)%3; - int i2=(i+2)%3; - int j1=(j+1)%3; - int j2=(j+2)%3; + for (i = 0; i < 3; i++) { + for (j = 0; j < 3; j++) { + int i1 = (i + 1) % 3; + int i2 = (i + 2) % 3; + int j1 = (j + 1) % 3; + int j2 = (j + 2) % 3; /** Reverse indexes i&j to take transpose. */ - to[j][i] = (from[i1][j1]*from[i2][j2]-from[i1][j2]*from[i2][j1])/d; + to[j][i] = (from[i1][j1] * from[i2][j2] - from[i1][j2] * from[i2][j1]) / d; /** * <pre> * if (i == j) { @@ -415,9 +415,9 @@ DO_INLINE void mul_fmatrix_S(float matrix[3][3], float scalar) /* STATUS: verified */ DO_INLINE void mul_fvector_fmatrix(float *to, float *from, float matrix[3][3]) { - to[0] = matrix[0][0]*from[0] + matrix[1][0]*from[1] + matrix[2][0]*from[2]; - to[1] = matrix[0][1]*from[0] + matrix[1][1]*from[1] + matrix[2][1]*from[2]; - to[2] = matrix[0][2]*from[0] + matrix[1][2]*from[1] + matrix[2][2]*from[2]; + to[0] = matrix[0][0] * from[0] + matrix[1][0] * from[1] + matrix[2][0] * from[2]; + to[1] = matrix[0][1] * from[0] + matrix[1][1] * from[1] + matrix[2][1] * from[2]; + to[2] = matrix[0][2] * from[0] + matrix[1][2] * from[1] + matrix[2][2] * from[2]; } /* 3x3 matrix multiplied by a vector */ @@ -477,9 +477,9 @@ BLI_INLINE void cross_m3_v3m3(float r[3][3], const float v[3], float m[3][3]) BLI_INLINE void cross_v3_identity(float r[3][3], const float v[3]) { - r[0][0] = 0.0f; r[1][0] = v[2]; r[2][0] = -v[1]; - r[0][1] = -v[2]; r[1][1] = 0.0f; r[2][1] = v[0]; - r[0][2] = v[1]; r[1][2] = -v[0]; r[2][2] = 0.0f; + r[0][0] = 0.0f; r[1][0] = v[2]; r[2][0] = -v[1]; + r[0][1] = -v[2]; r[1][1] = 0.0f; r[2][1] = v[0]; + r[0][2] = v[1]; r[1][2] = -v[0]; r[2][2] = 0.0f; } BLI_INLINE void madd_m3_m3fl(float r[3][3], float m[3][3], float f) @@ -560,7 +560,7 @@ DO_INLINE void del_bfmatrix(fmatrix3x3 *matrix) DO_INLINE void cp_bfmatrix(fmatrix3x3 *to, fmatrix3x3 *from) { // TODO bounds checking - memcpy(to, from, sizeof(fmatrix3x3) * (from[0].vcount+from[0].scount)); + memcpy(to, from, sizeof(fmatrix3x3) * (from[0].vcount + from[0].scount)); } /* init big matrix */ @@ -569,7 +569,7 @@ DO_INLINE void init_bfmatrix(fmatrix3x3 *matrix, float m3[3][3]) { unsigned int i; - for (i = 0; i < matrix[0].vcount+matrix[0].scount; i++) { + for (i = 0; i < matrix[0].vcount + matrix[0].scount; i++) { cp_fmatrix(matrix[i].m, m3); } } @@ -584,14 +584,14 @@ DO_INLINE void initdiag_bfmatrix(fmatrix3x3 *matrix, float m3[3][3]) for (i = 0; i < matrix[0].vcount; i++) { cp_fmatrix(matrix[i].m, m3); } - for (j = matrix[0].vcount; j < matrix[0].vcount+matrix[0].scount; j++) { + for (j = matrix[0].vcount; j < matrix[0].vcount + matrix[0].scount; j++) { cp_fmatrix(matrix[j].m, tmatrix); } } /* SPARSE SYMMETRIC multiply big matrix with long vector*/ /* STATUS: verified */ -DO_INLINE void mul_bfmatrix_lfvector( float (*to)[3], fmatrix3x3 *from, lfVector *fLongVector) +DO_INLINE void mul_bfmatrix_lfvector(float(*to)[3], fmatrix3x3 *from, lfVector *fLongVector) { unsigned int i = 0; unsigned int vcount = from[0].vcount; @@ -603,13 +603,13 @@ DO_INLINE void mul_bfmatrix_lfvector( float (*to)[3], fmatrix3x3 *from, lfVector { #pragma omp section { - for (i = from[0].vcount; i < from[0].vcount+from[0].scount; i++) { + for (i = from[0].vcount; i < from[0].vcount + from[0].scount; i++) { muladd_fmatrix_fvector(to[from[i].c], from[i].m, fLongVector[from[i].r]); } } #pragma omp section { - for (i = 0; i < from[0].vcount+from[0].scount; i++) { + for (i = 0; i < from[0].vcount + from[0].scount; i++) { muladd_fmatrix_fvector(temp[from[i].r], from[i].m, fLongVector[from[i].c]); } } @@ -624,12 +624,12 @@ DO_INLINE void mul_bfmatrix_lfvector( float (*to)[3], fmatrix3x3 *from, lfVector /* SPARSE SYMMETRIC sub big matrix with big matrix*/ /* A -= B * float + C * float --> for big matrix */ /* VERIFIED */ -DO_INLINE void subadd_bfmatrixS_bfmatrixS( fmatrix3x3 *to, fmatrix3x3 *from, float aS, fmatrix3x3 *matrix, float bS) +DO_INLINE void subadd_bfmatrixS_bfmatrixS(fmatrix3x3 *to, fmatrix3x3 *from, float aS, fmatrix3x3 *matrix, float bS) { unsigned int i = 0; /* process diagonal elements */ - for (i = 0; i < matrix[0].vcount+matrix[0].scount; i++) { + for (i = 0; i < matrix[0].vcount + matrix[0].scount; i++) { subadd_fmatrixS_fmatrixS(to[i].m, from[i].m, aS, matrix[i].m, bS); } @@ -639,27 +639,27 @@ DO_INLINE void subadd_bfmatrixS_bfmatrixS( fmatrix3x3 *to, fmatrix3x3 *from, flo // simulator start /////////////////////////////////////////////////////////////////// -typedef struct Implicit_Data { +typedef struct Implicit_Data { /* inputs */ - fmatrix3x3 *bigI; /* identity (constant) */ - fmatrix3x3 *tfm; /* local coordinate transform */ - fmatrix3x3 *M; /* masses */ - lfVector *F; /* forces */ - fmatrix3x3 *dFdV, *dFdX; /* force jacobians */ - int num_blocks; /* number of off-diagonal blocks (springs) */ + fmatrix3x3 *bigI; /* identity (constant) */ + fmatrix3x3 *tfm; /* local coordinate transform */ + fmatrix3x3 *M; /* masses */ + lfVector *F; /* forces */ + fmatrix3x3 *dFdV, *dFdX; /* force jacobians */ + int num_blocks; /* number of off-diagonal blocks (springs) */ /* motion state data */ - lfVector *X, *Xnew; /* positions */ - lfVector *V, *Vnew; /* velocities */ + lfVector *X, *Xnew; /* positions */ + lfVector *V, *Vnew; /* velocities */ /* internal solver data */ - lfVector *B; /* B for A*dV = B */ - fmatrix3x3 *A; /* A for A*dV = B */ + lfVector *B; /* B for A*dV = B */ + fmatrix3x3 *A; /* A for A*dV = B */ - lfVector *dV; /* velocity change (solution of A*dV = B) */ - lfVector *z; /* target velocity in constrained directions */ - fmatrix3x3 *S; /* filtering matrix for constraints */ - fmatrix3x3 *P, *Pinv; /* pre-conditioning matrix */ + lfVector *dV; /* velocity change (solution of A*dV = B) */ + lfVector *z; /* target velocity in constrained directions */ + fmatrix3x3 *S; /* filtering matrix for constraints */ + fmatrix3x3 *P, *Pinv; /* pre-conditioning matrix */ } Implicit_Data; Implicit_Data *BPH_mass_spring_solver_create(int numverts, int numsprings) @@ -744,7 +744,7 @@ BLI_INLINE void root_to_world_m3(Implicit_Data *data, int index, float r[3][3], DO_INLINE void filter(lfVector *V, fmatrix3x3 *S) { - unsigned int i=0; + unsigned int i = 0; for (i = 0; i < S[0].vcount; i++) { mul_m3_v3(S[i].m, V[S[i].r]); @@ -755,8 +755,8 @@ DO_INLINE void filter(lfVector *V, fmatrix3x3 *S) static int cg_filtered(lfVector *ldV, fmatrix3x3 *lA, lfVector *lB, lfVector *z, fmatrix3x3 *S) { // Solves for unknown X in equation AX=B - unsigned int conjgrad_loopcount=0, conjgrad_looplimit=100; - float conjgrad_epsilon=0.0001f /* , conjgrad_lasterror=0 */ /* UNUSED */; + unsigned int conjgrad_loopcount = 0, conjgrad_looplimit = 100; + float conjgrad_epsilon = 0.0001f /* , conjgrad_lasterror=0 */ /* UNUSED */; lfVector *q, *d, *tmp, *r; float s, starget, a, s_prev; unsigned int numverts = lA[0].vcount; @@ -782,13 +782,13 @@ static int cg_filtered(lfVector *ldV, fmatrix3x3 *lA, lfVector *lB, lfVector *z s = dot_lfvector(r, r, numverts); starget = s * sqrtf(conjgrad_epsilon); - while (s>starget && conjgrad_loopcount < conjgrad_looplimit) { + while (s > starget && conjgrad_loopcount < conjgrad_looplimit) { // Mul(q, A, d); // q = A*d; mul_bfmatrix_lfvector(q, lA, d); filter(q, S); - a = s/dot_lfvector(d, q, numverts); + a = s / dot_lfvector(d, q, numverts); // X = X + d*a; add_lfvector_lfvectorS(ldV, ldV, d, a, numverts); @@ -800,7 +800,7 @@ static int cg_filtered(lfVector *ldV, fmatrix3x3 *lA, lfVector *lB, lfVector *z s = dot_lfvector(r, r, numverts); //d = r+d*(s/s_prev); - add_lfvector_lfvectorS(d, r, d, (s/s_prev), numverts); + add_lfvector_lfvectorS(d, r, d, (s / s_prev), numverts); filter(d, S); @@ -814,15 +814,15 @@ static int cg_filtered(lfVector *ldV, fmatrix3x3 *lA, lfVector *lB, lfVector *z del_lfvector(r); // printf("W/O conjgrad_loopcount: %d\n", conjgrad_loopcount); - return conjgrad_loopcount<conjgrad_looplimit; // true means we reached desired accuracy in given time - ie stable + return conjgrad_loopcount < conjgrad_looplimit; // true means we reached desired accuracy in given time - ie stable } #endif static int cg_filtered(lfVector *ldV, fmatrix3x3 *lA, lfVector *lB, lfVector *z, fmatrix3x3 *S, ImplicitSolverResult *result) { // Solves for unknown X in equation AX=B - unsigned int conjgrad_loopcount=0, conjgrad_looplimit=100; - float conjgrad_epsilon=0.01f; + unsigned int conjgrad_loopcount = 0, conjgrad_looplimit = 100; + float conjgrad_epsilon = 0.01f; unsigned int numverts = lA[0].vcount; lfVector *fB = create_lfvector(numverts); @@ -839,7 +839,7 @@ static int cg_filtered(lfVector *ldV, fmatrix3x3 *lA, lfVector *lB, lfVector *z, cp_lfvector(fB, lB, numverts); filter(fB, S); bnorm2 = dot_lfvector(fB, fB, numverts); - delta_target = conjgrad_epsilon*conjgrad_epsilon * bnorm2; + delta_target = conjgrad_epsilon * conjgrad_epsilon * bnorm2; /* r = filter(B - A * dV) */ mul_bfmatrix_lfvector(AdV, lA, ldV); @@ -914,7 +914,7 @@ DO_INLINE void BuildPPinv(fmatrix3x3 *lA, fmatrix3x3 *P, fmatrix3x3 *Pinv) // Take only the diagonal blocks of A // #pragma omp parallel for private(i) if (lA[0].vcount > CLOTH_OPENMP_LIMIT) - for (i = 0; i<lA[0].vcount; i++) { + for (i = 0; i < lA[0].vcount; i++) { // block diagonalizer cp_fmatrix(P[i].m, lA[i].m); inverse_fmatrix(Pinv[i].m, P[i].m); @@ -926,9 +926,9 @@ DO_INLINE void BuildPPinv(fmatrix3x3 *lA, fmatrix3x3 *P, fmatrix3x3 *Pinv) // version 1.3 static int cg_filtered_pre(lfVector *dv, fmatrix3x3 *lA, lfVector *lB, lfVector *z, fmatrix3x3 *S, fmatrix3x3 *P, fmatrix3x3 *Pinv) { - unsigned int numverts = lA[0].vcount, iterations = 0, conjgrad_looplimit=100; + unsigned int numverts = lA[0].vcount, iterations = 0, conjgrad_looplimit = 100; float delta0 = 0, deltaNew = 0, deltaOld = 0, alpha = 0; - float conjgrad_epsilon=0.0001; // 0.2 is dt for steps=5 + float conjgrad_epsilon = 0.0001; // 0.2 is dt for steps=5 lfVector *r = create_lfvector(numverts); lfVector *p = create_lfvector(numverts); lfVector *s = create_lfvector(numverts); @@ -992,14 +992,14 @@ static int cg_filtered_pre(lfVector *dv, fmatrix3x3 *lA, lfVector *lB, lfVector printf("iterations: %d\n", iterations); - return iterations<conjgrad_looplimit; + return iterations < conjgrad_looplimit; } #endif // version 1.4 static int cg_filtered_pre(lfVector *dv, fmatrix3x3 *lA, lfVector *lB, lfVector *z, fmatrix3x3 *S, fmatrix3x3 *P, fmatrix3x3 *Pinv, fmatrix3x3 *bigI) { - unsigned int numverts = lA[0].vcount, iterations = 0, conjgrad_looplimit=100; + unsigned int numverts = lA[0].vcount, iterations = 0, conjgrad_looplimit = 100; float delta0 = 0, deltaNew = 0, deltaOld = 0, alpha = 0, tol = 0; lfVector *r = create_lfvector(numverts); lfVector *p = create_lfvector(numverts); @@ -1058,9 +1058,9 @@ static int cg_filtered_pre(lfVector *dv, fmatrix3x3 *lA, lfVector *lB, lfVector double start = PIL_check_seconds_timer(); #endif - tol = (0.01*0.2); + tol = (0.01 * 0.2); - while ((deltaNew > delta0*tol*tol) && (iterations < conjgrad_looplimit)) + while ((deltaNew > delta0 * tol * tol) && (iterations < conjgrad_looplimit)) { iterations++; @@ -1100,7 +1100,7 @@ static int cg_filtered_pre(lfVector *dv, fmatrix3x3 *lA, lfVector *lB, lfVector // printf("iterations: %d\n", iterations); - return iterations<conjgrad_looplimit; + return iterations < conjgrad_looplimit; } #endif @@ -1113,11 +1113,11 @@ bool BPH_mass_spring_solve_velocities(Implicit_Data *data, float dt, ImplicitSol cp_bfmatrix(data->A, data->M); - subadd_bfmatrixS_bfmatrixS(data->A, data->dFdV, dt, data->dFdX, (dt*dt)); + subadd_bfmatrixS_bfmatrixS(data->A, data->dFdV, dt, data->dFdX, (dt * dt)); mul_bfmatrix_lfvector(dFdXmV, data->dFdX, data->V); - add_lfvectorS_lfvectorS(data->B, data->F, dt, dFdXmV, (dt*dt), numverts); + add_lfvectorS_lfvectorS(data->B, data->F, dt, dFdXmV, (dt * dt), numverts); #ifdef DEBUG_TIME double start = PIL_check_seconds_timer(); @@ -1399,7 +1399,7 @@ static float calc_nor_area_tri(float nor[3], const float v1[3], const float v2[3 } /* XXX does not support force jacobians yet, since the effector system does not provide them either */ -void BPH_mass_spring_force_face_wind(Implicit_Data *data, int v1, int v2, int v3, const float (*winvec)[3]) +void BPH_mass_spring_force_face_wind(Implicit_Data *data, int v1, int v2, int v3, const float(*winvec)[3]) { const float effector_scale = 0.02f; float win[3], nor[3], area; @@ -1438,7 +1438,7 @@ static void edge_wind_vertex(const float dir[3], float length, float radius, con mul_v3_v3fl(f, wind, density * cross_section); } -void BPH_mass_spring_force_edge_wind(Implicit_Data *data, int v1, int v2, float radius1, float radius2, const float (*winvec)[3]) +void BPH_mass_spring_force_edge_wind(Implicit_Data *data, int v1, int v2, float radius1, float radius2, const float(*winvec)[3]) { float win[3], dir[3], length; float f[3], dfdx[3][3], dfdv[3][3]; @@ -1455,7 +1455,7 @@ void BPH_mass_spring_force_edge_wind(Implicit_Data *data, int v1, int v2, float add_v3_v3(data->F[v2], f); } -void BPH_mass_spring_force_vertex_wind(Implicit_Data *data, int v, float UNUSED(radius), const float (*winvec)[3]) +void BPH_mass_spring_force_vertex_wind(Implicit_Data *data, int v, float UNUSED(radius), const float(*winvec)[3]) { const float density = 0.01f; /* XXX arbitrary value, corresponds to effect of air density */ @@ -1474,7 +1474,7 @@ BLI_INLINE void dfdx_spring(float to[3][3], const float dir[3], float length, fl outerproduct(to, dir, dir); sub_m3_m3m3(to, I, to); - mul_m3_fl(to, (L/length)); + mul_m3_fl(to, (L / length)); sub_m3_m3m3(to, to, I); mul_m3_fl(to, k); } @@ -1484,10 +1484,10 @@ BLI_INLINE void dfdx_spring(float to[3][3], const float dir[3], float length, fl BLI_INLINE void dfdx_damp(float to[3][3], const float dir[3], float length, const float vel[3], float rest, float damping) { // inner spring damping vel is the relative velocity of the endpoints. - // return (I-outerprod(dir, dir)) * (-damping * -(dot(dir, vel)/Max(length, rest))); + // return (I-outerprod(dir, dir)) * (-damping * -(dot(dir, vel)/Max(length, rest))); mul_fvectorT_fvector(to, dir, dir); sub_fmatrix_fmatrix(to, I, to); - mul_fmatrix_S(to, (-damping * -(dot_v3v3(dir, vel)/MAX2(length, rest)))); + mul_fmatrix_S(to, (-damping * -(dot_v3v3(dir, vel) / MAX2(length, rest)))); } #endif @@ -1509,7 +1509,7 @@ BLI_INLINE float fb(float length, float L) BLI_INLINE float fbderiv(float length, float L) { - float x = length/L; + float x = length / L; float xx = x * x; float xxx = xx * x; return (-46.164f * xxx + 102.579f * xx - 78.166f * x + 23.116f); @@ -1536,7 +1536,7 @@ BLI_INLINE float fbstar_jacobi(float length, float L, float kb, float cb) return -cb; } else { - return -kb * fbderiv(length, L); + return -kb *fbderiv(length, L); } } @@ -1551,7 +1551,7 @@ BLI_INLINE bool spring_length(Implicit_Data *data, int i, int j, float r_extent[ #if 0 if (length > L) { if ((clmd->sim_parms->flags & CSIMSETT_FLAG_TEARING_ENABLED) && - ( ((length-L)*100.0f/L) > clmd->sim_parms->maxspringlen )) + ( ((length - L) * 100.0f / L) > clmd->sim_parms->maxspringlen)) { // cut spring! s->flags |= CSPRING_FLAG_DEACTIVATE; @@ -1559,7 +1559,7 @@ BLI_INLINE bool spring_length(Implicit_Data *data, int i, int j, float r_extent[ } } #endif - mul_v3_v3fl(r_dir, r_extent, 1.0f/(*r_length)); + mul_v3_v3fl(r_dir, r_extent, 1.0f / (*r_length)); } else { zero_v3(r_dir); diff --git a/source/blender/physics/intern/implicit_eigen.cpp b/source/blender/physics/intern/implicit_eigen.cpp index fd91df9c769..012764d5ff5 100644 --- a/source/blender/physics/intern/implicit_eigen.cpp +++ b/source/blender/physics/intern/implicit_eigen.cpp @@ -110,7 +110,7 @@ public: coeffRef(k) = v[k]; } - fVector& operator = (const ctype &v) + fVector& operator =(const ctype &v) { for (int k = 0; k < 3; ++k) coeffRef(k) = v[k]; @@ -141,7 +141,7 @@ public: coeffRef(l, k) = v[k][l]; } - fMatrix& operator = (const ctype &v) + fMatrix& operator =(const ctype &v) { for (int k = 0; k < 3; ++k) for (int l = 0; l < 3; ++l) @@ -167,18 +167,18 @@ public: } template <typename T> - lVector& operator = (T rhs) + lVector& operator =(T rhs) { base_t::operator=(rhs); return *this; } - float* v3(int vertex) + float *v3(int vertex) { return &coeffRef(3 * vertex); } - const float* v3(int vertex) const + const float *v3(int vertex) const { return &coeffRef(3 * vertex); } @@ -244,7 +244,7 @@ typedef Eigen::ConjugateGradient<lMatrix, Eigen::Lower, Eigen::DiagonalPrecondit #ifdef USE_EIGEN_CONSTRAINED_CG typedef Eigen::ConstrainedConjugateGradient<lMatrix, Eigen::Lower, lMatrix, Eigen::DiagonalPreconditioner<Scalar> > - ConstraintConjGrad; + ConstraintConjGrad; #endif using Eigen::ComputationInfo; @@ -350,9 +350,9 @@ BLI_INLINE void cross_m3_v3m3(float r[3][3], const float v[3], float m[3][3]) BLI_INLINE void cross_v3_identity(float r[3][3], const float v[3]) { - r[0][0] = 0.0f; r[1][0] = v[2]; r[2][0] = -v[1]; - r[0][1] = -v[2]; r[1][1] = 0.0f; r[2][1] = v[0]; - r[0][2] = v[1]; r[1][2] = -v[0]; r[2][2] = 0.0f; + r[0][0] = 0.0f; r[1][0] = v[2]; r[2][0] = -v[1]; + r[0][1] = -v[2]; r[1][1] = 0.0f; r[2][1] = v[0]; + r[0][2] = v[1]; r[1][2] = -v[0]; r[2][2] = 0.0f; } BLI_INLINE void madd_m3_m3fl(float r[3][3], float m[3][3], float f) @@ -422,28 +422,28 @@ struct Implicit_Data { int numverts; /* inputs */ - lMatrix M; /* masses */ - lVector F; /* forces */ - lMatrix dFdX, dFdV; /* force jacobians */ + lMatrix M; /* masses */ + lVector F; /* forces */ + lMatrix dFdX, dFdV; /* force jacobians */ - fMatrixVector tfm; /* local coordinate transform */ + fMatrixVector tfm; /* local coordinate transform */ /* motion state data */ - lVector X, Xnew; /* positions */ - lVector V, Vnew; /* velocities */ + lVector X, Xnew; /* positions */ + lVector V, Vnew; /* velocities */ /* internal solver data */ - lVector B; /* B for A*dV = B */ - lMatrix A; /* A for A*dV = B */ + lVector B; /* B for A*dV = B */ + lMatrix A; /* A for A*dV = B */ - lVector dV; /* velocity change (solution of A*dV = B) */ - lVector z; /* target velocity in constrained directions */ - lMatrix S; /* filtering matrix for constraints */ + lVector dV; /* velocity change (solution of A*dV = B) */ + lVector z; /* target velocity in constrained directions */ + lMatrix S; /* filtering matrix for constraints */ /* temporary constructors */ - lMatrixCtor iM; /* masses */ - lMatrixCtor idFdX, idFdV; /* force jacobians */ - lMatrixCtor iS; /* filtering matrix for constraints */ + lMatrixCtor iM; /* masses */ + lMatrixCtor idFdX, idFdV; /* force jacobians */ + lMatrixCtor iS; /* filtering matrix for constraints */ }; Implicit_Data *BPH_mass_spring_solver_create(int numverts, int numsprings) @@ -516,10 +516,10 @@ bool BPH_mass_spring_solve_velocities(Implicit_Data *data, float dt, ImplicitSol cg.filter() = data->S; #endif - data->A = data->M - dt * data->dFdV - dt*dt * data->dFdX; + data->A = data->M - dt * data->dFdV - dt * dt * data->dFdX; cg.compute(data->A); - data->B = dt * data->F + dt*dt * data->dFdX * data->V; + data->B = dt * data->F + dt * dt * data->dFdX * data->V; #ifdef IMPLICIT_PRINT_SOLVER_INPUT_OUTPUT printf("==== A ====\n"); @@ -786,7 +786,7 @@ static float calc_nor_area_tri(float nor[3], const float v1[3], const float v2[3 } /* XXX does not support force jacobians yet, since the effector system does not provide them either */ -void BPH_mass_spring_force_face_wind(Implicit_Data *data, int v1, int v2, int v3, const float (*winvec)[3]) +void BPH_mass_spring_force_face_wind(Implicit_Data *data, int v1, int v2, int v3, const float(*winvec)[3]) { const float effector_scale = 0.02f; float win[3], nor[3], area; @@ -806,7 +806,7 @@ void BPH_mass_spring_force_face_wind(Implicit_Data *data, int v1, int v2, int v3 madd_v3_v3fl(data->F.v3(v3), nor, factor * dot_v3v3(win, nor)); } -void BPH_mass_spring_force_edge_wind(Implicit_Data *data, int v1, int v2, const float (*winvec)[3]) +void BPH_mass_spring_force_edge_wind(Implicit_Data *data, int v1, int v2, const float(*winvec)[3]) { const float effector_scale = 0.01; float win[3], dir[3], nor[3], length; @@ -830,7 +830,7 @@ BLI_INLINE void dfdx_spring(float to[3][3], const float dir[3], float length, fl outerproduct(to, dir, dir); sub_m3_m3m3(to, I, to); - mul_m3_fl(to, (L/length)); + mul_m3_fl(to, (L / length)); sub_m3_m3m3(to, to, I); mul_m3_fl(to, k); } @@ -840,10 +840,10 @@ BLI_INLINE void dfdx_spring(float to[3][3], const float dir[3], float length, fl BLI_INLINE void dfdx_damp(float to[3][3], const float dir[3], float length, const float vel[3], float rest, float damping) { // inner spring damping vel is the relative velocity of the endpoints. - // return (I-outerprod(dir, dir)) * (-damping * -(dot(dir, vel)/Max(length, rest))); + // return (I-outerprod(dir, dir)) * (-damping * -(dot(dir, vel)/Max(length, rest))); mul_fvectorT_fvector(to, dir, dir); sub_fmatrix_fmatrix(to, I, to); - mul_fmatrix_S(to, (-damping * -(dot_v3v3(dir, vel)/MAX2(length, rest)))); + mul_fmatrix_S(to, (-damping * -(dot_v3v3(dir, vel) / MAX2(length, rest)))); } #endif @@ -862,7 +862,7 @@ BLI_INLINE float fb(float length, float L) BLI_INLINE float fbderiv(float length, float L) { - float x = length/L; + float x = length / L; return (-46.164f * powf(x, 3) + 102.579f * powf(x, 2) - 78.166f * x + 23.116f); } @@ -888,7 +888,7 @@ BLI_INLINE float fbstar_jacobi(float length, float L, float kb, float cb) return -cb; } else { - return -kb * fbderiv(length, L); + return -kb *fbderiv(length, L); } } @@ -903,7 +903,7 @@ BLI_INLINE bool spring_length(Implicit_Data *data, int i, int j, float r_extent[ #if 0 if (length > L) { if ((clmd->sim_parms->flags & CSIMSETT_FLAG_TEARING_ENABLED) && - ( ((length-L)*100.0f/L) > clmd->sim_parms->maxspringlen )) + ( ((length - L) * 100.0f / L) > clmd->sim_parms->maxspringlen)) { // cut spring! s->flags |= CSPRING_FLAG_DEACTIVATE; @@ -911,7 +911,7 @@ BLI_INLINE bool spring_length(Implicit_Data *data, int i, int j, float r_extent[ } } #endif - mul_v3_v3fl(r_dir, r_extent, 1.0f/(*r_length)); + mul_v3_v3fl(r_dir, r_extent, 1.0f / (*r_length)); } else { zero_v3(r_dir); |