> ## Documentation Index
> Fetch the complete documentation index at: https://docs-unity.molca.id/llms.txt
> Use this file to discover all available pages before exploring further.

# Touch controls & camera

> TouchOrbitCameraController, gesture recognition, and visual feedback for the DT twin viewer.

**Namespace:** `MolcaDT.Common`

The DT SDK provides a multi-touch camera control system with gesture recognition, orbit/pinch/pan, and visual feedback effects.

## TouchOrbitCameraController

**File:** `Assets/_MolcaDT/Code/Scripts/Common/TouchOrbitCameraController.cs`

Orbits a camera around a pivot point using touch input (typically 2-finger rotate). Works with `TouchVfxHandler` for input events. Supports smooth rotation, configurable axis constraints, and keyboard shortcuts (Q/E) for mouse emulation.

### Inspector

| Field                  | Type                 | Default | Purpose                                            |
| ---------------------- | -------------------- | ------- | -------------------------------------------------- |
| `_handler`             | `TouchVfxHandler`    | —       | Touch input event source                           |
| `_vfxController`       | `TouchVfxController` | —       | Visual feedback controller (optional)              |
| `_sampler`             | `TouchInputSampler`  | —       | Mouse/keyboard emulation input                     |
| `_rotateFingerCount`   | `int [1-10]`         | 2       | Fingers required for rotation                      |
| `_autoSubscribe`       | `bool`               | true    | Auto-wire to handler.OnRotate on enable            |
| `_pivot`               | `Transform`          | —       | Orbit center point                                 |
| `_camera`              | `Camera`             | —       | Camera to orbit (defaults to Camera.main)          |
| `_rotationSensitivity` | `float`              | 1       | Rotation sensitivity multiplier                    |
| `_invertRotation`      | `bool`               | false   | Invert rotation direction                          |
| `_rotationAxis`        | `Vector3`            | (0,1,0) | Constrain rotation to axis (Vector3.up for Y-only) |
| `_smoothRotation`      | `bool`               | true    | Enable smooth interpolation                        |
| `_rotationSmoothTime`  | `float`              | 0.1     | Smoothing duration in seconds                      |

### Code

```csharp theme={null}
using MolcaDT.Common;
using UnityEngine;

public class CameraSetup : MonoBehaviour
{
    [SerializeField] private TouchOrbitCameraController orbitController;
    [SerializeField] private Transform pivotPoint;

    private void Start()
    {
        // Configure pivot at runtime
        orbitController.SetPivot(pivotPoint);

        // Switch to XZ plane rotation for top-down view
        orbitController.SetRotationAxis(new Vector3(0, 1, 0));
    }
}
```

## TouchVfxHandler

**File:** `Assets/_MolcaDT/Code/Scripts/Common/TouchVfxHandler.cs`

Routes raw touch events to gesture recognizers. Key `UnityEvent` outputs:

| Event                         | Description                         |
| ----------------------------- | ----------------------------------- |
| `OnTap`                       | Single tap detected                 |
| `OnDoubleTap`                 | Double tap detected                 |
| `OnLongPress`                 | Long press detected                 |
| `OnDrag`                      | Drag gesture (delta position)       |
| `OnRotate`                    | Rotation gesture (angular delta)    |
| `OnPinch`                     | Pinch-to-zoom gesture (scale delta) |
| `OnFingerDown` / `OnFingerUp` | Per-finger press/release            |

## TouchGestureAnalyzer

**File:** `Assets/_MolcaDT/Code/Scripts/Common/TouchGestureAnalyzer.cs`

Classifies raw touch data into gesture types:

| Gesture   | Criteria                               |
| --------- | -------------------------------------- |
| Tap       | Short touch, minimal movement          |
| DoubleTap | Two quick taps within time threshold   |
| LongPress | Touch held beyond duration threshold   |
| Drag      | Touch moved beyond drag threshold      |
| Rotate    | Two fingers rotating around a centroid |
| Pinch     | Two fingers moving apart/together      |

## TouchVfxController

**File:** `Assets/_MolcaDT/Code/Scripts/Common/TouchVfxController.cs`

Provides visual feedback effects for touch interactions (ripple, highlight, cursor trails) driven by `TouchVfxHandler` events.

## Code

```csharp theme={null}
using MolcaDT.Common;
using UnityEngine;

public class TouchCameraController : MonoBehaviour
{
    [SerializeField] private TouchOrbitCameraController _orbit;
    [SerializeField] private TouchVfxHandler _touchHandler;
    [SerializeField] private float _zoomSpeed = 0.1f;

    private void OnEnable()
    {
        _touchHandler.OnPinch.AddListener(HandlePinch);
        _touchHandler.OnDoubleTap.AddListener(HandleDoubleTap);
    }

    private void OnDisable()
    {
        _touchHandler.OnPinch.RemoveListener(HandlePinch);
        _touchHandler.OnDoubleTap.RemoveListener(HandleDoubleTap);
    }

    private void HandlePinch(float zoomDelta)
    {
        // zoomDelta > 0 = pinch out (zoom in)
        // zoomDelta < 0 = pinch in (zoom out)
        transform.position += transform.forward * zoomDelta * _zoomSpeed;
    }

    private void HandleDoubleTap()
    {
        // Reset camera to default position
        Debug.Log("Double tap — reset view");
    }
}
```

## Related

* [DT startup flow](/dt/startup-flow) — where the camera rig is initialized
* [DT architecture](/dt/architecture) — camera rig positioning in layers
