# 03. Orbit controls and helpers, explained

**Goal:** let the user rotate, pan and zoom around a scene with the mouse or touch, and use helpers to see axes and scale.

## Walkthrough

```js
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
```
Controls, loaders and post-processing live in the **addons** folder (`examples/jsm` in the npm package). The import map maps `three/addons/` to that folder on the CDN; with npm the same path works out of the box.

```js
scene.add(new THREE.GridHelper(20, 20, 0x666666, 0x333333));
scene.add(new THREE.AxesHelper(3));
```
`GridHelper(size, divisions, centerLineColor, gridColor)` draws a flat grid on the XZ plane. `AxesHelper(length)` draws X in red, Y in green and Z in blue. three.js is **right-handed with Y up**: +X right, +Y up, +Z toward the viewer.

```js
box.scale.set(0.8, height, 0.8);
box.position.set(x, height / 2, z);
```
All boxes share one `BoxGeometry` of size 1. Scaling a mesh is cheaper than creating a new geometry per box. Because a box is centered on its position, lifting it by `height / 2` makes it sit on the ground.

```js
const controls = new OrbitControls(camera, renderer.domElement);
controls.target.set(0, 1, 0);
```
OrbitControls moves the **camera** around a **target point**. Pass the canvas (`renderer.domElement`) as the second argument so the controls only listen to events on the 3D view, not on the whole page.

```js
controls.enableDamping = true;
controls.dampingFactor = 0.05;
```
Damping adds inertia so movement eases out. With damping on, you must call `controls.update()` every frame, which the animation loop does.

```js
controls.minDistance = 3;
controls.maxDistance = 40;
controls.maxPolarAngle = Math.PI / 2 - 0.05;
```
Limits keep users from zooming inside objects, flying away, or looking from below the ground. The polar angle is measured from straight up: 0 is looking down from above, `Math.PI / 2` is level with the horizon.

## Which controls should I use?

| Controls | Feels like | Good for |
| --- | --- | --- |
| `OrbitControls` | Turntable around a target | Product viewers, model inspection (most common) |
| `MapControls` | Pan-first, like a map | Top-down maps, city builders |
| `TrackballControls` | Free rotation, no fixed "up" | Molecules, space scenes |
| `ArcballControls` | Rotation via a virtual sphere, with gizmos | CAD-like viewers |
| `FlyControls` | Free flight with keys and mouse | Flythroughs |
| `FirstPersonControls` / `PointerLockControls` | Look around with the mouse | Walkable scenes, games |
| `TransformControls` | Gizmo to move/rotate/scale an object | Editors |
| `DragControls` | Drag objects on a plane | Simple interactive layouts |

## Try this

1. Set `controls.autoRotate = true` for a showroom turntable.
2. Use `controls.enablePan = false` for product viewers so users cannot lose the object.
3. Replace `OrbitControls` with `MapControls` (same import folder) and compare.
4. Listen for `controls.addEventListener('change', ...)` and render only when something changed, instead of every frame, to save battery on static scenes.
