diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-02-25 23:26:38 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-02-25 23:26:38 +0300 |
commit | db744f8b7fc1415293a9ded3729fd5924e61fc2a (patch) | |
tree | bf5cfeaa8f611a76890db6d3d4e4b75e8b148376 | |
parent | 3eaad6b3eb3ff87af45b106be638f1148d4186db (diff) |
use math functions in view code, no functional changes.
-rw-r--r-- | source/blender/editors/space_view3d/view3d_edit.c | 72 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_view.c | 21 |
2 files changed, 28 insertions, 65 deletions
diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 8bc9ec386d0..27fe63ba657 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -110,9 +110,7 @@ static void view3d_boxview_clip(ScrArea *sa) if(ar->winx>ar->winy) y1= ar->winy*rv3d->dist/ar->winx; else y1= rv3d->dist; - - ofs[0]= rv3d->ofs[0]; - ofs[1]= rv3d->ofs[1]; + copy_v2_v2(ofs, rv3d->ofs); } else if(ELEM(rv3d->view, RV3D_VIEW_FRONT, RV3D_VIEW_BACK)) { ofs[2]= rv3d->ofs[2]; @@ -372,8 +370,7 @@ static void viewops_data_create(bContext *C, wmOperator *op, wmEvent *event) closest_to_line_v3(dvec, vod->dyn_ofs, my_pivot, my_origin); vod->dist0 = rv3d->dist = len_v3v3(my_pivot, dvec); - negate_v3(dvec); - VECCOPY(rv3d->ofs, dvec); + negate_v3_v3(rv3d->ofs, dvec); } negate_v3(vod->dyn_ofs); VECCOPY(vod->ofs, rv3d->ofs); @@ -548,11 +545,8 @@ static void viewrotate_apply(ViewOpsData *vod, int x, int y) * dragged. */ phi = si * M_PI / 2.0; - si= sin(phi); q1[0]= cos(phi); - q1[1]*= si; - q1[2]*= si; - q1[3]*= si; + mul_v3_fl(q1+1, sin(phi)); mul_qt_qtqt(rv3d->viewquat, q1, vod->oldquat); if (vod->use_dyn_ofs) { @@ -570,7 +564,7 @@ static void viewrotate_apply(ViewOpsData *vod, int x, int y) } else { /* New turntable view code by John Aughey */ - float si, phi, q1[4]; + float phi, q1[4]; float m[3][3]; float m_inv[3][3]; float xvec[3] = {1,0,0}; @@ -590,11 +584,8 @@ static void viewrotate_apply(ViewOpsData *vod, int x, int y) /* Perform the up/down rotation */ phi = sensitivity * -(y - vod->oldy); - si = sin(phi); q1[0] = cos(phi); - q1[1] = si * xvec[0]; - q1[2] = si * xvec[1]; - q1[3] = si * xvec[2]; + mul_v3_v3fl(q1+1, xvec, sin(phi)); mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, q1); if (vod->use_dyn_ofs) { @@ -635,12 +626,10 @@ static void viewrotate_apply(ViewOpsData *vod, int x, int y) if ((dot_v3v3(snapmat[0], viewmat[0]) > thres) && (dot_v3v3(snapmat[1], viewmat[1]) > thres) && - (dot_v3v3(snapmat[2], viewmat[2]) > thres)){ - - QUATCOPY(rv3d->viewquat, snapquats[i]); - - rv3d->view = view; - + (dot_v3v3(snapmat[2], viewmat[2]) > thres) + ) { + copy_qt_qt(rv3d->viewquat, snapquats[i]); + rv3d->view= view; break; } } @@ -969,18 +958,15 @@ static void view_zoom_mouseloc(ARegion *ar, float dfac, int mx, int my) vb[0] = ar->winx; vb[1] = ar->winy; - tpos[0] = -rv3d->ofs[0]; - tpos[1] = -rv3d->ofs[1]; - tpos[2] = -rv3d->ofs[2]; + negate_v3_v3(tpos, rv3d->ofs); /* Project cursor position into 3D space */ initgrabz(rv3d, tpos[0], tpos[1], tpos[2]); window_to_3d_delta(ar, dvec, mouseloc[0]-vb[0]/2, mouseloc[1]-vb[1]/2); /* Calculate view target position for dolly */ - tvec[0] = -(tpos[0] + dvec[0]); - tvec[1] = -(tpos[1] + dvec[1]); - tvec[2] = -(tpos[2] + dvec[2]); + add_v3_v3v3(tvec, tpos, dvec); + negate_v3(tvec); /* Offset to target position and dolly */ new_dist = rv3d->dist * dfac; @@ -989,11 +975,7 @@ static void view_zoom_mouseloc(ARegion *ar, float dfac, int mx, int my) rv3d->dist = new_dist; /* Calculate final offset */ - dvec[0] = tvec[0] + dvec[0] * dfac; - dvec[1] = tvec[1] + dvec[1] * dfac; - dvec[2] = tvec[2] + dvec[2] * dfac; - - VECCOPY(rv3d->ofs, dvec); + madd_v3_v3v3fl(rv3d->ofs, tvec, dvec, dfac); } else { rv3d->dist *= dfac; } @@ -1407,9 +1389,7 @@ static int viewselected_exec(bContext *C, wmOperator *op) /* like a localview wi if(ok==0) return OPERATOR_FINISHED; - afm[0]= (max[0]-min[0]); - afm[1]= (max[1]-min[1]); - afm[2]= (max[2]-min[2]); + sub_v3_v3v3(afm, max, min); size= MAX3(afm[0], afm[1], afm[2]); if(rv3d->persp==RV3D_ORTHO) { @@ -1427,10 +1407,7 @@ static int viewselected_exec(bContext *C, wmOperator *op) /* like a localview wi } } - new_ofs[0]= -(min[0]+max[0])/2.0f; - new_ofs[1]= -(min[1]+max[1])/2.0f; - new_ofs[2]= -(min[2]+max[2])/2.0f; - + madd_v3_v3v3fl(new_ofs, min, max, -0.5f); new_dist = size; /* correction for window aspect ratio */ @@ -1703,9 +1680,7 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op) new_ofs[2] = -p[2]; } else { /* We cant use the depth, fallback to the old way that dosnt set the center depth */ - new_ofs[0] = rv3d->ofs[0]; - new_ofs[1] = rv3d->ofs[1]; - new_ofs[2] = rv3d->ofs[2]; + copy_v3_v3(new_ofs, rv3d->ofs); initgrabz(rv3d, -new_ofs[0], -new_ofs[1], -new_ofs[2]); @@ -1979,7 +1954,7 @@ static EnumPropertyItem prop_view_orbit_items[] = { static int vieworbit_exec(bContext *C, wmOperator *op) { RegionView3D *rv3d= CTX_wm_region_view3d(C); - float phi, si, q1[4], new_quat[4]; + float phi, q1[4], new_quat[4]; int orbitdir; orbitdir = RNA_enum_get(op->ptr, "type"); @@ -1988,6 +1963,7 @@ static int vieworbit_exec(bContext *C, wmOperator *op) if(rv3d->persp != RV3D_CAMOB) { if(orbitdir == V3D_VIEW_STEPLEFT || orbitdir == V3D_VIEW_STEPRIGHT) { + float si; /* z-axis */ phi= (float)(M_PI/360.0)*U.pad_rot_angle; if(orbitdir == V3D_VIEW_STEPRIGHT) phi= -phi; @@ -2005,11 +1981,8 @@ static int vieworbit_exec(bContext *C, wmOperator *op) normalize_v3(q1+1); phi= (float)(M_PI/360.0)*U.pad_rot_angle; if(orbitdir == V3D_VIEW_STEPDOWN) phi= -phi; - si= (float)sin(phi); q1[0]= (float)cos(phi); - q1[1]*= si; - q1[2]*= si; - q1[3]*= si; + mul_v3_fl(q1+1, sin(phi)); mul_qt_qtqt(new_quat, rv3d->viewquat, q1); rv3d->view= 0; } @@ -2812,7 +2785,7 @@ void viewmoveNDOF(Scene *scene, ARegion *ar, View3D *v3d, int mode) float xvec[3] = {1,0,0}; float yvec[3] = {0,-1,0}; float zvec[3] = {0,0,1}; - float phi, si; + float phi; float q1[4]; float obofs[3]; float reverse; @@ -2961,11 +2934,8 @@ void viewmoveNDOF(Scene *scene, ARegion *ar, View3D *v3d, int mode) /* Perform the up/down rotation */ phi = sbadjust * rsens * /*0.5f * */ fval[3]; /* spin vertically half as fast as horizontally */ - si = sin(phi); q1[0] = cos(phi); - q1[1] = si * xvec[0]; - q1[2] = si * xvec[1]; - q1[3] = si * xvec[2]; + mul_v3_v3fl(q1+1, xvec, sin(phi)); mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, q1); if (use_sel) { diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c index 09d8d79f8f5..906f6e4da41 100644 --- a/source/blender/editors/space_view3d/view3d_view.c +++ b/source/blender/editors/space_view3d/view3d_view.c @@ -404,13 +404,9 @@ static void setcameratoview3d(View3D *v3d, RegionView3D *rv3d, Object *ob) { float dvec[3]; float mat3[3][3]; - - dvec[0]= rv3d->dist*rv3d->viewinv[2][0]; - dvec[1]= rv3d->dist*rv3d->viewinv[2][1]; - dvec[2]= rv3d->dist*rv3d->viewinv[2][2]; - - VECCOPY(ob->loc, dvec); - sub_v3_v3v3(ob->loc, ob->loc, rv3d->ofs); + + mul_v3_v3fl(dvec, rv3d->viewinv[2], rv3d->dist); + sub_v3_v3v3(ob->loc, dvec, rv3d->ofs); rv3d->viewquat[0]= -rv3d->viewquat[0]; // quat_to_eul( ob->rot,rv3d->viewquat); // in 2.4x for xyz eulers only @@ -602,9 +598,7 @@ void viewvector(RegionView3D *rv3d, float coord[3], float vec[3]) p2[3] = 1.0f; mul_m4_v4(rv3d->viewmat, p2); - p2[0] = 2.0f * p2[0]; - p2[1] = 2.0f * p2[1]; - p2[2] = 2.0f * p2[2]; + mul_v3_fl(p2, 2.0f); mul_m4_v4(rv3d->viewinv, p2); @@ -2612,10 +2606,9 @@ void view3d_align_axis_to_vector(View3D *v3d, RegionView3D *rv3d, int axisidx, f if(axisidx > 0) alignaxis[axisidx-1]= 1.0; else alignaxis[-axisidx-1]= -1.0; - - VECCOPY(norm, vec); - normalize_v3(norm); - + + normalize_v3_v3(norm, vec); + angle= (float)acos(dot_v3v3(alignaxis, norm)); cross_v3_v3v3(axis, alignaxis, norm); axis_angle_to_quat( new_quat,axis, -angle); |