Cleanup: comments (long lines) in physics

This commit is contained in:
2019-04-30 14:41:33 +10:00
parent 5d7ee02b17
commit 95a9646c00
6 changed files with 77 additions and 44 deletions

View File

@@ -232,7 +232,7 @@ static void cloth_setup_constraints(ClothModifierData *clmd,
ColliderContacts *ct = &contacts[i];
for (j = 0; j < ct->totcollisions; ++j) {
CollPair *collpair = &ct->collisions[j];
// float restitution = (1.0f - clmd->coll_parms->damping) * (1.0f - ct->ob->pd->pdef_sbdamp);
// float restitution = (1.0f - clmd->coll_parms->damping) * (1.0f - ct->ob->pd->pdef_sbdamp);
float restitution = 0.0f;
int v = collpair->face1;
float impulse[3];
@@ -334,7 +334,7 @@ static int UNUSED_FUNCTION(cloth_calc_helper_forces)(Object *UNUSED(ob),
sub_v3_v3v3(vec, cos[i], cv->tx);
mul_v3_fl(vec, cv->mass * dt * 20.0f);
add_v3_v3(cv->tv, vec);
//copy_v3_v3(cv->tx, cos[i]);
// copy_v3_v3(cv->tx, cos[i]);
}
MEM_freeN(cos);
@@ -382,8 +382,9 @@ BLI_INLINE void cloth_calc_spring_force(ClothModifierData *clmd, ClothSpring *s)
k_tension = scaling_tension / (parms->avg_spring_len + FLT_EPSILON);
if (s->type & CLOTH_SPRING_TYPE_SEWING) {
// TODO: verify, half verified (couldn't see error)
// sewing springs usually have a large distance at first so clamp the force so we don't get tunnelling through colission objects
/* TODO: verify, half verified (couldn't see error)
* sewing springs usually have a large distance at first so clamp the force so we don't get
* tunnelling through colission objects */
BPH_mass_spring_force_spring_linear(data,
s->ij,
s->kl,
@@ -459,9 +460,9 @@ BLI_INLINE void cloth_calc_spring_force(ClothModifierData *clmd, ClothSpring *s)
s->flags |= CLOTH_SPRING_FLAG_NEEDED;
/* XXX WARNING: angular bending springs for hair apply stiffness factor as an overall factor, unlike cloth springs!
* this is crap, but needed due to cloth/hair mixing ...
* max_bend factor is not even used for hair, so ...
/* XXX WARNING: angular bending springs for hair apply stiffness factor as an overall factor,
* unlike cloth springs! this is crap, but needed due to cloth/hair mixing ... max_bend factor
* is not even used for hair, so ...
*/
scaling = s->lin_stiffness * parms->bending;
kb = scaling / (20.0f * (parms->avg_spring_len + FLT_EPSILON));
@@ -469,7 +470,8 @@ BLI_INLINE void cloth_calc_spring_force(ClothModifierData *clmd, ClothSpring *s)
// Fix for [#45084] for cloth stiffness must have cb proportional to kb
cb = kb * parms->bending_damping;
/* XXX assuming same restlen for ij and jk segments here, this can be done correctly for hair later */
/* XXX assuming same restlen for ij and jk segments here,
* this can be done correctly for hair later. */
BPH_mass_spring_force_spring_bending_hair(data, s->ij, s->kl, s->mn, s->target, kb, cb);
# if 0
@@ -487,8 +489,8 @@ BLI_INLINE void cloth_calc_spring_force(ClothModifierData *clmd, ClothSpring *s)
BKE_sim_debug_data_add_vector(
clmd->debug_data, x_kl, d, 0.8, 0.8, 0.2, "target", 7982, s->kl);
// copy_v3_v3(d, s->target_ij);
// BKE_sim_debug_data_add_vector(clmd->debug_data, x, d, 1, 0.4, 0.4, "target", 7983, s->kl);
// copy_v3_v3(d, s->target_ij);
// BKE_sim_debug_data_add_vector(clmd->debug_data, x, d, 1, 0.4, 0.4, "target", 7983, s->kl);
}
# endif
#endif
@@ -861,12 +863,18 @@ static void cloth_continuum_step(ClothModifierData *clmd, float dt)
BPH_hair_volume_grid_interpolate(grid, x, &gdensity, gvel, gvel_smooth, NULL, NULL);
// BKE_sim_debug_data_add_circle(clmd->debug_data, x, gdensity, 0.7, 0.3, 1, "grid density", i, j, 3111);
// BKE_sim_debug_data_add_circle(
// clmd->debug_data, x, gdensity, 0.7, 0.3, 1,
// "grid density", i, j, 3111);
if (!is_zero_v3(gvel) || !is_zero_v3(gvel_smooth)) {
float dvel[3];
sub_v3_v3v3(dvel, gvel_smooth, gvel);
// BKE_sim_debug_data_add_vector(clmd->debug_data, x, gvel, 0.4, 0, 1, "grid velocity", i, j, 3112);
// BKE_sim_debug_data_add_vector(clmd->debug_data, x, gvel_smooth, 0.6, 1, 1, "grid velocity", i, j, 3113);
// BKE_sim_debug_data_add_vector(
// clmd->debug_data, x, gvel, 0.4, 0, 1,
// "grid velocity", i, j, 3112);
// BKE_sim_debug_data_add_vector(
// clmd->debug_data, x, gvel_smooth, 0.6, 1, 1,
// "grid velocity", i, j, 3113);
BKE_sim_debug_data_add_vector(
clmd->debug_data, x, dvel, 0.4, 1, 0.7, "grid velocity", i, j, 3114);
# if 0
@@ -875,10 +883,16 @@ static void cloth_continuum_step(ClothModifierData *clmd, float dt)
float col1[3] = {0.0, 1.0, 0.0};
float col[3];
interp_v3_v3v3(col, col0, col1, CLAMPIS(gdensity * clmd->sim_parms->density_strength, 0.0, 1.0));
// BKE_sim_debug_data_add_circle(clmd->debug_data, x, gdensity * clmd->sim_parms->density_strength, 0, 1, 0.4, "grid velocity", i, j, 3115);
// BKE_sim_debug_data_add_dot(clmd->debug_data, x, col[0], col[1], col[2], "grid velocity", i, j, 3115);
BKE_sim_debug_data_add_circle(clmd->debug_data, x, 0.01f, col[0], col[1], col[2], "grid velocity", i, j, 3115);
interp_v3_v3v3(col, col0, col1,
CLAMPIS(gdensity * clmd->sim_parms->density_strength, 0.0, 1.0));
// BKE_sim_debug_data_add_circle(
// clmd->debug_data, x, gdensity * clmd->sim_parms->density_strength, 0, 1, 0.4,
// "grid velocity", i, j, 3115);
// BKE_sim_debug_data_add_dot(
// clmd->debug_data, x, col[0], col[1], col[2],
// "grid velocity", i, j, 3115);
BKE_sim_debug_data_add_circle(
clmd->debug_data, x, 0.01f, col[0], col[1], col[2], "grid velocity", i, j, 3115);
}
# endif
}
@@ -1118,7 +1132,8 @@ int BPH_cloth_solve(
if (clmd->sim_parms->vgroup_mass > 0) {
if (verts[i].flags & CLOTH_VERT_FLAG_PINNED) {
float x[3];
/* divide by time_scale to prevent pinned vertices' delta locations from being multiplied */
/* divide by time_scale to prevent pinned vertices'
* delta locations from being multiplied */
interp_v3_v3v3(
x, verts[i].xold, verts[i].xconst, (step + dt) / clmd->sim_parms->time_scale);
BPH_mass_spring_set_position(id, i, x);

View File

@@ -31,9 +31,11 @@ namespace internal {
* \param rhs: The right hand side vector b
* \param x: On input and initial solution, on output the computed solution.
* \param precond: A preconditioner being able to efficiently solve for an
* approximation of Ax=b (regardless of b)
* \param iters: On input the max number of iteration, on output the number of performed iterations.
* \param tol_error: On input the tolerance error, on output an estimation of the relative error.
* approximation of Ax=b (regardless of b)
* \param iters: On input the max number of iteration,
* on output the number of performed iterations.
* \param tol_error: On input the tolerance error,
* on output an estimation of the relative error.
*/
template<typename MatrixType,
typename Rhs,
@@ -59,7 +61,7 @@ EIGEN_DONT_INLINE void constrained_conjugate_gradient(const MatrixType &mat,
int n = mat.cols();
VectorType residual = filter * (rhs - mat * x); //initial residual
VectorType residual = filter * (rhs - mat * x); // initial residual
RealScalar rhsNorm2 = (filter * rhs).squaredNorm();
if (rhsNorm2 == 0) {
@@ -78,7 +80,7 @@ EIGEN_DONT_INLINE void constrained_conjugate_gradient(const MatrixType &mat,
}
VectorType p(n);
p = filter * precond.solve(residual); //initial search direction
p = filter * precond.solve(residual); // initial search direction
VectorType z(n), tmp(n);
RealScalar absNew = numext::real(
@@ -157,17 +159,18 @@ struct traits<
/** \ingroup IterativeLinearSolvers_Module
* \brief A conjugate gradient solver for sparse self-adjoint problems with additional constraints
*
* This class allows to solve for A.x = b sparse linear problems using a conjugate gradient algorithm.
* The sparse matrix A must be selfadjoint. The vectors x and b can be either dense or sparse.
* This class allows to solve for A.x = b sparse linear problems using a conjugate gradient
* algorithm. The sparse matrix A must be selfadjoint. The vectors x and b can be either dense or
* sparse.
*
* \tparam _MatrixType the type of the sparse matrix A, can be a dense or a sparse matrix.
* \tparam _UpLo the triangular part that will be used for the computations. It can be Lower
* or Upper. Default is Lower.
* \tparam _Preconditioner the type of the preconditioner. Default is DiagonalPreconditioner
*
* The maximal number of iterations and tolerance value can be controlled via the setMaxIterations()
* and setTolerance() methods. The defaults are the size of the problem for the maximal number of iterations
* and NumTraits<Scalar>::epsilon() for the tolerance.
* The maximal number of iterations and tolerance value can be controlled via the
* setMaxIterations() and setTolerance() methods. The defaults are the size of the problem for the
* maximal number of iterations and NumTraits<Scalar>::epsilon() for the tolerance.
*
* This class can be used as the direct solver classes. Here is a typical usage example:
* \code

View File

@@ -140,8 +140,9 @@ typedef Eigen::SparseMatrix<Scalar> lMatrix;
/* Constructor type that provides more convenient handling of Eigen triplets
* for efficient construction of sparse 3x3 block matrices.
* This should be used for building lMatrix instead of writing to such lMatrix directly (which is very inefficient).
* After all elements have been defined using the set() method, the actual matrix can be filled using construct().
* This should be used for building lMatrix instead of writing to such lMatrix directly (which is
* very inefficient). After all elements have been defined using the set() method, the actual
* matrix can be filled using construct().
*/
struct lMatrix3fCtor {
lMatrix3fCtor()

View File

@@ -487,7 +487,9 @@ BLI_INLINE void hair_volume_add_segment_2D(HairGrid *grid,
BKE_sim_debug_data_add_dot(x2w, 0.1, 0.1, 0.7, "grid", 649, debug_i, j, k);
BKE_sim_debug_data_add_line(wloc, x2w, 0.3, 0.8, 0.3, "grid", 253, debug_i, j, k);
BKE_sim_debug_data_add_line(wloc, x3w, 0.8, 0.3, 0.3, "grid", 254, debug_i, j, k);
// BKE_sim_debug_data_add_circle(x2w, len_v3v3(wloc, x2w), 0.2, 0.7, 0.2, "grid", 255, i, j, k);
// BKE_sim_debug_data_add_circle(
// x2w, len_v3v3(wloc, x2w), 0.2, 0.7, 0.2,
// "grid", 255, i, j, k);
}
}
# endif
@@ -980,7 +982,9 @@ bool BPH_hair_volume_solve_divergence(HairGrid *grid,
if (!is_margin) {
float dvel[3];
sub_v3_v3v3(dvel, vert->velocity_smooth, vert->velocity);
// BKE_sim_debug_data_add_vector(grid->debug_data, wloc, dvel, 1, 1, 1, "grid", 5566, i, j, k);
// BKE_sim_debug_data_add_vector(
// grid->debug_data, wloc, dvel, 1, 1, 1,
// "grid", 5566, i, j, k);
}
if (!is_margin) {
@@ -990,8 +994,11 @@ bool BPH_hair_volume_solve_divergence(HairGrid *grid,
float col[3];
interp_v3_v3v3(col, col0, colp, d);
// if (d > 0.05f)
// BKE_sim_debug_data_add_dot(grid->debug_data, wloc, col[0], col[1], col[2], "grid", 5544, i, j, k);
// if (d > 0.05f) {
// BKE_sim_debug_data_add_dot(
// grid->debug_data, wloc, col[0], col[1], col[2],
// "grid", 5544, i, j, k);
// }
}
}
}

View File

@@ -766,7 +766,9 @@ DO_INLINE void filter(lfVector *V, fmatrix3x3 *S)
}
}
# if 0 /* this version of the CG algorithm does not work very well with partial constraints (where S has non-zero elements) */
/* this version of the CG algorithm does not work very well with partial constraints
* (where S has non-zero elements). */
# if 0
static int cg_filtered(lfVector *ldV, fmatrix3x3 *lA, lfVector *lB, lfVector *z, fmatrix3x3 *S)
{
// Solves for unknown X in equation AX=B
@@ -1455,7 +1457,8 @@ static float calc_nor_area_tri(float nor[3],
return normalize_v3(nor);
}
/* XXX does not support force jacobians yet, since the effector system does not provide them either */
/* 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])
{
@@ -1538,7 +1541,7 @@ void BPH_mass_spring_force_vertex_wind(Implicit_Data *data,
BLI_INLINE void dfdx_spring(float to[3][3], const float dir[3], float length, float L, float k)
{
// dir is unit length direction, rest is spring's restlength, k is spring constant.
//return ( (I-outerprod(dir, dir))*Min(1.0f, rest/length) - I) * -k;
// return ( (I-outerprod(dir, dir))*Min(1.0f, rest/length) - I) * -k;
outerproduct(to, dir, dir);
sub_m3_m3m3(to, I, to);
@@ -1699,7 +1702,8 @@ bool BPH_mass_spring_force_spring_linear(Implicit_Data *data,
dfdx_spring(dfdx, dir, length, restlen, stiffness_tension);
}
else if (new_compress) {
/* This is based on the Choi and Ko bending model, which works surprisingly well for compression. */
/* This is based on the Choi and Ko bending model,
* which works surprisingly well for compression. */
float kb = stiffness_compression;
float cb = kb; /* cb equal to kb seems to work, but a factor can be added if necessary */
@@ -1828,7 +1832,8 @@ BLI_INLINE void spring_angle(Implicit_Data *data,
sub_v3_v3(r_vel_b, vel_e);
}
/* Angular springs roughly based on the bending model proposed by Baraff and Witkin in "Large Steps in Cloth Simulation". */
/* Angular springs roughly based on the bending model proposed by Baraff and Witkin in "Large Steps
* in Cloth Simulation". */
bool BPH_mass_spring_force_spring_angular(Implicit_Data *data,
int i,
int j,

View File

@@ -182,8 +182,9 @@ typedef Eigen::SparseMatrix<Scalar> lMatrix;
/* Constructor type that provides more convenient handling of Eigen triplets
* for efficient construction of sparse 3x3 block matrices.
* This should be used for building lMatrix instead of writing to such lMatrix directly (which is very inefficient).
* After all elements have been defined using the set() method, the actual matrix can be filled using construct().
* This should be used for building lMatrix instead of writing to such lMatrix directly (which is
* very inefficient). After all elements have been defined using the set() method, the actual
* matrix can be filled using construct().
*/
struct lMatrixCtor {
lMatrixCtor()
@@ -814,7 +815,8 @@ static float calc_nor_area_tri(float nor[3],
return normalize_v3(nor);
}
/* XXX does not support force jacobians yet, since the effector system does not provide them either */
/* 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])
{
@@ -855,8 +857,8 @@ void BPH_mass_spring_force_edge_wind(Implicit_Data *data, int v1, int v2, const
BLI_INLINE void dfdx_spring(float to[3][3], const float dir[3], float length, float L, float k)
{
// dir is unit length direction, rest is spring's restlength, k is spring constant.
//return ( (I-outerprod(dir, dir))*Min(1.0f, rest/length) - I) * -k;
/* dir is unit length direction, rest is spring's restlength, k is spring constant. */
// return ((I - outerprod(dir, dir)) * Min(1.0f, rest / length) - I) * -k;
outerproduct(to, dir, dir);
sub_m3_m3m3(to, I, to);