Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_view3d/view3d_edit.c
| Show First 20 Lines • Show All 3,958 Lines • ▼ Show 20 Lines | |||||
| static EnumPropertyItem prop_view_orbit_items[] = { | static EnumPropertyItem prop_view_orbit_items[] = { | ||||
| {V3D_VIEW_STEPLEFT, "ORBITLEFT", 0, "Orbit Left", "Orbit the view around to the Left"}, | {V3D_VIEW_STEPLEFT, "ORBITLEFT", 0, "Orbit Left", "Orbit the view around to the Left"}, | ||||
| {V3D_VIEW_STEPRIGHT, "ORBITRIGHT", 0, "Orbit Right", "Orbit the view around to the Right"}, | {V3D_VIEW_STEPRIGHT, "ORBITRIGHT", 0, "Orbit Right", "Orbit the view around to the Right"}, | ||||
| {V3D_VIEW_STEPUP, "ORBITUP", 0, "Orbit Up", "Orbit the view Up"}, | {V3D_VIEW_STEPUP, "ORBITUP", 0, "Orbit Up", "Orbit the view Up"}, | ||||
| {V3D_VIEW_STEPDOWN, "ORBITDOWN", 0, "Orbit Down", "Orbit the view Down"}, | {V3D_VIEW_STEPDOWN, "ORBITDOWN", 0, "Orbit Down", "Orbit the view Down"}, | ||||
| {0, NULL, 0, NULL, NULL} | {0, NULL, 0, NULL, NULL} | ||||
| }; | }; | ||||
| static EnumPropertyItem prop_view_orbit_style_items[] = { | |||||
| {V3D_VIEW_TURNTABLE, "TURNTABLE", 0, "Turntable", "Use turntable style orbit"}, | |||||
| {V3D_VIEW_TRACKBALL, "TRACKBALL", 0, "Trackball", "Use trackball style orbit"}, | |||||
| {0, NULL, 0, NULL, NULL} | |||||
| }; | |||||
| static int vieworbit_exec(bContext *C, wmOperator *op) | static int vieworbit_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| View3D *v3d; | View3D *v3d; | ||||
| ARegion *ar; | ARegion *ar; | ||||
| RegionView3D *rv3d; | RegionView3D *rv3d; | ||||
| int orbitdir; | int orbitdir, orbitstyle; | ||||
| char view_opposite; | char view_opposite; | ||||
| PropertyRNA *prop_angle = RNA_struct_find_property(op->ptr, "angle"); | PropertyRNA *prop_angle = RNA_struct_find_property(op->ptr, "angle"); | ||||
| float angle = RNA_property_is_set(op->ptr, prop_angle) ? | float angle = RNA_property_is_set(op->ptr, prop_angle) ? | ||||
| RNA_property_float_get(op->ptr, prop_angle) : DEG2RADF(U.pad_rot_angle); | RNA_property_float_get(op->ptr, prop_angle) : DEG2RADF(U.pad_rot_angle); | ||||
| /* no NULL check is needed, poll checks */ | /* no NULL check is needed, poll checks */ | ||||
| v3d = CTX_wm_view3d(C); | v3d = CTX_wm_view3d(C); | ||||
| ar = CTX_wm_region(C); | ar = CTX_wm_region(C); | ||||
| rv3d = ar->regiondata; | rv3d = ar->regiondata; | ||||
| /* support for switching to the opposite view (even when in locked views) */ | /* support for switching to the opposite view (even when in locked views) */ | ||||
| view_opposite = (fabsf(angle) == (float)M_PI) ? ED_view3d_axis_view_opposite(rv3d->view) : RV3D_VIEW_USER; | view_opposite = (fabsf(angle) == (float)M_PI) ? ED_view3d_axis_view_opposite(rv3d->view) : RV3D_VIEW_USER; | ||||
| orbitdir = RNA_enum_get(op->ptr, "type"); | orbitdir = RNA_enum_get(op->ptr, "type"); | ||||
| orbitstyle = RNA_enum_get(op->ptr, "style"); | |||||
| if ((rv3d->viewlock & RV3D_LOCKED) && (view_opposite == RV3D_VIEW_USER)) { | if ((rv3d->viewlock & RV3D_LOCKED) && (view_opposite == RV3D_VIEW_USER)) { | ||||
| /* no NULL check is needed, poll checks */ | /* no NULL check is needed, poll checks */ | ||||
| ED_view3d_context_user_region(C, &v3d, &ar); | ED_view3d_context_user_region(C, &v3d, &ar); | ||||
| rv3d = ar->regiondata; | rv3d = ar->regiondata; | ||||
| } | } | ||||
| if ((rv3d->viewlock & RV3D_LOCKED) == 0 || (view_opposite != RV3D_VIEW_USER)) { | if ((rv3d->viewlock & RV3D_LOCKED) == 0 || (view_opposite != RV3D_VIEW_USER)) { | ||||
| if ((rv3d->persp != RV3D_CAMOB) || ED_view3d_camera_lock_check(v3d, rv3d)) { | if ((rv3d->persp != RV3D_CAMOB) || ED_view3d_camera_lock_check(v3d, rv3d)) { | ||||
| int smooth_viewtx = WM_operator_smooth_viewtx_get(op); | int smooth_viewtx = WM_operator_smooth_viewtx_get(op); | ||||
| float quat_mul[4]; | float quat_mul[4]; | ||||
| float quat_new[4]; | float quat_new[4]; | ||||
| if (view_opposite == RV3D_VIEW_USER) { | if (view_opposite == RV3D_VIEW_USER) { | ||||
| view3d_ensure_persp(v3d, ar); | view3d_ensure_persp(v3d, ar); | ||||
| } | } | ||||
| if (ELEM(orbitdir, V3D_VIEW_STEPLEFT, V3D_VIEW_STEPRIGHT)) { | if (ELEM(orbitdir, V3D_VIEW_STEPLEFT, V3D_VIEW_STEPRIGHT)) { | ||||
| if (orbitdir == V3D_VIEW_STEPRIGHT) { | if (orbitdir == V3D_VIEW_STEPRIGHT) { | ||||
| angle = -angle; | angle = -angle; | ||||
| } | } | ||||
| if (orbitstyle == V3D_VIEW_TURNTABLE) { | |||||
| /* Global Z-axis */ | |||||
| axis_angle_to_quat_single(quat_mul, 'Z', angle); | |||||
| } | |||||
| else { | |||||
| /* View Y-axis */ | /* View Y-axis */ | ||||
| axis_angle_to_quat(quat_mul, rv3d->viewinv[1], angle); | axis_angle_to_quat(quat_mul, rv3d->viewinv[1], angle); | ||||
| } | } | ||||
| } | |||||
| else { | else { | ||||
| if (orbitdir == V3D_VIEW_STEPDOWN) { | if (orbitdir == V3D_VIEW_STEPDOWN) { | ||||
| angle = -angle; | angle = -angle; | ||||
| } | } | ||||
| if (orbitstyle == V3D_VIEW_TURNTABLE) { | |||||
| /* Global horizontal axis */ | |||||
| float nor[3]; | |||||
| /* we want axis_view to lie in Oxy and be 'visually' perpendicular | |||||
| * to Oz, which is equivalent to having it perpendicular to view's Z | |||||
| */ | |||||
| float axis_view[3] = { | |||||
| -rv3d->viewinv[2][1], | |||||
| rv3d->viewinv[2][0], | |||||
| 0.0f}; | |||||
| /* ensure consistent rotation direction */ | |||||
| if (rv3d->viewinv[1][2] < 0.0f) { | |||||
| mul_v3_fl(axis_view, -1.0f); | |||||
| } | |||||
| /* fall back to local X-axis if degenerated orientation (aligned to Z) */ | |||||
| if (normalize_v3_v3(nor, axis_view) == 0.0f) { | |||||
| copy_v3_v3(axis_view, rv3d->viewinv[0]); | |||||
| } | |||||
| axis_angle_to_quat(quat_mul, axis_view, angle); | |||||
| } | |||||
| else { | |||||
| /* View X-axis */ | /* View X-axis */ | ||||
| axis_angle_to_quat(quat_mul, rv3d->viewinv[0], angle); | axis_angle_to_quat(quat_mul, rv3d->viewinv[0], angle); | ||||
| } | } | ||||
| } | |||||
| mul_qt_qtqt(quat_new, rv3d->viewquat, quat_mul); | mul_qt_qtqt(quat_new, rv3d->viewquat, quat_mul); | ||||
| if (view_opposite != RV3D_VIEW_USER) { | if (view_opposite != RV3D_VIEW_USER) { | ||||
| rv3d->view = view_opposite; | rv3d->view = view_opposite; | ||||
| /* avoid float in-precision, just get a new orientation */ | /* avoid float in-precision, just get a new orientation */ | ||||
| ED_view3d_quat_from_axis_view(view_opposite, quat_new); | ED_view3d_quat_from_axis_view(view_opposite, quat_new); | ||||
| } | } | ||||
| Show All 39 Lines | void VIEW3D_OT_view_orbit(wmOperatorType *ot) | ||||
| ot->flag = 0; | ot->flag = 0; | ||||
| /* properties */ | /* properties */ | ||||
| prop = RNA_def_float(ot->srna, "angle", 0, -FLT_MAX, FLT_MAX, "Roll", "", -FLT_MAX, FLT_MAX); | prop = RNA_def_float(ot->srna, "angle", 0, -FLT_MAX, FLT_MAX, "Roll", "", -FLT_MAX, FLT_MAX); | ||||
| RNA_def_property_flag(prop, PROP_SKIP_SAVE); | RNA_def_property_flag(prop, PROP_SKIP_SAVE); | ||||
| ot->prop = RNA_def_enum(ot->srna, "type", prop_view_orbit_items, 0, "Orbit", "Direction of View Orbit"); | ot->prop = RNA_def_enum(ot->srna, "type", prop_view_orbit_items, 0, "Orbit", "Direction of View Orbit"); | ||||
| RNA_def_enum(ot->srna, "style", prop_view_orbit_style_items, V3D_VIEW_TRACKBALL, "Style", "Style of View Orbit"); | |||||
| } | } | ||||
| /* ************************ viewroll ******************************** */ | /* ************************ viewroll ******************************** */ | ||||
| static void view_roll_angle(ARegion *ar, float quat[4], const float orig_quat[4], const float dvec[3], float angle) | static void view_roll_angle(ARegion *ar, float quat[4], const float orig_quat[4], const float dvec[3], float angle) | ||||
| { | { | ||||
| RegionView3D *rv3d = ar->regiondata; | RegionView3D *rv3d = ar->regiondata; | ||||
| ▲ Show 20 Lines • Show All 1,173 Lines • Show Last 20 Lines | |||||