Cleanup: remove all BLI_utiledefines' ugly vectorial macros.

Not only were those often making doublons with already existing
BLI_math's stuff, but they were also used to hide implicit type
conversions...

As usual this adds some more exotic inlined vector functions (one of
the rare cases where I really miss C++ and its templates... ;) ).
This commit is contained in:
Bastien Montagne 2019-01-20 16:22:55 +01:00
parent b0dee09a6d
commit 482c4d099a
9 changed files with 93 additions and 80 deletions

View File

@ -428,9 +428,9 @@ static void collision_compute_barycentric ( float pv[3], float p1[3], float p2[3
double tempV1[3], tempV2[3], tempV4[3];
double a, b, c, d, e, f;
VECSUB ( tempV1, p1, p3 );
VECSUB ( tempV2, p2, p3 );
VECSUB ( tempV4, pv, p3 );
sub_v3db_v3fl_v3fl(tempV1, p1, p3);
sub_v3db_v3fl_v3fl(tempV2, p2, p3);
sub_v3db_v3fl_v3fl(tempV4, pv, p3);
a = INPR ( tempV1, tempV1 );
b = INPR ( tempV1, tempV2 );
@ -1131,8 +1131,8 @@ static int cloth_bvh_objcollisions_resolve(ClothModifierData * clmd, Object **co
for (i = 0; i < mvert_num; i++) {
// calculate "velocities" (just xnew = xold + v; no dt in v)
if (verts[i].impulse_count) {
VECADD ( verts[i].tv, verts[i].tv, verts[i].impulse);
VECADD ( verts[i].dcvel, verts[i].dcvel, verts[i].impulse);
add_v3_v3(verts[i].tv, verts[i].impulse);
add_v3_v3(verts[i].dcvel, verts[i].impulse);
zero_v3(verts[i].impulse);
verts[i].impulse_count = 0;
@ -1168,8 +1168,8 @@ static int cloth_bvh_selfcollisions_resolve(ClothModifierData * clmd, CollPair *
for (i = 0; i < mvert_num; i++) {
if (verts[i].impulse_count) {
// VECADDMUL ( verts[i].tv, verts[i].impulse, 1.0f / verts[i].impulse_count );
VECADD ( verts[i].tv, verts[i].tv, verts[i].impulse);
VECADD ( verts[i].dcvel, verts[i].dcvel, verts[i].impulse);
add_v3_v3(verts[i].tv, verts[i].impulse);
add_v3_v3(verts[i].dcvel, verts[i].impulse);
zero_v3(verts[i].impulse);
verts[i].impulse_count = 0;
@ -1305,7 +1305,7 @@ int cloth_bvh_collision(Depsgraph *depsgraph, Object *ob, ClothModifierData *clm
}
}
VECADD(verts[i].tx, verts[i].txold, verts[i].tv);
add_v3_v3v3(verts[i].tx, verts[i].txold, verts[i].tv);
}
}
@ -1572,7 +1572,7 @@ void cloth_find_point_contacts(Depsgraph *depsgraph, Object *ob, ClothModifierDa
}
}
VECADD(verts[i].tx, verts[i].txold, verts[i].tv);
add_v3_v3v3(verts[i].tx, verts[i].txold, verts[i].tv);
}
////////////////////////////////////////////////////////////

View File

@ -811,7 +811,7 @@ static int ptcache_smoke_read(PTCacheFile *pf, void *smoke_v)
sds->active_fields = active_fields | cache_fields;
smoke_reallocate_fluid(sds, ch_dx, ch_res, 1);
sds->dx = ch_dx;
VECCOPY(sds->res, ch_res);
copy_v3_v3_int(sds->res, ch_res);
sds->total_cells = ch_res[0]*ch_res[1]*ch_res[2];
if (sds->flags & MOD_SMOKE_HIGHRES) {
smoke_reallocate_highres_fluid(sds, ch_dx, ch_res, 1);

View File

@ -296,12 +296,12 @@ static int smokeModifier_init(SmokeModifierData *smd, Object *ob, int scene_fram
res[0] = res[1] = res[2] = 1; /* use minimum res for adaptive init */
}
else {
VECCOPY(res, sds->base_res);
copy_v3_v3_int(res, sds->base_res);
}
VECCOPY(sds->res, res);
copy_v3_v3_int(sds->res, res);
sds->total_cells = sds->res[0] * sds->res[1] * sds->res[2];
sds->res_min[0] = sds->res_min[1] = sds->res_min[2] = 0;
VECCOPY(sds->res_max, res);
copy_v3_v3_int(sds->res_max, res);
/* allocate fluid */
smoke_reallocate_fluid(sds, sds->dx, sds->res, 0);
@ -881,7 +881,7 @@ static void obstacles_from_mesh(
normal_float_to_short_v3(mvert[i].no, n);
/* vert velocity */
VECADD(co, mvert[i].co, sds->shift);
add_v3fl_v3fl_v3i(co, mvert[i].co, sds->shift);
if (has_velocity)
{
sub_v3_v3v3(&vert_vel[i * 3], co, &scs->verts_old[i * 3]);
@ -1254,8 +1254,7 @@ static void emit_from_particles_task_cb(
1.0f : (1.0f - (nearest.dist - data->solid) / data->smooth);
/* Uses particle velocity as initial velocity for smoke */
if (sfs->flags & MOD_SMOKE_FLOW_INITVELOCITY && (sfs->psys->part->phystype != PART_PHYS_NO)) {
VECADDFAC(&em->velocity[index * 3], &em->velocity[index * 3],
&data->particle_vel[nearest.index * 3], sfs->vel_multi);
madd_v3_v3fl(&em->velocity[index * 3], &data->particle_vel[nearest.index * 3], sfs->vel_multi);
}
}
}
@ -1414,7 +1413,7 @@ static void emit_from_particles(
/* Uses particle velocity as initial velocity for smoke */
if (sfs->flags & MOD_SMOKE_FLOW_INITVELOCITY && (psys->part->phystype != PART_PHYS_NO))
{
VECADDFAC(&em->velocity[index * 3], &em->velocity[index * 3], &particle_vel[p * 3], sfs->vel_multi);
madd_v3_v3fl(&em->velocity[index * 3], &particle_vel[p * 3], sfs->vel_multi);
}
} // particles loop
}
@ -1736,7 +1735,7 @@ static void emit_from_mesh(Object *flow_ob, SmokeDomainSettings *sds, SmokeFlowS
/* vert velocity */
if (sfs->flags & MOD_SMOKE_FLOW_INITVELOCITY) {
float co[3];
VECADD(co, mvert[i].co, sds->shift);
add_v3fl_v3fl_v3i(co, mvert[i].co, sds->shift);
if (has_velocity) {
sub_v3_v3v3(&vert_vel[i * 3], co, &sfs->verts_old[i * 3]);
mul_v3_fl(&vert_vel[i * 3], sds->dx / dt);
@ -2052,9 +2051,9 @@ static void adjustDomainResolution(SmokeDomainSettings *sds, int new_shift[3], E
smoke_turbulence_free(turb_old);
/* set new domain dimensions */
VECCOPY(sds->res_min, min);
VECCOPY(sds->res_max, max);
VECCOPY(sds->res, res);
copy_v3_v3_int(sds->res_min, min);
copy_v3_v3_int(sds->res_max, max);
copy_v3_v3_int(sds->res, res);
sds->total_cells = total_cells;
}
}
@ -2150,7 +2149,7 @@ static void update_flowsfluids(
mul_m4_v3(ob->obmat, ob_loc);
VECSUB(frame_shift_f, ob_loc, sds->prev_loc);
sub_v3_v3v3(frame_shift_f, ob_loc, sds->prev_loc);
copy_v3_v3(sds->prev_loc, ob_loc);
/* convert global space shift to local "cell" space */
mul_mat3_m4_v3(sds->imat, frame_shift_f);
@ -2158,12 +2157,12 @@ static void update_flowsfluids(
frame_shift_f[1] = frame_shift_f[1] / sds->cell_size[1];
frame_shift_f[2] = frame_shift_f[2] / sds->cell_size[2];
/* add to total shift */
VECADD(sds->shift_f, sds->shift_f, frame_shift_f);
add_v3_v3(sds->shift_f, frame_shift_f);
/* convert to integer */
total_shift[0] = floor(sds->shift_f[0]);
total_shift[1] = floor(sds->shift_f[1]);
total_shift[2] = floor(sds->shift_f[2]);
VECSUB(new_shift, total_shift, sds->shift);
total_shift[0] = (int)(floorf(sds->shift_f[0]));
total_shift[1] = (int)(floorf(sds->shift_f[1]));
total_shift[2] = (int)(floorf(sds->shift_f[2]));
sub_v3_v3v3_int(new_shift, total_shift, sds->shift);
copy_v3_v3_int(sds->shift, total_shift);
/* calculate new domain boundary points so that smoke doesn't slide on sub-cell movement */
@ -2689,8 +2688,8 @@ static Mesh *createDomainGeometry(SmokeDomainSettings *sds, Object *ob)
if (num_verts) {
/* volume bounds */
VECMADD(min, sds->p0, sds->cell_size, sds->res_min);
VECMADD(max, sds->p0, sds->cell_size, sds->res_max);
madd_v3fl_v3fl_v3fl_v3i(min, sds->p0, sds->cell_size, sds->res_min);
madd_v3fl_v3fl_v3fl_v3i(max, sds->p0, sds->cell_size, sds->res_max);
/* set vertices */
/* top slab */
@ -2729,7 +2728,7 @@ static Mesh *createDomainGeometry(SmokeDomainSettings *sds, Object *ob)
invert_m4_m4(ob->imat, ob->obmat);
mul_m4_v3(ob->obmat, ob_loc);
mul_m4_v3(sds->obmat, ob_cache_loc);
VECSUB(sds->obj_shift_f, ob_cache_loc, ob_loc);
sub_v3_v3v3(sds->obj_shift_f, ob_cache_loc, ob_loc);
/* convert shift to local space and apply to vertices */
mul_mat3_m4_v3(ob->imat, sds->obj_shift_f);
/* apply */

View File

@ -83,6 +83,8 @@ MINLINE void zero_v3_db(double r[3]);
MINLINE void copy_v2_v2_db(double r[2], const double a[2]);
MINLINE void copy_v3_v3_db(double r[3], const double a[3]);
MINLINE void copy_v4_v4_db(double r[4], const double a[4]);
/* short -> float */
MINLINE void copy_v3fl_v3s(float r[3], const short a[3]);
/* int <-> float */
MINLINE void copy_v2fl_v2i(float r[2], const int a[2]);
MINLINE void round_v2i_v2fl(int r[2], const float a[2]);
@ -112,14 +114,20 @@ MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3]);
MINLINE void add_v4_v4(float r[4], const float a[4]);
MINLINE void add_v4_v4v4(float r[4], const float a[4], const float b[4]);
MINLINE void add_v3fl_v3fl_v3i(float r[3], const float a[3], const int b[3]);
MINLINE void add_v3fl_v3fl_v3s(float r[3], const float a[3], const short b[3]);
MINLINE void sub_v2_v2(float r[2], const float a[2]);
MINLINE void sub_v2_v2v2(float r[2], const float a[2], const float b[2]);
MINLINE void sub_v2_v2v2_int(int r[2], const int a[2], const int b[2]);
MINLINE void sub_v3_v3(float r[3], const float a[3]);
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3]);
MINLINE void sub_v3_v3v3_int(int r[3], const int a[3], const int b[3]);
MINLINE void sub_v4_v4(float r[4], const float a[4]);
MINLINE void sub_v4_v4v4(float r[4], const float a[4], const float b[4]);
MINLINE void sub_v3db_v3fl_v3fl(double r[3], const float a[3], const float b[3]);
MINLINE void mul_v2_fl(float r[2], float f);
MINLINE void mul_v2_v2fl(float r[2], const float a[2], float f);
MINLINE void mul_v3_fl(float r[3], float f);
@ -150,6 +158,8 @@ MINLINE void madd_v3_v3v3v3(float r[3], const float a[3], const float b[3], cons
MINLINE void madd_v4_v4fl(float r[4], const float a[4], float f);
MINLINE void madd_v4_v4v4(float r[4], const float a[4], const float b[4]);
MINLINE void madd_v3fl_v3fl_v3fl_v3i(float r[3], const float a[3], const float b[3], const int c[3]);
MINLINE void negate_v2(float r[2]);
MINLINE void negate_v2_v2(float r[2], const float a[2]);
MINLINE void negate_v3(float r[3]);

View File

@ -224,45 +224,6 @@ extern "C" {
b = tmp; \
} (void)0
#define VECCOPY(v1, v2) { \
*(v1) = *(v2); \
*(v1 + 1) = *(v2 + 1); \
*(v1 + 2) = *(v2 + 2); \
} (void)0
#define VECCOPY2D(v1, v2) { \
*(v1) = *(v2); \
*(v1 + 1) = *(v2 + 1); \
} (void)0
#define VECADD(v1, v2, v3) { \
*(v1) = *(v2) + *(v3); \
*(v1 + 1) = *(v2 + 1) + *(v3 + 1); \
*(v1 + 2) = *(v2 + 2) + *(v3 + 2); \
} (void)0
#define VECSUB(v1, v2, v3) { \
*(v1) = *(v2) - *(v3); \
*(v1 + 1) = *(v2 + 1) - *(v3 + 1); \
*(v1 + 2) = *(v2 + 2) - *(v3 + 2); \
} (void)0
#define VECSUB2D(v1, v2, v3) { \
*(v1) = *(v2) - *(v3); \
*(v1 + 1) = *(v2 + 1) - *(v3 + 1); \
} (void)0
#define VECADDFAC(v1, v2, v3, fac) { \
*(v1) = *(v2) + *(v3) * (fac); \
*(v1 + 1) = *(v2 + 1) + *(v3 + 1) * (fac); \
*(v1 + 2) = *(v2 + 2) + *(v3 + 2) * (fac); \
} (void)0
#define VECMADD(v1, v2, v3, v4) { \
*(v1) = *(v2) + *(v3) * (*(v4)); \
*(v1 + 1) = *(v2 + 1) + *(v3 + 1) * (*(v4 + 1)); \
*(v1 + 2) = *(v2 + 2) + *(v3 + 2) * (*(v4 + 2)); \
} (void)0
#define VECSUBFAC(v1, v2, v3, fac) { \
*(v1) = *(v2) - *(v3) * (fac); \
*(v1 + 1) = *(v2 + 1) - *(v3 + 1) * (fac); \
*(v1 + 2) = *(v2 + 2) - *(v3 + 2) * (fac); \
} (void)0
/* some misc stuff.... */
/* avoid multiple access for supported compilers */

View File

@ -68,6 +68,13 @@ MINLINE void copy_v3_v3(float r[3], const float a[3])
r[2] = a[2];
}
MINLINE void copy_v3fl_v3s(float r[3], const short a[3])
{
r[0] = (float)a[0];
r[1] = (float)a[1];
r[2] = (float)a[2];
}
MINLINE void copy_v4_v4(float r[4], const float a[4])
{
r[0] = a[0];
@ -378,6 +385,20 @@ MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3])
r[2] = a[2] + b[2];
}
MINLINE void add_v3fl_v3fl_v3i(float r[3], const float a[3], const int b[3])
{
r[0] = a[0] + (float)b[0];
r[1] = a[1] + (float)b[1];
r[2] = a[2] + (float)b[2];
}
MINLINE void add_v3fl_v3fl_v3s(float r[3], const float a[3], const short b[3])
{
r[0] = a[0] + (float)b[0];
r[1] = a[1] + (float)b[1];
r[2] = a[2] + (float)b[2];
}
MINLINE void add_v4_v4(float r[4], const float a[4])
{
r[0] += a[0];
@ -426,6 +447,20 @@ MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
r[2] = a[2] - b[2];
}
MINLINE void sub_v3_v3v3_int(int r[3], const int a[3], const int b[3])
{
r[0] = a[0] - b[0];
r[1] = a[1] - b[1];
r[2] = a[2] - b[2];
}
MINLINE void sub_v3db_v3fl_v3fl(double r[3], const float a[3], const float b[3])
{
r[0] = (double)a[0] - (double)b[0];
r[1] = (double)a[1] - (double)b[1];
r[2] = (double)a[2] - (double)b[2];
}
MINLINE void sub_v4_v4(float r[4], const float a[4])
{
r[0] -= a[0];
@ -622,6 +657,13 @@ MINLINE void madd_v3_v3v3v3(float r[3], const float a[3], const float b[3], cons
r[2] = a[2] + b[2] * c[2];
}
MINLINE void madd_v3fl_v3fl_v3fl_v3i(float r[3], const float a[3], const float b[3], const int c[3])
{
r[0] = a[0] + b[0] * (float)c[0];
r[1] = a[1] + b[1] * (float)c[1];
r[2] = a[2] + b[2] * (float)c[2];
}
MINLINE void madd_v4_v4fl(float r[4], const float a[4], float f)
{
r[0] += a[0] * f;

View File

@ -238,7 +238,7 @@ static int armature_click_extrude_invoke(bContext *C, wmOperator *op, const wmEv
copy_v3_v3(oldcurs, cursor->location);
VECCOPY2D(mval_f, event->mval);
copy_v2fl_v2i(mval_f, event->mval);
ED_view3d_win_to_3d(v3d, ar, cursor->location, mval_f, tvec);
copy_v3_v3(cursor->location, tvec);

View File

@ -1325,25 +1325,26 @@ void recalc_emitter_field(Depsgraph *UNUSED(depsgraph), Object *UNUSED(ob), Part
mvert = &mesh->mvert[mface->v1];
copy_v3_v3(vec, mvert->co);
VECCOPY(nor, mvert->no);
copy_v3fl_v3s(nor, mvert->no);
mvert = &mesh->mvert[mface->v2];
add_v3_v3v3(vec, vec, mvert->co);
VECADD(nor, nor, mvert->no);
add_v3fl_v3fl_v3s(nor, nor, mvert->no);
mvert = &mesh->mvert[mface->v3];
add_v3_v3v3(vec, vec, mvert->co);
VECADD(nor, nor, mvert->no);
add_v3fl_v3fl_v3s(nor, nor, mvert->no);
if (mface->v4) {
mvert = &mesh->mvert[mface->v4];
add_v3_v3v3(vec, vec, mvert->co);
VECADD(nor, nor, mvert->no);
add_v3fl_v3fl_v3s(nor, nor, mvert->no);
mul_v3_fl(vec, 0.25);
}
else
else {
mul_v3_fl(vec, 1.0f / 3.0f);
}
normalize_v3(nor);
@ -4360,7 +4361,7 @@ static void brush_edit_apply_event(bContext *C, wmOperator *op, const wmEvent *e
PointerRNA itemptr;
float mouse[2];
VECCOPY2D(mouse, event->mval);
copy_v2fl_v2i(mouse, event->mval);
/* fill in stroke */
RNA_collection_add(op->ptr, "stroke", &itemptr);

View File

@ -216,7 +216,7 @@ DO_INLINE void add_lfvector_lfvector(float(*to)[3], float(*fLongVectorA)[3], flo
unsigned int i = 0;
for (i = 0; i < verts; i++) {
VECADD(to[i], fLongVectorA[i], fLongVectorB[i]);
add_v3_v3v3(to[i], fLongVectorA[i], fLongVectorB[i]);
}
}
@ -431,9 +431,9 @@ DO_INLINE void mul_fmatrix_fvector(float *to, float matrix[3][3], float from[3])
/* 3x3 matrix addition with 3x3 matrix */
DO_INLINE void add_fmatrix_fmatrix(float to[3][3], float matrixA[3][3], float matrixB[3][3])
{
VECADD(to[0], matrixA[0], matrixB[0]);
VECADD(to[1], matrixA[1], matrixB[1]);
VECADD(to[2], matrixA[2], matrixB[2]);
add_v3_v3v3(to[0], matrixA[0], matrixB[0]);
add_v3_v3v3(to[1], matrixA[1], matrixB[1]);
add_v3_v3v3(to[2], matrixA[2], matrixB[2]);
}
/* A -= B*x + C*y (3x3 matrix sub-addition with 3x3 matrix) */
DO_INLINE void subadd_fmatrixS_fmatrixS(float to[3][3], float matrixA[3][3], float aS, float matrixB[3][3], float bS)