From 914d2e8164e10003f919a644b892ee5fc01d63ea Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Thu, 17 Apr 2025 04:26:58 +0200 Subject: [PATCH] UI: Reverse Pen Y Tilt Expected Direction It is more convenient for math reasons, for Blender to treat a pen tilt toward the user as a positive angle. This PR just reverses all the comments about the expected values. And also reverses the values from WinTab, Windows Ink, and Wayland to match. Pull Request: https://projects.blender.org/blender/blender/pulls/137636 --- intern/ghost/GHOST_Types.h | 2 +- intern/ghost/intern/GHOST_SystemCocoa.mm | 3 ++- intern/ghost/intern/GHOST_SystemWayland.cc | 5 +++-- intern/ghost/intern/GHOST_WindowWin32.cc | 4 ++-- intern/ghost/intern/GHOST_Wintab.cc | 6 +++++- source/blender/makesrna/intern/rna_brush.cc | 2 +- source/blender/windowmanager/WM_types.hh | 2 +- 7 files changed, 15 insertions(+), 9 deletions(-) diff --git a/intern/ghost/GHOST_Types.h b/intern/ghost/GHOST_Types.h index 5f408f7dd08..9582e83aaef 100644 --- a/intern/ghost/GHOST_Types.h +++ b/intern/ghost/GHOST_Types.h @@ -166,7 +166,7 @@ typedef struct GHOST_TabletData { GHOST_TTabletMode Active; /* 0=None, 1=Stylus, 2=Eraser */ float Pressure; /* range 0.0 (not touching) to 1.0 (full pressure) */ float Xtilt; /* range -1.0 (left) to +1.0 (right) */ - float Ytilt; /* range -1.0 (toward user) to +1.0 (away from user) */ + float Ytilt; /* range -1.0 (away from user) to +1.0 (toward user) */ } GHOST_TabletData; static const GHOST_TabletData GHOST_TABLET_DATA_NONE = { diff --git a/intern/ghost/intern/GHOST_SystemCocoa.mm b/intern/ghost/intern/GHOST_SystemCocoa.mm index c9f56cc4a8f..618dd8a2996 100644 --- a/intern/ghost/intern/GHOST_SystemCocoa.mm +++ b/intern/ghost/intern/GHOST_SystemCocoa.mm @@ -1484,7 +1484,8 @@ GHOST_TSuccess GHOST_SystemCocoa::handleTabletEvent(void *eventPtr, short eventT /* Range: -1 (left) to 1 (right). */ ct.Xtilt = event.tilt.x; /* On macOS, the y tilt behavior is inverted from what we expect: negative - * meaning a tilt toward the user, positive meaning away from the user. */ + * meaning a tilt toward the user, positive meaning away from the user. + * Convert to what Blender expects: -1.0 (away from user) to +1.0 (toward user). */ ct.Ytilt = -event.tilt.y; break; diff --git a/intern/ghost/intern/GHOST_SystemWayland.cc b/intern/ghost/intern/GHOST_SystemWayland.cc index 43f53c46fc6..093151edef6 100644 --- a/intern/ghost/intern/GHOST_SystemWayland.cc +++ b/intern/ghost/intern/GHOST_SystemWayland.cc @@ -4791,10 +4791,11 @@ static void tablet_tool_handle_tilt(void *data, const wl_fixed_t tilt_x, const wl_fixed_t tilt_y) { - /* Map degrees to `-1.0 (left/back)..1.0 (right/forward)`. */ + /* Map X tilt to `-1.0 (left)..1.0 (right)`. + * Map Y tilt to `-1.0 (away from user)..1.0 (toward user)`. */ const float tilt_unit[2] = { float(wl_fixed_to_double(tilt_x) / 90.0f), - float(wl_fixed_to_double(tilt_y) / -90.0f), + float(wl_fixed_to_double(tilt_y) / 90.0f), }; CLOG_INFO(LOG, 2, "tilt (x=%.4f, y=%.4f)", UNPACK2(tilt_unit)); GWL_TabletTool *tablet_tool = static_cast(data); diff --git a/intern/ghost/intern/GHOST_WindowWin32.cc b/intern/ghost/intern/GHOST_WindowWin32.cc index ebc5182aa0c..82f5edf99c1 100644 --- a/intern/ghost/intern/GHOST_WindowWin32.cc +++ b/intern/ghost/intern/GHOST_WindowWin32.cc @@ -1013,9 +1013,9 @@ GHOST_TSuccess GHOST_WindowWin32::getPointerInfo( if (pointerPenInfo[i].penMask & PEN_MASK_TILT_Y) { /* Input value is a range of -90 to +90, with a positive value * indicating a tilt toward the user. Convert to what Blender - * expects: -1.0f (toward user) to +1.0f (away from user). */ + * expects: -1.0f (away from user) to +1.0f (toward user). */ outPointerInfo[i].tabletData.Ytilt = std::clamp( - pointerPenInfo[i].tiltY / -90.0f, -1.0f, 1.0f); + pointerPenInfo[i].tiltY / 90.0f, -1.0f, 1.0f); } } diff --git a/intern/ghost/intern/GHOST_Wintab.cc b/intern/ghost/intern/GHOST_Wintab.cc index 1c0f5f77807..491617ff7f8 100644 --- a/intern/ghost/intern/GHOST_Wintab.cc +++ b/intern/ghost/intern/GHOST_Wintab.cc @@ -362,8 +362,12 @@ void GHOST_Wintab::getInput(std::vector &outWintabInfo) float vecLen = cos(altRad); /* From there calculate X and Y components based on azimuth. */ + + /* Blender expects: -1.0f (left) to +1.0f (right). */ out.tabletData.Xtilt = sin(azmRad) * vecLen; - out.tabletData.Ytilt = float(sin(M_PI_2 - azmRad) * vecLen); + + /* Blender expects: -1.0f (away from user) to +1.0f (toward user). */ + out.tabletData.Ytilt = -float(sin(M_PI_2 - azmRad) * vecLen); } out.time = pkt.pkTime; diff --git a/source/blender/makesrna/intern/rna_brush.cc b/source/blender/makesrna/intern/rna_brush.cc index 83e6aeab645..21c32ee62aa 100644 --- a/source/blender/makesrna/intern/rna_brush.cc +++ b/source/blender/makesrna/intern/rna_brush.cc @@ -3942,7 +3942,7 @@ static void rna_def_operator_stroke_element(BlenderRNA *brna) prop = RNA_def_property(srna, "y_tilt", PROP_FLOAT, PROP_FACTOR); RNA_def_property_flag(prop, PROP_IDPROPERTY); RNA_def_property_range(prop, -1.0f, 1.0f); - RNA_def_property_ui_text(prop, "Tilt Y", "Pen tilt from forward (-1.0) to back (+1.0)"); + RNA_def_property_ui_text(prop, "Tilt Y", "Pen tilt from backward (-1.0) to forward (+1.0)"); /* used in uv painting */ prop = RNA_def_property(srna, "time", PROP_FLOAT, PROP_UNSIGNED); diff --git a/source/blender/windowmanager/WM_types.hh b/source/blender/windowmanager/WM_types.hh index d62fbd8f783..f0f5f17068c 100644 --- a/source/blender/windowmanager/WM_types.hh +++ b/source/blender/windowmanager/WM_types.hh @@ -702,7 +702,7 @@ struct wmTabletData { float pressure; /** range -1.0 (left) to +1.0 (right). */ float x_tilt; - /** range -1.0 (toward user) to +1.0 (away from user). */ + /** range -1.0 (away from user) to +1.0 (toward user). */ float y_tilt; /** Interpret mouse motion as absolute as typical for tablets. */ char is_motion_absolute;