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
This commit is contained in:
Harley Acheson
2025-04-17 04:26:58 +02:00
committed by Harley Acheson
parent 4e37bd8c65
commit 914d2e8164
7 changed files with 15 additions and 9 deletions

View File

@@ -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 = {

View File

@@ -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;

View File

@@ -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<GWL_TabletTool *>(data);

View File

@@ -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);
}
}

View File

@@ -362,8 +362,12 @@ void GHOST_Wintab::getInput(std::vector<GHOST_WintabInfoWin32> &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;

View File

@@ -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);

View File

@@ -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;