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:
parent
cc367bc713
commit
3bbf4f9d14
2 changed files with 26 additions and 9 deletions
|
|
@ -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?) {
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue