diff --git a/app/src/main/java/no/naiv/tiltshift/effect/TiltShiftRenderer.kt b/app/src/main/java/no/naiv/tiltshift/effect/TiltShiftRenderer.kt index 18e35e3..1b90e50 100644 --- a/app/src/main/java/no/naiv/tiltshift/effect/TiltShiftRenderer.kt +++ b/app/src/main/java/no/naiv/tiltshift/effect/TiltShiftRenderer.kt @@ -44,12 +44,13 @@ class TiltShiftRenderer( 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( - 0f, 1f, // Bottom left - 1f, 1f, // Bottom right - 0f, 0f, // Top left - 1f, 0f // Top right + 1f, 1f, // Bottom left of screen -> bottom right of texture + 1f, 0f, // Bottom right of screen -> top right of texture + 0f, 1f, // Top left of screen -> bottom left of texture + 0f, 0f // Top right of screen -> top left of texture ) override fun onSurfaceCreated(gl: GL10?, config: EGLConfig?) { diff --git a/app/src/main/java/no/naiv/tiltshift/ui/TiltShiftOverlay.kt b/app/src/main/java/no/naiv/tiltshift/ui/TiltShiftOverlay.kt index 0783767..6b9b2d4 100644 --- a/app/src/main/java/no/naiv/tiltshift/ui/TiltShiftOverlay.kt +++ b/app/src/main/java/no/naiv/tiltshift/ui/TiltShiftOverlay.kt @@ -39,6 +39,12 @@ private enum class GestureType { 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. */ @@ -53,6 +59,7 @@ fun TiltShiftOverlay( var initialZoom by remember { mutableFloatStateOf(1f) } var initialAngle by remember { mutableFloatStateOf(0f) } var initialSize by remember { mutableFloatStateOf(0.3f) } + var initialPosition by remember { mutableFloatStateOf(0.5f) } Canvas( modifier = modifier @@ -66,9 +73,11 @@ fun TiltShiftOverlay( var previousPointerCount = 1 var accumulatedRotation = 0f var accumulatedZoom = 1f + var accumulatedDragY = 0f initialAngle = params.angle initialSize = params.size + initialPosition = params.position initialZoom = 1f do { @@ -101,18 +110,23 @@ fun TiltShiftOverlay( when (currentGesture) { GestureType.ROTATE -> { - accumulatedRotation += rotation + // Apply dampening to rotation + accumulatedRotation += rotation * ROTATION_SENSITIVITY val newAngle = initialAngle + accumulatedRotation onParamsChange(params.copy(angle = newAngle)) } GestureType.PINCH_SIZE -> { - accumulatedZoom *= zoom + // Apply dampening to size change + val dampenedZoom = 1f + (zoom - 1f) * SIZE_SENSITIVITY + accumulatedZoom *= dampenedZoom val newSize = (initialSize * accumulatedZoom) .coerceIn(BlurParameters.MIN_SIZE, BlurParameters.MAX_SIZE) onParamsChange(params.copy(size = newSize)) } GestureType.PINCH_ZOOM -> { - onZoomChange(zoom) + // Apply dampening to camera zoom + val dampenedZoom = 1f + (zoom - 1f) * ZOOM_SENSITIVITY + onZoomChange(dampenedZoom) } else -> {} } @@ -125,8 +139,10 @@ fun TiltShiftOverlay( } if (currentGesture == GestureType.DRAG_POSITION) { + // Apply dampening to position drag 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)) } }