Cleanup: simplify calculation of NDOF pan/zoom in 2D views
Make the logic for converting NDOF Z-motion to a scale value more straightforward. Flipping the Z axis was scaling by negative-time, now the entire pan vector is scaled by time and the zoom value is calculated as `scale = 1 - (z * time)` instead of `1 + (z * -time)`. Although they're equivalent, confusion here caused T100953. Also clamp the scale (while unlikely, negative scale wasn't prevented).
This commit is contained in:
parent
1fbd300adb
commit
e4e80058c8
|
@ -1641,14 +1641,14 @@ static int clip_view_ndof_invoke(bContext *C, wmOperator *UNUSED(op), const wmEv
|
|||
float pan_vec[3];
|
||||
|
||||
const wmNDOFMotionData *ndof = event->customdata;
|
||||
const float speed = NDOF_PIXELS_PER_SECOND;
|
||||
const float pan_speed = NDOF_PIXELS_PER_SECOND;
|
||||
|
||||
WM_event_ndof_pan_get(ndof, pan_vec, true);
|
||||
|
||||
mul_v2_fl(pan_vec, (speed * ndof->dt) / sc->zoom);
|
||||
pan_vec[2] *= -ndof->dt;
|
||||
mul_v3_fl(pan_vec, ndof->dt);
|
||||
mul_v2_fl(pan_vec, pan_speed / sc->zoom);
|
||||
|
||||
sclip_zoom_set_factor(C, 1.0f + pan_vec[2], NULL, false);
|
||||
sclip_zoom_set_factor(C, max_ff(0.0f, 1.0f - pan_vec[2]), NULL, false);
|
||||
sc->xof += pan_vec[0];
|
||||
sc->yof += pan_vec[1];
|
||||
|
||||
|
|
|
@ -762,14 +762,14 @@ static int image_view_ndof_invoke(bContext *C, wmOperator *UNUSED(op), const wmE
|
|||
float pan_vec[3];
|
||||
|
||||
const wmNDOFMotionData *ndof = event->customdata;
|
||||
const float speed = NDOF_PIXELS_PER_SECOND;
|
||||
const float pan_speed = NDOF_PIXELS_PER_SECOND;
|
||||
|
||||
WM_event_ndof_pan_get(ndof, pan_vec, true);
|
||||
|
||||
mul_v2_fl(pan_vec, (speed * ndof->dt) / sima->zoom);
|
||||
pan_vec[2] *= -ndof->dt;
|
||||
mul_v3_fl(pan_vec, ndof->dt);
|
||||
mul_v2_fl(pan_vec, pan_speed / sima->zoom);
|
||||
|
||||
sima_zoom_set_factor(sima, region, 1.0f + pan_vec[2], NULL, false);
|
||||
sima_zoom_set_factor(sima, region, max_ff(0.0f, 1.0f - pan_vec[2]), NULL, false);
|
||||
sima->xof += pan_vec[0];
|
||||
sima->yof += pan_vec[1];
|
||||
|
||||
|
|
|
@ -370,14 +370,17 @@ static int view3d_ndof_cameraview_pan_zoom(bContext *C, const wmEvent *event)
|
|||
return OPERATOR_PASS_THROUGH;
|
||||
}
|
||||
|
||||
const float pan_speed = NDOF_PIXELS_PER_SECOND;
|
||||
const bool has_translate = !is_zero_v2(ndof->tvec);
|
||||
const bool has_zoom = ndof->tvec[2] != 0.0f;
|
||||
|
||||
float pan_vec[3];
|
||||
WM_event_ndof_pan_get(ndof, pan_vec, true);
|
||||
|
||||
mul_v2_fl(pan_vec, ndof->dt);
|
||||
pan_vec[2] *= -ndof->dt;
|
||||
mul_v3_fl(pan_vec, ndof->dt);
|
||||
/* NOTE: unlike image and clip views, the 2D pan doesn't have to be scaled by the zoom level.
|
||||
* #ED_view3d_camera_view_pan already takes the zoom level into account. */
|
||||
mul_v2_fl(pan_vec, pan_speed);
|
||||
|
||||
/* NOTE(@campbellbarton): In principle rotating could pass through to regular
|
||||
* non-camera NDOF behavior (exiting the camera-view and rotating).
|
||||
|
@ -393,16 +396,14 @@ static int view3d_ndof_cameraview_pan_zoom(bContext *C, const wmEvent *event)
|
|||
bool changed = false;
|
||||
|
||||
if (has_translate) {
|
||||
const float speed = NDOF_PIXELS_PER_SECOND;
|
||||
float event_ofs[2] = {pan_vec[0] * speed, pan_vec[1] * speed};
|
||||
if (ED_view3d_camera_view_pan(region, event_ofs)) {
|
||||
/* Use the X & Y of `pan_vec`. */
|
||||
if (ED_view3d_camera_view_pan(region, pan_vec)) {
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (has_zoom) {
|
||||
const float scale = 1.0f + pan_vec[2];
|
||||
if (ED_view3d_camera_view_zoom_scale(rv3d, scale)) {
|
||||
if (ED_view3d_camera_view_zoom_scale(rv3d, max_ff(0.0f, 1.0f - pan_vec[2]))) {
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue