From cc673669c749d56f4b3078cd831c2a0dd88bf6c0 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 31 Jul 2010 10:58:10 +0000 Subject: use more BLI math funcs (no functional changes) --- source/blender/blenloader/intern/readfile.c | 4 +- source/blender/editors/armature/editarmature.c | 16 +++---- source/blender/editors/object/object_transform.c | 53 +++++++-------------- source/blender/editors/space_view3d/drawobject.c | 56 ++++++++--------------- source/blender/editors/space_view3d/view3d_snap.c | 17 ++----- source/blender/editors/transform/transform.c | 12 ++--- source/blender/modifiers/intern/MOD_meshdeform.c | 4 +- 7 files changed, 56 insertions(+), 106 deletions(-) (limited to 'source') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index c050f25256a..943bf2c6f39 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -12406,9 +12406,7 @@ static void append_do_cursor(Scene *scene, Library *curlib, short flag) return; /* move from the center of the appended objects to cursor */ - centerloc[0]= (min[0]+max[0])/2; - centerloc[1]= (min[1]+max[1])/2; - centerloc[2]= (min[2]+max[2])/2; + mid_v3_v3v3(centerloc, min, max); curs = scene->cursor; VECSUB(centerloc,curs,centerloc); diff --git a/source/blender/editors/armature/editarmature.c b/source/blender/editors/armature/editarmature.c index 7db20fea6eb..989c5bdc0ba 100644 --- a/source/blender/editors/armature/editarmature.c +++ b/source/blender/editors/armature/editarmature.c @@ -428,7 +428,6 @@ void docenter_armature (Scene *scene, View3D *v3d, Object *ob, int centermode) bArmature *arm= ob->data; float cent[3] = {0.0f, 0.0f, 0.0f}; float min[3], max[3]; - float omat[3][3]; /* Put the armature into editmode */ if(ob!=obedit) @@ -437,7 +436,7 @@ void docenter_armature (Scene *scene, View3D *v3d, Object *ob, int centermode) /* Find the centerpoint */ if (centermode == 2) { float *fp= give_cursor(scene, v3d); - VECCOPY(cent, fp); + copy_v3_v3(cent, fp); invert_m4_m4(ob->imat, ob->obmat); mul_m4_v3(ob->imat, cent); } @@ -448,10 +447,8 @@ void docenter_armature (Scene *scene, View3D *v3d, Object *ob, int centermode) DO_MINMAX(ebone->head, min, max); DO_MINMAX(ebone->tail, min, max); } - - cent[0]= (min[0] + max[0]) / 2.0f; - cent[1]= (min[1] + max[1]) / 2.0f; - cent[2]= (min[2] + max[2]) / 2.0f; + + mid_v3_v3v3(cent, min, max); } /* Do the adjustments */ @@ -465,13 +462,12 @@ void docenter_armature (Scene *scene, View3D *v3d, Object *ob, int centermode) /* Adjust object location for new centerpoint */ if(centermode && obedit==NULL) { - copy_m3_m4(omat, ob->obmat); - - mul_m3_v3(omat, cent); + mul_mat3_m4_v3(ob->obmat, cent); /* ommit translation part */ add_v3_v3(ob->loc, cent); } - else + else { ED_armature_edit_free(ob); + } } /* ---------------------- */ diff --git a/source/blender/editors/object/object_transform.c b/source/blender/editors/object/object_transform.c index cd66b9ab2ba..bc8a2a2fc60 100644 --- a/source/blender/editors/object/object_transform.c +++ b/source/blender/editors/object/object_transform.c @@ -182,7 +182,7 @@ static int object_rotation_clear_exec(bContext *C, wmOperator *op) axis_angle_to_eulO( oldeul, EULER_ORDER_DEFAULT,ob->rotAxis, ob->rotAngle); } else { - VECCOPY(oldeul, ob->rot); + copy_v3_v3(oldeul, ob->rot); } eul[0]= eul[1]= eul[2]= 0.0f; @@ -706,8 +706,7 @@ static int object_origin_set_exec(bContext *C, wmOperator *op) { Main *bmain= CTX_data_main(C); Scene *scene= CTX_data_scene(C); - ScrArea *sa= CTX_wm_area(C); - View3D *v3d= sa->spacedata.first; + View3D *v3d= CTX_wm_view3d(C); Object *obedit= CTX_data_edit_object(C); Object *tob; Mesh *me, *tme; @@ -716,7 +715,7 @@ static int object_origin_set_exec(bContext *C, wmOperator *op) BPoint *bp; */ Nurb *nu, *nu1; EditVert *eve; - float cent[3], centn[3], min[3], max[3], omat[3][3]; + float cent[3], centn[3], min[3], max[3]; int a, total= 0; int centermode = RNA_enum_get(op->ptr, "type"); @@ -731,8 +730,8 @@ static int object_origin_set_exec(bContext *C, wmOperator *op) if (obedit && centermode > 0) { BKE_report(op->reports, RPT_ERROR, "Operation cannot be performed in EditMode"); return OPERATOR_CANCELLED; - } - cent[0]= cent[1]= cent[2]= 0.0; + } + zero_v3(cent); if(obedit) { @@ -745,7 +744,7 @@ static int object_origin_set_exec(bContext *C, wmOperator *op) for(eve= em->verts.first; eve; eve= eve->next) { if(v3d->around==V3D_CENTROID) { total++; - VECADD(cent, cent, eve->co); + add_v3_v3(cent, eve->co); } else { DO_MINMAX(eve->co, min, max); @@ -756,9 +755,7 @@ static int object_origin_set_exec(bContext *C, wmOperator *op) mul_v3_fl(cent, 1.0f/(float)total); } else { - cent[0]= (min[0]+max[0])/2.0f; - cent[1]= (min[1]+max[1])/2.0f; - cent[2]= (min[2]+max[2])/2.0f; + mid_v3_v3v3(cent, min, max); } for(eve= em->verts.first; eve; eve= eve->next) { @@ -792,7 +789,7 @@ static int object_origin_set_exec(bContext *C, wmOperator *op) tot_lib_error++; } else { if(centermode==2) { - VECCOPY(cent, give_cursor(scene, v3d)); + copy_v3_v3(cent, give_cursor(scene, v3d)); invert_m4_m4(ob->imat, ob->obmat); mul_m4_v3(ob->imat, cent); } else { @@ -801,10 +798,8 @@ static int object_origin_set_exec(bContext *C, wmOperator *op) for(a=0; atotvert; a++, mvert++) { DO_MINMAX(mvert->co, min, max); } - - cent[0]= (min[0]+max[0])/2.0f; - cent[1]= (min[1]+max[1])/2.0f; - cent[2]= (min[2]+max[2])/2.0f; + + mid_v3_v3v3(cent, min, max); } mvert= me->mvert; @@ -827,13 +822,9 @@ static int object_origin_set_exec(bContext *C, wmOperator *op) me->id.flag |= LIB_DOIT; if(centermode) { - copy_m3_m4(omat, ob->obmat); - copy_v3_v3(centn, cent); - mul_m3_v3(omat, centn); - ob->loc[0]+= centn[0]; - ob->loc[1]+= centn[1]; - ob->loc[2]+= centn[2]; + mul_mat3_m4_v3(ob->obmat, centn); /* ommit translation part */ + add_v3_v3(ob->loc, centn); where_is_object(scene, ob); ignore_parent_tx(bmain, scene, ob); @@ -848,12 +839,9 @@ static int object_origin_set_exec(bContext *C, wmOperator *op) ob_other->flag |= OB_DONE; ob_other->recalc= OB_RECALC_OB|OB_RECALC_DATA; - copy_m3_m4(omat, ob_other->obmat); copy_v3_v3(centn, cent); - mul_m3_v3(omat, centn); - ob_other->loc[0]+= centn[0]; - ob_other->loc[1]+= centn[1]; - ob_other->loc[2]+= centn[2]; + mul_mat3_m4_v3(ob_other->obmat, centn); /* ommit translation part */ + add_v3_v3(ob_other->loc, centn); where_is_object(scene, ob_other); ignore_parent_tx(bmain, scene, ob_other); @@ -920,9 +908,7 @@ static int object_origin_set_exec(bContext *C, wmOperator *op) nu= nu->next; } - cent[0]= (min[0]+max[0])/2.0f; - cent[1]= (min[1]+max[1])/2.0f; - cent[2]= (min[2]+max[2])/2.0f; + mid_v3_v3v3(cent, min, max); } nu= nu1; @@ -944,13 +930,8 @@ static int object_origin_set_exec(bContext *C, wmOperator *op) } if(centermode && obedit==NULL) { - copy_m3_m4(omat, ob->obmat); - - mul_m3_v3(omat, cent); - ob->loc[0]+= cent[0]; - ob->loc[1]+= cent[1]; - ob->loc[2]+= cent[2]; - + mul_mat3_m4_v3(ob->obmat, cent); /* ommit translation part */ + add_v3_v3(ob->loc, cent); where_is_object(scene, ob); ignore_parent_tx(bmain, scene, ob); } diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index 5bb1ea2cc9f..02a8709a1ac 100644 --- a/source/blender/editors/space_view3d/drawobject.c +++ b/source/blender/editors/space_view3d/drawobject.c @@ -446,11 +446,11 @@ void drawaxes(float size, int flag, char drawtype) for (axis=0; axis<4; axis++) { if (axis % 2 == 1) { - v2[0] *= -1; - v3[1] *= -1; + v2[0] = -v2[0]; + v3[1] = -v3[1]; } else { - v2[1] *= -1; - v3[0] *= -1; + v2[1] = -v2[1]; + v3[0] = -v3[0]; } glVertex3fv(v1); @@ -513,12 +513,10 @@ void drawcircball(int mode, float *cent, float rad, float tmat[][4]) { float vec[3], vx[3], vy[3]; int a, tot=32; - - VECCOPY(vx, tmat[0]); - VECCOPY(vy, tmat[1]); - mul_v3_fl(vx, rad); - mul_v3_fl(vy, rad); - + + mul_v3_v3fl(vx, tmat[0], rad); + mul_v3_v3fl(vy, tmat[1], rad); + glBegin(mode); for(a=0; aclipsta*lavec[0]; - sta[1]= mat[3][1]+ la->clipsta*lavec[1]; - sta[2]= mat[3][2]+ la->clipsta*lavec[2]; - - end[0]= mat[3][0]+ la->clipend*lavec[0]; - end[1]= mat[3][1]+ la->clipend*lavec[1]; - end[2]= mat[3][2]+ la->clipend*lavec[2]; - + madd_v3_v3v3fl(sta, mat[3], lavec, la->clipsta); + madd_v3_v3v3fl(end, mat[3], lavec, la->clipend); glBegin(GL_LINE_STRIP); glVertex3fv(sta); @@ -820,10 +812,7 @@ static void spotvolume(float *lvec, float *vvec, float inp) quat_to_mat3(mat1,q); /* rotate lamp vector now over acos(inp) degrees */ - - vvec[0] = lvec[0] ; - vvec[1] = lvec[1] ; - vvec[2] = lvec[2] ; + copy_v3_v3(vvec, lvec); unit_m3(mat2); co = inp; @@ -948,7 +937,7 @@ static void drawlamp(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base, } /* Inner Circle */ - VECCOPY(vec, ob->obmat[3]); + copy_v3_v3(vec, ob->obmat[3]); glEnable(GL_BLEND); drawcircball(GL_LINE_LOOP, vec, lampsize, imat); glDisable(GL_BLEND); @@ -987,10 +976,8 @@ static void drawlamp(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base, vec_rot_to_mat3( mat,imat[2], M_PI/4.0f); /* vectors */ - VECCOPY(v1, imat[0]); - mul_v3_fl(v1, circrad*1.2f); - VECCOPY(v2, imat[0]); - mul_v3_fl(v2, circrad*2.5f); + mul_v3_v3fl(v1, imat[0], circrad * 1.2f); + mul_v3_v3fl(v2, imat[0], circrad * 2.5f); /* center */ glTranslatef(vec[0], vec[1], vec[2]); @@ -1018,7 +1005,7 @@ static void drawlamp(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base, } glPopMatrix(); /* back in object space */ - vec[0]= vec[1]= vec[2]= 0.0f; + zero_v3(vec); if ((la->type==LA_SPOT) || (la->type==LA_YF_PHOTON)) { lvec[0]=lvec[1]= 0.0; @@ -1110,7 +1097,7 @@ static void drawlamp(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base, /* draw the hemisphere curves */ short axis, steps, dir; float outdist, zdist, mul; - vec[0]=vec[1]=vec[2]= 0.0; + zero_v3(vec); outdist = 0.14; mul = 1.4; dir = 1; setlinestyle(4); @@ -5246,8 +5233,8 @@ void get_local_bounds(Object *ob, float *center, float *size) BoundBox *bb= object_get_boundbox(ob); if(bb==NULL) { - center[0]= center[1]= center[2]= 0.0; - VECCOPY(size, ob->size); + zero_v3(center); + copy_v3_v3(size, ob->size); } else { size[0]= 0.5*fabs(bb->vec[0][0] - bb->vec[4][0]); @@ -5506,9 +5493,7 @@ void drawRBpivot(bRigidBodyJointConstraint *data) dir[axis] = 1.f; glBegin(GL_LINES); mul_m4_v3(mat,dir); - v[0] += dir[0]; - v[1] += dir[1]; - v[2] += dir[2]; + add_v3_v3(v, dir); glVertex3fv(v1); glVertex3fv(v); glEnd(); @@ -6154,9 +6139,8 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag) if(dtflag2 & V3D_RENDER_OVERRIDE)==0) { if((ob->gameflag & OB_DYNAMIC) || ((ob->gameflag & OB_BOUNDS) && (ob->boundtype == OB_BOUND_SPHERE))) { - float imat[4][4], vec[3]; + float imat[4][4], vec[3]= {0.0f, 0.0f, 0.0f}; - vec[0]= vec[1]= vec[2]= 0.0; invert_m4_m4(imat, rv3d->viewmatob); setlinestyle(2); diff --git a/source/blender/editors/space_view3d/view3d_snap.c b/source/blender/editors/space_view3d/view3d_snap.c index 160306ef300..9928ba1983e 100644 --- a/source/blender/editors/space_view3d/view3d_snap.c +++ b/source/blender/editors/space_view3d/view3d_snap.c @@ -365,7 +365,7 @@ static void make_trans_verts(Object *obedit, float *min, float *max, int mode) while(ml) { if(ml->flag & SELECT) { tv->loc= &ml->x; - VECCOPY(tv->oldloc, tv->loc); + copy_v3_v3(tv->oldloc, tv->loc); tv->val= &(ml->rad); tv->oldval= ml->rad; tv->flag= 1; @@ -387,7 +387,7 @@ static void make_trans_verts(Object *obedit, float *min, float *max, int mode) while(a--) { if((mode & 1) || (bp->f1 & SELECT)) { if(bp->hide==0) { - VECCOPY(tv->oldloc, bp->vec); + copy_v3_v3(tv->oldloc, bp->vec); tv->loc= bp->vec; tv->flag= bp->f1 & SELECT; tv++; @@ -403,23 +403,16 @@ static void make_trans_verts(Object *obedit, float *min, float *max, int mode) total= 0.0; for(a=0; aflag & SELECT) { - centroid[0]+= tv->oldloc[0]; - centroid[1]+= tv->oldloc[1]; - centroid[2]+= tv->oldloc[2]; + add_v3_v3(centroid, tv->oldloc); total+= 1.0; DO_MINMAX(tv->oldloc, min, max); } } if(total!=0.0) { - centroid[0]/= total; - centroid[1]/= total; - centroid[2]/= total; + mul_v3_fl(centroid, 1.0f/total); } - center[0]= (min[0]+max[0])/2.0; - center[1]= (min[1]+max[1])/2.0; - center[2]= (min[2]+max[2])/2.0; - + mid_v3_v3v3(center, min, max); } /* *********************** operators ******************** */ diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index 86fdb81e0d9..9743a4ef0f5 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -2171,21 +2171,19 @@ void initWarp(TransInfo *t) /* we need min/max in view space */ for(i = 0; i < t->total; i++) { float center[3]; - VECCOPY(center, t->data[i].center); + copy_v3_v3(center, t->data[i].center); mul_m3_v3(t->data[i].mtx, center); mul_m4_v3(t->viewmat, center); sub_v3_v3(center, t->viewmat[3]); if (i) minmax_v3_v3v3(min, max, center); else { - VECCOPY(max, center); - VECCOPY(min, center); + copy_v3_v3(max, center); + copy_v3_v3(min, center); } } - - t->center[0]= (min[0]+max[0])/2.0f; - t->center[1]= (min[1]+max[1])/2.0f; - t->center[2]= (min[2]+max[2])/2.0f; + + mid_v3_v3v3(t->center, min, max); if (max[0] == min[0]) max[0] += 0.1; /* not optimal, but flipping is better than invalid garbage (i.e. division by zero!) */ t->val= (max[0]-min[0])/2.0f; /* t->val is X dimension projected boundbox */ diff --git a/source/blender/modifiers/intern/MOD_meshdeform.c b/source/blender/modifiers/intern/MOD_meshdeform.c index 9ae86ac4ec0..9f102fe6c21 100644 --- a/source/blender/modifiers/intern/MOD_meshdeform.c +++ b/source/blender/modifiers/intern/MOD_meshdeform.c @@ -126,7 +126,7 @@ static float meshdeform_dynamic_bind(MeshDeformModifierData *mmd, float (*dco)[3 float weight, cageweight, totweight, *cageco; int i, j, a, x, y, z, size; - co[0]= co[1]= co[2]= 0.0f; + zero_v3(co); totweight= 0.0f; size= mmd->dyngridsize; @@ -312,7 +312,7 @@ static void meshdeformModifier_do( } else { totweight= 0.0f; - co[0]= co[1]= co[2]= 0.0f; + zero_v3(co); for(a=offsets[b]; a