Cleanup: style

Also 'com' as abbreviation for center-of-mass is a bit confusing, rename to 'center'.
This commit is contained in:
Campbell Barton 2015-07-20 05:19:47 +10:00
parent 23a4f547e7
commit e58d788340
9 changed files with 65 additions and 50 deletions

View File

@ -272,9 +272,10 @@ bool BKE_mesh_center_bounds(const struct Mesh *me, float r_cent[3]);
bool BKE_mesh_center_centroid(const struct Mesh *me, float r_cent[3]);
void BKE_mesh_calc_volume(
const struct MVert *mverts, const int numVerts,
const struct MLoopTri *mlooptri, const int numTris,
const struct MLoop *mloop, float *r_vol, float *r_com);
const struct MVert *mverts, const int mverts_num,
const struct MLoopTri *mlooptri, const int looptri_num,
const struct MLoop *mloop,
float *r_volume, float r_center[3]);
/* tessface */
void BKE_mesh_loops_to_mface_corners(

View File

@ -69,7 +69,7 @@ void BKE_rigidbody_world_groups_relink(struct RigidBodyWorld *rbw);
void BKE_rigidbody_validate_sim_world(struct Scene *scene, struct RigidBodyWorld *rbw, bool rebuild);
void BKE_rigidbody_calc_volume(struct Object *ob, float *r_vol);
void BKE_rigidbody_calc_center_of_mass(struct Object *ob, float r_com[3]);
void BKE_rigidbody_calc_center_of_mass(struct Object *ob, float r_center[3]);
/* -------------- */
/* Utilities */

View File

@ -3157,8 +3157,8 @@ DerivedMesh *CDDM_merge_verts(DerivedMesh *dm, const int *vtargetmap, const int
}
/*create new cddm*/
cddm2 = (CDDerivedMesh *)CDDM_from_template((
DerivedMesh *)cddm, STACK_SIZE(mvert), STACK_SIZE(medge), 0, STACK_SIZE(mloop), STACK_SIZE(mpoly));
cddm2 = (CDDerivedMesh *)CDDM_from_template(
(DerivedMesh *)cddm, STACK_SIZE(mvert), STACK_SIZE(medge), 0, STACK_SIZE(mloop), STACK_SIZE(mpoly));
/*update edge indices and copy customdata*/
med = medge;

View File

@ -2046,20 +2046,21 @@ bool BKE_mesh_center_centroid(const Mesh *me, float r_cent[3])
* \{ */
static bool mesh_calc_center_centroid_ex(
const MVert *mverts, int UNUSED(numVerts),
const MLoopTri *lt, int numTris,
const MVert *mverts, int UNUSED(mverts_num),
const MLoopTri *looptri, int looptri_num,
const MLoop *mloop, float r_center[3])
{
const MLoopTri *lt;
float totweight;
int t;
int i;
zero_v3(r_center);
if (numTris == 0)
if (looptri_num == 0)
return false;
totweight = 0.0f;
for (t = 0; t < numTris; t++, lt++) {
for (i = 0, lt = looptri; i < looptri_num; i++, lt++) {
const MVert *v1 = &mverts[mloop[lt->tri[0]].v];
const MVert *v2 = &mverts[mloop[lt->tri[1]].v];
const MVert *v3 = &mverts[mloop[lt->tri[2]].v];
@ -2079,40 +2080,52 @@ static bool mesh_calc_center_centroid_ex(
return true;
}
void BKE_mesh_calc_volume(const MVert *mverts, const int numVerts,
const MLoopTri *lt, const int numTris,
const MLoop *mloop, float *r_vol, float *r_com)
/**
* Calculate the volume and center.
*
* \param r_volume: Volume (unsigned).
* \param r_center: Center of mass.
*/
void BKE_mesh_calc_volume(
const MVert *mverts, const int mverts_num,
const MLoopTri *looptri, const int looptri_num,
const MLoop *mloop,
float *r_volume, float r_center[3])
{
const MLoopTri *lt;
float center[3];
float totvol;
int f;
int i;
if (r_vol) *r_vol = 0.0f;
if (r_com) zero_v3(r_com);
if (r_volume)
*r_volume = 0.0f;
if (r_center)
zero_v3(r_center);
if (numTris == 0)
if (looptri_num == 0)
return;
if (!mesh_calc_center_centroid_ex(mverts, numVerts, lt, numTris, mloop, center))
if (!mesh_calc_center_centroid_ex(mverts, mverts_num, looptri, looptri_num, mloop, center))
return;
totvol = 0.0f;
for (f = 0; f < numTris; f++, lt++) {
for (i = 0, lt = looptri; i < looptri_num; i++, lt++) {
const MVert *v1 = &mverts[mloop[lt->tri[0]].v];
const MVert *v2 = &mverts[mloop[lt->tri[1]].v];
const MVert *v3 = &mverts[mloop[lt->tri[2]].v];
float vol;
vol = volume_tetrahedron_signed_v3(center, v1->co, v2->co, v3->co);
if (r_vol) {
if (r_volume) {
totvol += vol;
}
if (r_com) {
if (r_center) {
/* averaging factor 1/4 is applied in the end */
madd_v3_v3fl(r_com, center, vol); // XXX could extract this
madd_v3_v3fl(r_com, v1->co, vol);
madd_v3_v3fl(r_com, v2->co, vol);
madd_v3_v3fl(r_com, v3->co, vol);
madd_v3_v3fl(r_center, center, vol); /* XXX could extract this */
madd_v3_v3fl(r_center, v1->co, vol);
madd_v3_v3fl(r_center, v2->co, vol);
madd_v3_v3fl(r_center, v3->co, vol);
}
}
@ -2120,15 +2133,15 @@ void BKE_mesh_calc_volume(const MVert *mverts, const int numVerts,
* totvol can become negative even for a valid mesh.
* The true value is always the positive value.
*/
if (r_vol) {
*r_vol = fabsf(totvol);
if (r_volume) {
*r_volume = fabsf(totvol);
}
if (r_com) {
if (r_center) {
/* Note: Factor 1/4 is applied once for all vertices here.
* This also automatically negates the vector if totvol is negative.
*/
if (totvol != 0.0f)
mul_v3_fl(r_com, 0.25f / totvol);
mul_v3_fl(r_center, 0.25f / totvol);
}
}
@ -2318,7 +2331,7 @@ int BKE_mesh_recalc_tessellation(
/* We abuse MFace->edcode to tag quad faces. See below for details. */
#define TESSFACE_IS_QUAD 1
const int looptris_tot = poly_to_tri_count(totpoly, totloop);
const int looptri_num = poly_to_tri_count(totpoly, totloop);
MPoly *mp, *mpoly;
MLoop *ml, *mloop;
@ -2335,9 +2348,9 @@ int BKE_mesh_recalc_tessellation(
/* allocate the length of totfaces, avoid many small reallocs,
* if all faces are tri's it will be correct, quads == 2x allocs */
/* take care. we are _not_ calloc'ing so be sure to initialize each field */
mface_to_poly_map = MEM_mallocN(sizeof(*mface_to_poly_map) * (size_t)looptris_tot, __func__);
mface = MEM_mallocN(sizeof(*mface) * (size_t)looptris_tot, __func__);
lindices = MEM_mallocN(sizeof(*lindices) * (size_t)looptris_tot, __func__);
mface_to_poly_map = MEM_mallocN(sizeof(*mface_to_poly_map) * (size_t)looptri_num, __func__);
mface = MEM_mallocN(sizeof(*mface) * (size_t)looptri_num, __func__);
lindices = MEM_mallocN(sizeof(*lindices) * (size_t)looptri_num, __func__);
mface_index = 0;
mp = mpoly;
@ -2497,10 +2510,10 @@ int BKE_mesh_recalc_tessellation(
CustomData_free(fdata, totface);
totface = mface_index;
BLI_assert(totface <= looptris_tot);
BLI_assert(totface <= looptri_num);
/* not essential but without this we store over-alloc'd memory in the CustomData layers */
if (LIKELY(looptris_tot != totface)) {
if (LIKELY(looptri_num != totface)) {
mface = MEM_reallocN(mface, sizeof(*mface) * (size_t)totface);
mface_to_poly_map = MEM_reallocN(mface_to_poly_map, sizeof(*mface_to_poly_map) * (size_t)totface);
}

View File

@ -554,14 +554,14 @@ void BKE_rigidbody_calc_volume(Object *ob, float *r_vol)
if (r_vol) *r_vol = volume;
}
void BKE_rigidbody_calc_center_of_mass(Object *ob, float r_com[3])
void BKE_rigidbody_calc_center_of_mass(Object *ob, float r_center[3])
{
RigidBodyOb *rbo = ob->rigidbody_object;
float size[3] = {1.0f, 1.0f, 1.0f};
float height = 1.0f;
zero_v3(r_com);
zero_v3(r_center);
/* if automatically determining dimensions, use the Object's boundbox
* - assume that all quadrics are standing upright on local z-axis
@ -586,7 +586,7 @@ void BKE_rigidbody_calc_center_of_mass(Object *ob, float r_com[3])
/* cone is geometrically centered on the median,
* center of mass is 1/4 up from the base
*/
r_com[2] = -0.25f * height;
r_center[2] = -0.25f * height;
break;
case RB_SHAPE_CONVEXH:
@ -595,7 +595,7 @@ void BKE_rigidbody_calc_center_of_mass(Object *ob, float r_com[3])
if (ob->type == OB_MESH) {
DerivedMesh *dm = rigidbody_get_mesh(ob);
MVert *mvert;
const MLoopTri* lt = NULL;
const MLoopTri *looptri = NULL;
int totvert, tottri = 0;
const MLoop* mloop = NULL;
@ -607,12 +607,12 @@ void BKE_rigidbody_calc_center_of_mass(Object *ob, float r_com[3])
mvert = dm->getVertArray(dm);
totvert = dm->getNumVerts(dm);
lt = dm->getLoopTriArray(dm);
looptri = dm->getLoopTriArray(dm);
tottri = dm->getNumLoopTri(dm);
mloop = dm->getLoopArray(dm);
if (totvert > 0 && tottri > 0) {
BKE_mesh_calc_volume(mvert, totvert, lt, tottri, mloop, NULL, r_com);
BKE_mesh_calc_volume(mvert, totvert, looptri, tottri, mloop, NULL, r_center);
}
/* cleanup temp data */
@ -1593,7 +1593,7 @@ struct RigidBodyCon *BKE_rigidbody_copy_constraint(Object *ob) { return NULL; }
void BKE_rigidbody_relink_constraint(RigidBodyCon *rbc) {}
void BKE_rigidbody_validate_sim_world(Scene *scene, RigidBodyWorld *rbw, bool rebuild) {}
void BKE_rigidbody_calc_volume(Object *ob, float *r_vol) { if (r_vol) *r_vol = 0.0f; }
void BKE_rigidbody_calc_center_of_mass(Object *ob, float r_com[3]) { zero_v3(r_com); }
void BKE_rigidbody_calc_center_of_mass(Object *ob, float r_center[3]) { zero_v3(r_center); }
struct RigidBodyWorld *BKE_rigidbody_create_world(Scene *scene) { return NULL; }
struct RigidBodyWorld *BKE_rigidbody_world_copy(RigidBodyWorld *rbw) { return NULL; }
void BKE_rigidbody_world_groups_relink(struct RigidBodyWorld *rbw) {}

View File

@ -3524,8 +3524,8 @@ static bool project_paint_flt_max_cull(
{
if (!ps->is_ortho) {
if (coSS->v1[0] == FLT_MAX ||
coSS->v2[0] == FLT_MAX ||
coSS->v3[0] == FLT_MAX)
coSS->v2[0] == FLT_MAX ||
coSS->v3[0] == FLT_MAX)
{
return true;
}
@ -4350,8 +4350,9 @@ static void do_projectpaint_mask_f(ProjPaintState *ps, ProjPixel *projPixel, flo
}
}
static void image_paint_partial_redraw_expand(ImagePaintPartialRedraw *cell,
const ProjPixel *projPixel)
static void image_paint_partial_redraw_expand(
ImagePaintPartialRedraw *cell,
const ProjPixel *projPixel)
{
cell->x1 = min_ii(cell->x1, (int)projPixel->x_px);
cell->y1 = min_ii(cell->y1, (int)projPixel->y_px);

View File

@ -160,7 +160,7 @@ static int space_image_buffer_exists_poll(bContext *C)
{
SpaceImage *sima = CTX_wm_space_image(C);
if (sima && ED_space_image_has_buffer(sima)) {
return true;
return true;
}
return false;
}

View File

@ -287,7 +287,7 @@ enum {
LIB_ID_RECALC_DATA = 1 << 13,
LIB_ANIM_NO_RECALC = 1 << 14,
LIB_ID_RECALC_ALL = (LIB_ID_RECALC|LIB_ID_RECALC_DATA),
LIB_ID_RECALC_ALL = (LIB_ID_RECALC | LIB_ID_RECALC_DATA),
};
#ifdef __cplusplus

View File

@ -1000,7 +1000,7 @@ int BPH_cloth_solve(Object *ob, float frame, ClothModifierData *clmd, ListBase *
if (clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_GOAL) { /* do goal stuff */
for (i = 0; i < numverts; i++) {
// update velocities with constrained velocities from pinned verts
if (verts [i].flags & CLOTH_VERT_FLAG_PINNED) {
if (verts[i].flags & CLOTH_VERT_FLAG_PINNED) {
float v[3];
sub_v3_v3v3(v, verts[i].xconst, verts[i].xold);
// mul_v3_fl(v, clmd->sim_parms->stepsPerFrame);