Fix portrait orientation and reduce gesture sensitivity

- Rotate texture coordinates 90° for portrait mode display
  (camera sensors are landscape-oriented by default)
- Add sensitivity dampening constants for all gesture types:
  - Position drag: 0.3x
  - Rotation: 0.4x
  - Size pinch: 0.5x
  - Zoom pinch: 0.6x
- Track accumulated drag for smoother position changes

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Ole-Morten Duesund 2026-01-28 15:32:31 +01:00
commit 3bbf4f9d14
2 changed files with 26 additions and 9 deletions

View file

@ -44,12 +44,13 @@ class TiltShiftRenderer(
1f, 1f // Top right 1f, 1f // Top right
) )
// Texture coordinates (flip Y for camera) // Texture coordinates rotated 90° for portrait mode
// (Camera sensors are landscape-oriented, we rotate to portrait)
private val texCoords = floatArrayOf( private val texCoords = floatArrayOf(
0f, 1f, // Bottom left 1f, 1f, // Bottom left of screen -> bottom right of texture
1f, 1f, // Bottom right 1f, 0f, // Bottom right of screen -> top right of texture
0f, 0f, // Top left 0f, 1f, // Top left of screen -> bottom left of texture
1f, 0f // Top right 0f, 0f // Top right of screen -> top left of texture
) )
override fun onSurfaceCreated(gl: GL10?, config: EGLConfig?) { override fun onSurfaceCreated(gl: GL10?, config: EGLConfig?) {

View file

@ -39,6 +39,12 @@ private enum class GestureType {
PINCH_ZOOM // Pinch in center to zoom camera PINCH_ZOOM // Pinch in center to zoom camera
} }
// Sensitivity factors for gesture controls (lower = less sensitive)
private const val POSITION_SENSITIVITY = 0.3f // Drag to move focus line
private const val ROTATION_SENSITIVITY = 0.4f // Two-finger rotation
private const val SIZE_SENSITIVITY = 0.5f // Pinch to resize blur zone
private const val ZOOM_SENSITIVITY = 0.6f // Pinch to zoom camera
/** /**
* Overlay that shows tilt-shift effect controls and handles gestures. * Overlay that shows tilt-shift effect controls and handles gestures.
*/ */
@ -53,6 +59,7 @@ fun TiltShiftOverlay(
var initialZoom by remember { mutableFloatStateOf(1f) } var initialZoom by remember { mutableFloatStateOf(1f) }
var initialAngle by remember { mutableFloatStateOf(0f) } var initialAngle by remember { mutableFloatStateOf(0f) }
var initialSize by remember { mutableFloatStateOf(0.3f) } var initialSize by remember { mutableFloatStateOf(0.3f) }
var initialPosition by remember { mutableFloatStateOf(0.5f) }
Canvas( Canvas(
modifier = modifier modifier = modifier
@ -66,9 +73,11 @@ fun TiltShiftOverlay(
var previousPointerCount = 1 var previousPointerCount = 1
var accumulatedRotation = 0f var accumulatedRotation = 0f
var accumulatedZoom = 1f var accumulatedZoom = 1f
var accumulatedDragY = 0f
initialAngle = params.angle initialAngle = params.angle
initialSize = params.size initialSize = params.size
initialPosition = params.position
initialZoom = 1f initialZoom = 1f
do { do {
@ -101,18 +110,23 @@ fun TiltShiftOverlay(
when (currentGesture) { when (currentGesture) {
GestureType.ROTATE -> { GestureType.ROTATE -> {
accumulatedRotation += rotation // Apply dampening to rotation
accumulatedRotation += rotation * ROTATION_SENSITIVITY
val newAngle = initialAngle + accumulatedRotation val newAngle = initialAngle + accumulatedRotation
onParamsChange(params.copy(angle = newAngle)) onParamsChange(params.copy(angle = newAngle))
} }
GestureType.PINCH_SIZE -> { GestureType.PINCH_SIZE -> {
accumulatedZoom *= zoom // Apply dampening to size change
val dampenedZoom = 1f + (zoom - 1f) * SIZE_SENSITIVITY
accumulatedZoom *= dampenedZoom
val newSize = (initialSize * accumulatedZoom) val newSize = (initialSize * accumulatedZoom)
.coerceIn(BlurParameters.MIN_SIZE, BlurParameters.MAX_SIZE) .coerceIn(BlurParameters.MIN_SIZE, BlurParameters.MAX_SIZE)
onParamsChange(params.copy(size = newSize)) onParamsChange(params.copy(size = newSize))
} }
GestureType.PINCH_ZOOM -> { GestureType.PINCH_ZOOM -> {
onZoomChange(zoom) // Apply dampening to camera zoom
val dampenedZoom = 1f + (zoom - 1f) * ZOOM_SENSITIVITY
onZoomChange(dampenedZoom)
} }
else -> {} else -> {}
} }
@ -125,8 +139,10 @@ fun TiltShiftOverlay(
} }
if (currentGesture == GestureType.DRAG_POSITION) { if (currentGesture == GestureType.DRAG_POSITION) {
// Apply dampening to position drag
val deltaY = (centroid.y - previousCentroid.y) / size.height val deltaY = (centroid.y - previousCentroid.y) / size.height
val newPosition = (params.position + deltaY).coerceIn(0f, 1f) accumulatedDragY += deltaY * POSITION_SENSITIVITY
val newPosition = (initialPosition + accumulatedDragY).coerceIn(0f, 1f)
onParamsChange(params.copy(position = newPosition)) onParamsChange(params.copy(position = newPosition))
} }
} }