Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_view3d/view3d_edit.c
| Show First 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| else if (U.uiflag & USER_AUTOPERSP) { | else if (U.uiflag & USER_AUTOPERSP) { | ||||
| rv3d->persp = vod->init.persp; | rv3d->persp = vod->init.persp; | ||||
| } | } | ||||
| } | } | ||||
| static void viewrotate_apply(ViewOpsData *vod, const int event_xy[2]) | static void viewrotate_apply(ViewOpsData *vod, const int event_xy[2], const float deg) | ||||
| { | { | ||||
| RegionView3D *rv3d = vod->rv3d; | RegionView3D *rv3d = vod->rv3d; | ||||
| rv3d->view = RV3D_VIEW_USER; /* need to reset every time because of view snapping */ | rv3d->view = RV3D_VIEW_USER; /* need to reset every time because of view snapping */ | ||||
| if (U.flag & USER_TRACKBALL) { | if ((U.flag & USER_TRACKBALL) && !deg) { /* MOUSEROTATE always rotates as a Turntable. */ | ||||
| float axis[3], q1[4], dvec[3], newvec[3]; | float axis[3], q1[4], dvec[3], newvec[3]; | ||||
| float angle; | float angle; | ||||
| { | { | ||||
| const int event_xy_offset[2] = { | const int event_xy_offset[2] = { | ||||
| event_xy[0] + vod->init.event_xy_offset[0], | event_xy[0] + vod->init.event_xy_offset[0], | ||||
| event_xy[1] + vod->init.event_xy_offset[1], | event_xy[1] + vod->init.event_xy_offset[1], | ||||
| }; | }; | ||||
| Show All 23 Lines | |||||
| viewrotate_apply_dyn_ofs(vod, vod->curr.viewquat); | viewrotate_apply_dyn_ofs(vod, vod->curr.viewquat); | ||||
| } | } | ||||
| else { | else { | ||||
| float quat_local_x[4], quat_global_z[4]; | float quat_local_x[4], quat_global_z[4]; | ||||
| float m[3][3]; | float m[3][3]; | ||||
| float m_inv[3][3]; | float m_inv[3][3]; | ||||
| const float zvec_global[3] = {0.0f, 0.0f, 1.0f}; | const float zvec_global[3] = {0.0f, 0.0f, 1.0f}; | ||||
| float xaxis[3]; | float xaxis[3]; | ||||
| float angle_x, angle_z; | |||||
| /* Radians per-pixel. */ | /* Radians per-pixel. */ | ||||
| const float sensitivity = U.view_rotate_sensitivity_turntable / U.dpi_fac; | const float sensitivity = U.view_rotate_sensitivity_turntable / U.dpi_fac; | ||||
| /* Get the 3x3 matrix and its inverse from the quaternion */ | /* Get the 3x3 matrix and its inverse from the quaternion */ | ||||
| quat_to_mat3(m, vod->curr.viewquat); | quat_to_mat3(m, vod->curr.viewquat); | ||||
| invert_m3_m3(m_inv, m); | invert_m3_m3(m_inv, m); | ||||
| Show All 37 Lines | |||||
| } | } | ||||
| else { | else { | ||||
| copy_v3_v3(xaxis, m_inv[0]); | copy_v3_v3(xaxis, m_inv[0]); | ||||
| } | } | ||||
| #else | #else | ||||
| copy_v3_v3(xaxis, m_inv[0]); | copy_v3_v3(xaxis, m_inv[0]); | ||||
| #endif | #endif | ||||
| /* MOUSEROTATE performs an orbital rotation directly using degrees. */ | |||||
| if (deg) { | |||||
| angle_x = 0.0f; | |||||
| angle_z = vod->reverse * DEG2RADF(deg); | |||||
| } | |||||
| else { | |||||
| angle_x = sensitivity * -(event_xy[1] - vod->prev.event_xy[1]); | |||||
| angle_z = sensitivity * vod->reverse * (event_xy[0] - vod->prev.event_xy[0]); | |||||
| } | |||||
| /* Determine the direction of the x vector (for rotating up and down) */ | /* Determine the direction of the x vector (for rotating up and down) */ | ||||
| /* This can likely be computed directly from the quaternion. */ | /* This can likely be computed directly from the quaternion. */ | ||||
| /* Perform the up/down rotation */ | /* Perform the up/down rotation */ | ||||
| axis_angle_to_quat(quat_local_x, xaxis, sensitivity * -(event_xy[1] - vod->prev.event_xy[1])); | axis_angle_to_quat(quat_local_x, xaxis, angle_x); | ||||
| mul_qt_qtqt(quat_local_x, vod->curr.viewquat, quat_local_x); | mul_qt_qtqt(quat_local_x, vod->curr.viewquat, quat_local_x); | ||||
| /* Perform the orbital rotation */ | /* Perform the orbital rotation */ | ||||
| axis_angle_to_quat_single( | axis_angle_to_quat_single(quat_global_z, 'Z', angle_z); | ||||
| quat_global_z, 'Z', sensitivity * vod->reverse * (event_xy[0] - vod->prev.event_xy[0])); | |||||
| mul_qt_qtqt(vod->curr.viewquat, quat_local_x, quat_global_z); | mul_qt_qtqt(vod->curr.viewquat, quat_local_x, quat_global_z); | ||||
| viewrotate_apply_dyn_ofs(vod, vod->curr.viewquat); | viewrotate_apply_dyn_ofs(vod, vod->curr.viewquat); | ||||
| } | } | ||||
| /* avoid precision loss over time */ | /* avoid precision loss over time */ | ||||
| normalize_qt(vod->curr.viewquat); | normalize_qt(vod->curr.viewquat); | ||||
| ▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | |||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| else if (event->type == vod->init.event_type && event->val == KM_RELEASE) { | else if (event->type == vod->init.event_type && event->val == KM_RELEASE) { | ||||
| event_code = VIEW_CONFIRM; | event_code = VIEW_CONFIRM; | ||||
| } | } | ||||
| if (event_code == VIEW_APPLY) { | if (event_code == VIEW_APPLY) { | ||||
| viewrotate_apply(vod, event->xy); | viewrotate_apply(vod, event->xy, 0.0f); | ||||
| if (ED_screen_animation_playing(CTX_wm_manager(C))) { | if (ED_screen_animation_playing(CTX_wm_manager(C))) { | ||||
| use_autokey = true; | use_autokey = true; | ||||
| } | } | ||||
| } | } | ||||
| else if (event_code == VIEW_CONFIRM) { | else if (event_code == VIEW_CONFIRM) { | ||||
| use_autokey = true; | use_autokey = true; | ||||
| ret = OPERATOR_FINISHED; | ret = OPERATOR_FINISHED; | ||||
| } | } | ||||
| Show All 33 Lines | |||||
| viewops_flag_from_prefs() | VIEWOPS_FLAG_PERSP_ENSURE | | viewops_flag_from_prefs() | VIEWOPS_FLAG_PERSP_ENSURE | | ||||
| (use_cursor_init ? VIEWOPS_FLAG_USE_MOUSE_INIT : 0)); | (use_cursor_init ? VIEWOPS_FLAG_USE_MOUSE_INIT : 0)); | ||||
| if (ELEM(event->type, MOUSEPAN, MOUSEROTATE)) { | if (ELEM(event->type, MOUSEPAN, MOUSEROTATE)) { | ||||
| /* Rotate direction we keep always same */ | /* Rotate direction we keep always same */ | ||||
| int event_xy[2]; | int event_xy[2]; | ||||
| if (event->type == MOUSEPAN) { | if (event->type == MOUSEPAN) { | ||||
| if (event->is_direction_inverted) { | event_xy[0] = event->xy[0] + WM_event_absolute_delta_x(event); | ||||
| event_xy[0] = 2 * event->xy[0] - event->prev_xy[0]; | event_xy[1] = event->xy[1] + WM_event_absolute_delta_y(event); | ||||
| event_xy[1] = 2 * event->xy[1] - event->prev_xy[1]; | |||||
| } | |||||
| else { | |||||
| copy_v2_v2_int(event_xy, event->prev_xy); | |||||
| } | |||||
| } | } | ||||
| else { | else { | ||||
| /* MOUSEROTATE performs orbital rotation, so y axis delta is set to 0 */ | /* MOUSEROTATE performs orbital rotation using 'event->factor' in degrees. */ | ||||
| copy_v2_v2_int(event_xy, event->prev_xy); | copy_v2_v2_int(event_xy, event->xy); | ||||
| } | } | ||||
| viewrotate_apply(vod, event_xy); | viewrotate_apply(vod, event_xy, event->factor); | ||||
| viewops_data_free(C, op); | viewops_data_free(C, op); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| /* add temp handler */ | /* add temp handler */ | ||||
| WM_event_add_modal_handler(C, op); | WM_event_add_modal_handler(C, op); | ||||
| ▲ Show 20 Lines • Show All 184 Lines • ▼ Show 20 Lines | |||||
| val_orig, | val_orig, | ||||
| r_timer_lastdraw); | r_timer_lastdraw); | ||||
| } | } | ||||
| static void viewzoom_apply_camera(ViewOpsData *vod, | static void viewzoom_apply_camera(ViewOpsData *vod, | ||||
| const int xy[2], | const int xy[2], | ||||
| const eViewZoom_Style viewzoom, | const eViewZoom_Style viewzoom, | ||||
| const bool zoom_invert, | const bool zoom_invert, | ||||
| const bool zoom_to_pos) | const bool zoom_to_pos, | ||||
| const float fac) | |||||
| { | { | ||||
| float zfac; | float zfac; | ||||
| float zoomfac_prev = BKE_screen_view3d_zoom_to_fac(vod->init.camzoom) * 2.0f; | float zoomfac_prev = BKE_screen_view3d_zoom_to_fac(vod->init.camzoom) * 2.0f; | ||||
| float zoomfac = BKE_screen_view3d_zoom_to_fac(vod->rv3d->camzoom) * 2.0f; | float zoomfac = BKE_screen_view3d_zoom_to_fac(vod->rv3d->camzoom) * 2.0f; | ||||
| zfac = viewzoom_scale_value_offset(&vod->region->winrct, | if (fac) { /* MOUSEZOOM */ | ||||
| viewzoom, | zfac = 1.0f + fac; | ||||
| zoom_invert, | } | ||||
| true, | else { | ||||
| xy, | zfac = viewzoom_scale_value_offset(&vod->region->winrct, | ||||
| vod->init.event_xy, | viewzoom, | ||||
| vod->init.event_xy_offset, | zoom_invert, | ||||
| zoomfac, | true, | ||||
| zoomfac_prev, | xy, | ||||
| &vod->prev.time); | vod->init.event_xy, | ||||
| vod->init.event_xy_offset, | |||||
| zoomfac, | |||||
| zoomfac_prev, | |||||
| &vod->prev.time); | |||||
| } | |||||
| if (!ELEM(zfac, 1.0f, 0.0f)) { | if (!ELEM(zfac, 1.0f, 0.0f)) { | ||||
| /* calculate inverted, then invert again (needed because of camera zoom scaling) */ | /* calculate inverted, then invert again (needed because of camera zoom scaling) */ | ||||
| zfac = 1.0f / zfac; | zfac = 1.0f / zfac; | ||||
| view_zoom_to_window_xy_camera(vod->scene, | view_zoom_to_window_xy_camera(vod->scene, | ||||
| vod->depsgraph, | vod->depsgraph, | ||||
| vod->v3d, | vod->v3d, | ||||
| vod->region, | vod->region, | ||||
| zfac, | zfac, | ||||
| zoom_to_pos ? vod->prev.event_xy : NULL); | zoom_to_pos ? vod->prev.event_xy : NULL); | ||||
| } | } | ||||
| ED_region_tag_redraw(vod->region); | ED_region_tag_redraw(vod->region); | ||||
| } | } | ||||
| static void viewzoom_apply_3d(ViewOpsData *vod, | static void viewzoom_apply_3d(ViewOpsData *vod, | ||||
| const int xy[2], | const int xy[2], | ||||
| const eViewZoom_Style viewzoom, | const eViewZoom_Style viewzoom, | ||||
| const bool zoom_invert, | const bool zoom_invert, | ||||
| const bool zoom_to_pos) | const bool zoom_to_pos, | ||||
| const float fac) | |||||
| { | { | ||||
| float zfac; | float zfac; | ||||
| float dist_range[2]; | float dist_range[2]; | ||||
| ED_view3d_dist_range_get(vod->v3d, dist_range); | ED_view3d_dist_range_get(vod->v3d, dist_range); | ||||
| zfac = viewzoom_scale_value_offset(&vod->region->winrct, | if (fac) { /* MOUSEZOOM */ | ||||
| viewzoom, | zfac = 1.0f - fac; | ||||
| zoom_invert, | } | ||||
| false, | else { | ||||
| xy, | zfac = viewzoom_scale_value_offset(&vod->region->winrct, | ||||
| vod->init.event_xy, | viewzoom, | ||||
| vod->init.event_xy_offset, | zoom_invert, | ||||
| vod->rv3d->dist, | false, | ||||
| vod->init.dist, | xy, | ||||
| &vod->prev.time); | vod->init.event_xy, | ||||
| vod->init.event_xy_offset, | |||||
| vod->rv3d->dist, | |||||
| vod->init.dist, | |||||
| &vod->prev.time); | |||||
| } | |||||
| if (zfac != 1.0f) { | if (zfac != 1.0f) { | ||||
| const float zfac_min = dist_range[0] / vod->rv3d->dist; | const float zfac_min = dist_range[0] / vod->rv3d->dist; | ||||
| const float zfac_max = dist_range[1] / vod->rv3d->dist; | const float zfac_max = dist_range[1] / vod->rv3d->dist; | ||||
| CLAMP(zfac, zfac_min, zfac_max); | CLAMP(zfac, zfac_min, zfac_max); | ||||
| view_zoom_to_window_xy_3d(vod->region, zfac, zoom_to_pos ? vod->prev.event_xy : NULL); | view_zoom_to_window_xy_3d(vod->region, zfac, zoom_to_pos ? vod->prev.event_xy : NULL); | ||||
| } | } | ||||
| Show All 9 Lines | |||||
| ED_region_tag_redraw(vod->region); | ED_region_tag_redraw(vod->region); | ||||
| } | } | ||||
| static void viewzoom_apply(ViewOpsData *vod, | static void viewzoom_apply(ViewOpsData *vod, | ||||
| const int xy[2], | const int xy[2], | ||||
| const eViewZoom_Style viewzoom, | const eViewZoom_Style viewzoom, | ||||
| const bool zoom_invert, | const bool zoom_invert, | ||||
| const bool zoom_to_pos) | const bool zoom_to_pos, | ||||
| const float fac) | |||||
| { | { | ||||
| if ((vod->rv3d->persp == RV3D_CAMOB) && | if ((vod->rv3d->persp == RV3D_CAMOB) && | ||||
| (vod->rv3d->is_persp && ED_view3d_camera_lock_check(vod->v3d, vod->rv3d)) == 0) { | (vod->rv3d->is_persp && ED_view3d_camera_lock_check(vod->v3d, vod->rv3d)) == 0) { | ||||
| viewzoom_apply_camera(vod, xy, viewzoom, zoom_invert, zoom_to_pos); | viewzoom_apply_camera(vod, xy, viewzoom, zoom_invert, zoom_to_pos, fac); | ||||
| } | } | ||||
| else { | else { | ||||
| viewzoom_apply_3d(vod, xy, viewzoom, zoom_invert, zoom_to_pos); | viewzoom_apply_3d(vod, xy, viewzoom, zoom_invert, zoom_to_pos, fac); | ||||
| } | } | ||||
| } | } | ||||
| static int viewzoom_modal(bContext *C, wmOperator *op, const wmEvent *event) | static int viewzoom_modal(bContext *C, wmOperator *op, const wmEvent *event) | ||||
| { | { | ||||
| ViewOpsData *vod = op->customdata; | ViewOpsData *vod = op->customdata; | ||||
| short event_code = VIEW_PASS; | short event_code = VIEW_PASS; | ||||
| bool use_autokey = false; | bool use_autokey = false; | ||||
| Show All 27 Lines | |||||
| } | } | ||||
| if (event_code == VIEW_APPLY) { | if (event_code == VIEW_APPLY) { | ||||
| const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init"); | const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init"); | ||||
| viewzoom_apply(vod, | viewzoom_apply(vod, | ||||
| event->xy, | event->xy, | ||||
| (eViewZoom_Style)U.viewzoom, | (eViewZoom_Style)U.viewzoom, | ||||
| (U.uiflag & USER_ZOOM_INVERT) != 0, | (U.uiflag & USER_ZOOM_INVERT) != 0, | ||||
| (use_cursor_init && (U.uiflag & USER_ZOOM_TO_MOUSEPOS))); | (use_cursor_init && (U.uiflag & USER_ZOOM_TO_MOUSEPOS)), | ||||
| 0.0f); | |||||
| if (ED_screen_animation_playing(CTX_wm_manager(C))) { | if (ED_screen_animation_playing(CTX_wm_manager(C))) { | ||||
| use_autokey = true; | use_autokey = true; | ||||
| } | } | ||||
| } | } | ||||
| else if (event_code == VIEW_CONFIRM) { | else if (event_code == VIEW_CONFIRM) { | ||||
| use_autokey = true; | use_autokey = true; | ||||
| ret = OPERATOR_FINISHED; | ret = OPERATOR_FINISHED; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 114 Lines • ▼ Show 20 Lines | |||||
| RNA_int_set(op->ptr, "my", event->xy[1]); | RNA_int_set(op->ptr, "my", event->xy[1]); | ||||
| } | } | ||||
| if (RNA_struct_property_is_set(op->ptr, "delta")) { | if (RNA_struct_property_is_set(op->ptr, "delta")) { | ||||
| viewzoom_exec(C, op); | viewzoom_exec(C, op); | ||||
| } | } | ||||
| else { | else { | ||||
| if (ELEM(event->type, MOUSEZOOM, MOUSEPAN)) { | if (ELEM(event->type, MOUSEZOOM, MOUSEPAN)) { | ||||
| int event_xy[2]; | |||||
| if (U.uiflag & USER_ZOOM_HORIZ) { | if (event->type == MOUSEPAN) { | ||||
| vod->init.event_xy[0] = vod->prev.event_xy[0] = event->xy[0]; | event_xy[0] = event->xy[0] + WM_event_absolute_delta_x(event); | ||||
| event_xy[1] = event->xy[1] + WM_event_absolute_delta_y(event); | |||||
| } | } | ||||
| else { | else { | ||||
| /* Set y move = x move as MOUSEZOOM uses only x axis to pass magnification value */ | /* MOUSEZOOM performs zooming using 'event->factor' (change in zoom factor). */ | ||||
| vod->init.event_xy[1] = vod->prev.event_xy[1] = vod->init.event_xy[1] + event->xy[0] - | copy_v2_v2_int(event_xy, event->xy); | ||||
| event->prev_xy[0]; | |||||
| } | } | ||||
| viewzoom_apply(vod, | viewzoom_apply(vod, | ||||
| event->prev_xy, | event_xy, | ||||
| USER_ZOOM_DOLLY, | USER_ZOOM_DOLLY, | ||||
| (U.uiflag & USER_ZOOM_INVERT) != 0, | (U.uiflag & USER_ZOOM_INVERT) != 0, | ||||
| (use_cursor_init && (U.uiflag & USER_ZOOM_TO_MOUSEPOS))); | (use_cursor_init && (U.uiflag & USER_ZOOM_TO_MOUSEPOS)), | ||||
| event->factor); | |||||
| ED_view3d_camera_lock_autokey(vod->v3d, vod->rv3d, C, false, true); | ED_view3d_camera_lock_autokey(vod->v3d, vod->rv3d, C, false, true); | ||||
| viewops_data_free(C, op); | viewops_data_free(C, op); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| if (U.viewzoom == USER_ZOOM_CONTINUE) { | if (U.viewzoom == USER_ZOOM_CONTINUE) { | ||||
| /* needs a timer to continue redrawing */ | /* needs a timer to continue redrawing */ | ||||
| ▲ Show 20 Lines • Show All 93 Lines • ▼ Show 20 Lines | |||||
| const float orig_ofs[3], | const float orig_ofs[3], | ||||
| const float dvec[3], | const float dvec[3], | ||||
| float dfac) | float dfac) | ||||
| { | { | ||||
| RegionView3D *rv3d = region->regiondata; | RegionView3D *rv3d = region->regiondata; | ||||
| madd_v3_v3v3fl(rv3d->ofs, orig_ofs, dvec, -(1.0f - dfac)); | madd_v3_v3v3fl(rv3d->ofs, orig_ofs, dvec, -(1.0f - dfac)); | ||||
| } | } | ||||
| static void viewdolly_apply(ViewOpsData *vod, const int xy[2], const bool zoom_invert) | static void viewdolly_apply( | ||||
| ViewOpsData *vod, const int xy[2], const bool zoom_invert, const float fac) | |||||
| { | { | ||||
| float zfac = 1.0; | float zfac = 1.0; | ||||
| { | if (fac) { /* MOUSEZOOM */ | ||||
| zfac = 1.0f - fac * vod->rv3d->dist; | |||||
| } | |||||
| else { | |||||
| float len1, len2; | float len1, len2; | ||||
| if (U.uiflag & USER_ZOOM_HORIZ) { | if (U.uiflag & USER_ZOOM_HORIZ) { | ||||
| len1 = (vod->region->winrct.xmax - xy[0]) + 5; | len1 = (vod->region->winrct.xmax - xy[0]) + 5; | ||||
| len2 = (vod->region->winrct.xmax - vod->init.event_xy[0]) + 5; | len2 = (vod->region->winrct.xmax - vod->init.event_xy[0]) + 5; | ||||
| } | } | ||||
| else { | else { | ||||
| len1 = (vod->region->winrct.ymax - xy[1]) + 5; | len1 = (vod->region->winrct.ymax - xy[1]) + 5; | ||||
| ▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | |||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| else if (event->type == vod->init.event_type && event->val == KM_RELEASE) { | else if (event->type == vod->init.event_type && event->val == KM_RELEASE) { | ||||
| event_code = VIEW_CONFIRM; | event_code = VIEW_CONFIRM; | ||||
| } | } | ||||
| if (event_code == VIEW_APPLY) { | if (event_code == VIEW_APPLY) { | ||||
| viewdolly_apply(vod, event->xy, (U.uiflag & USER_ZOOM_INVERT) != 0); | viewdolly_apply(vod, event->xy, (U.uiflag & USER_ZOOM_INVERT) != 0, 0.0f); | ||||
| if (ED_screen_animation_playing(CTX_wm_manager(C))) { | if (ED_screen_animation_playing(CTX_wm_manager(C))) { | ||||
| use_autokey = true; | use_autokey = true; | ||||
| } | } | ||||
| } | } | ||||
| else if (event_code == VIEW_CONFIRM) { | else if (event_code == VIEW_CONFIRM) { | ||||
| use_autokey = true; | use_autokey = true; | ||||
| ret = OPERATOR_FINISHED; | ret = OPERATOR_FINISHED; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 113 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| else { | else { | ||||
| /* overwrite the mouse vector with the view direction (zoom into the center) */ | /* overwrite the mouse vector with the view direction (zoom into the center) */ | ||||
| if ((use_cursor_init && (U.uiflag & USER_ZOOM_TO_MOUSEPOS)) == 0) { | if ((use_cursor_init && (U.uiflag & USER_ZOOM_TO_MOUSEPOS)) == 0) { | ||||
| negate_v3_v3(vod->init.mousevec, vod->rv3d->viewinv[2]); | negate_v3_v3(vod->init.mousevec, vod->rv3d->viewinv[2]); | ||||
| normalize_v3(vod->init.mousevec); | normalize_v3(vod->init.mousevec); | ||||
| } | } | ||||
| if (event->type == MOUSEZOOM) { | if (ELEM(event->type, MOUSEZOOM, MOUSEPAN)) { | ||||
| /* Bypass Zoom invert flag for track pads (pass false always) */ | int event_xy[2]; | ||||
| if (U.uiflag & USER_ZOOM_HORIZ) { | if (event->type == MOUSEPAN) { | ||||
| vod->init.event_xy[0] = vod->prev.event_xy[0] = event->xy[0]; | event_xy[0] = event->xy[0] + WM_event_absolute_delta_x(event); | ||||
| event_xy[1] = event->xy[1] + WM_event_absolute_delta_y(event); | |||||
| } | } | ||||
| else { | else { | ||||
| /* Set y move = x move as MOUSEZOOM uses only x axis to pass magnification value */ | /* MOUSEZOOM performs zooming using 'event->factor' (change in zoom factor). */ | ||||
| vod->init.event_xy[1] = vod->prev.event_xy[1] = vod->init.event_xy[1] + event->xy[0] - | copy_v2_v2_int(event_xy, event->xy); | ||||
| event->prev_xy[0]; | |||||
| } | } | ||||
| viewdolly_apply(vod, event->prev_xy, (U.uiflag & USER_ZOOM_INVERT) == 0); | |||||
| viewdolly_apply(vod, event_xy, (U.uiflag & USER_ZOOM_INVERT) != 0, event->factor); | |||||
| viewops_data_free(C, op); | viewops_data_free(C, op); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| /* add temp handler */ | /* add temp handler */ | ||||
| WM_event_add_modal_handler(C, op); | WM_event_add_modal_handler(C, op); | ||||
| return OPERATOR_RUNNING_MODAL; | return OPERATOR_RUNNING_MODAL; | ||||
| ▲ Show 20 Lines • Show All 184 Lines • ▼ Show 20 Lines | |||||
| mul_qt_qtqt(quat, orig_quat, quat_mul); | mul_qt_qtqt(quat, orig_quat, quat_mul); | ||||
| /* avoid precision loss over time */ | /* avoid precision loss over time */ | ||||
| normalize_qt(quat); | normalize_qt(quat); | ||||
| rv3d->view = RV3D_VIEW_USER; | rv3d->view = RV3D_VIEW_USER; | ||||
| } | } | ||||
| static void viewroll_apply(ViewOpsData *vod, int x, int y) | static void viewroll_apply(ViewOpsData *vod, int x, int y, const float deg) | ||||
| { | { | ||||
| float angle = BLI_dial_angle(vod->init.dial, (const float[2]){x, y}); | float angle; | ||||
| if (deg) { /* MOUSEROTATE */ | |||||
| angle = -DEG2RADF(deg); | |||||
| } | |||||
| else { | |||||
| angle = BLI_dial_angle(vod->init.dial, (const float[2]){x, y}); | |||||
| } | |||||
| if (angle != 0.0f) { | if (angle != 0.0f) { | ||||
| view_roll_angle(vod->region, vod->rv3d->viewquat, vod->init.quat, vod->init.mousevec, angle); | view_roll_angle(vod->region, vod->rv3d->viewquat, vod->init.quat, vod->init.mousevec, angle); | ||||
| } | } | ||||
| if (vod->use_dyn_ofs) { | if (vod->use_dyn_ofs) { | ||||
| view3d_orbit_apply_dyn_ofs( | view3d_orbit_apply_dyn_ofs( | ||||
| vod->rv3d->ofs, vod->init.ofs, vod->init.quat, vod->rv3d->viewquat, vod->dyn_ofs); | vod->rv3d->ofs, vod->init.ofs, vod->init.quat, vod->rv3d->viewquat, vod->dyn_ofs); | ||||
| ▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | |||||
| viewops_data_free(C, op); | viewops_data_free(C, op); | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| else if (event->type == vod->init.event_type && event->val == KM_RELEASE) { | else if (event->type == vod->init.event_type && event->val == KM_RELEASE) { | ||||
| event_code = VIEW_CONFIRM; | event_code = VIEW_CONFIRM; | ||||
| } | } | ||||
| if (event_code == VIEW_APPLY) { | if (event_code == VIEW_APPLY) { | ||||
| viewroll_apply(vod, event->xy[0], event->xy[1]); | viewroll_apply(vod, event->xy[0], event->xy[1], 0.0f); | ||||
| if (ED_screen_animation_playing(CTX_wm_manager(C))) { | if (ED_screen_animation_playing(CTX_wm_manager(C))) { | ||||
| use_autokey = true; | use_autokey = true; | ||||
| } | } | ||||
| } | } | ||||
| else if (event_code == VIEW_CONFIRM) { | else if (event_code == VIEW_CONFIRM) { | ||||
| use_autokey = true; | use_autokey = true; | ||||
| ret = OPERATOR_FINISHED; | ret = OPERATOR_FINISHED; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 97 Lines • ▼ Show 20 Lines | |||||
| ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->region); | ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->region); | ||||
| /* overwrite the mouse vector with the view direction */ | /* overwrite the mouse vector with the view direction */ | ||||
| normalize_v3_v3(vod->init.mousevec, vod->rv3d->viewinv[2]); | normalize_v3_v3(vod->init.mousevec, vod->rv3d->viewinv[2]); | ||||
| negate_v3(vod->init.mousevec); | negate_v3(vod->init.mousevec); | ||||
| if (event->type == MOUSEROTATE) { | if (event->type == MOUSEROTATE) { | ||||
| vod->init.event_xy[0] = vod->prev.event_xy[0] = event->xy[0]; | viewroll_apply(vod, event->xy[0], event->xy[1], event->factor); | ||||
| viewroll_apply(vod, event->prev_xy[0], event->prev_xy[1]); | |||||
| viewops_data_free(C, op); | viewops_data_free(C, op); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| /* add temp handler */ | /* add temp handler */ | ||||
| WM_event_add_modal_handler(C, op); | WM_event_add_modal_handler(C, op); | ||||
| return OPERATOR_RUNNING_MODAL; | return OPERATOR_RUNNING_MODAL; | ||||
| ▲ Show 20 Lines • Show All 92 Lines • Show Last 20 Lines | |||||