Atlaslog
Atlaslog / three.js / Tutorial / Cameras and view control
three.js · Tutorial

Cameras and view control

Quick answer

This tutorial explains how fov, aspect, near and far define what a PerspectiveCamera sees, and why tight clipping planes preserve depth precision. It configures OrbitControls with enableDamping and distance limits, then switches to MapControls so panning follows the ground and rotation stays bounded. A Raycaster converts pointer events into normalized device coordinates for picking, and a manual tween moves camera and target together. Readers can build a stable city-scale navigation rig.

Last verified 2026-11-03 · three.js 0.160.0 · Cite this page
Key points
Example
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';

const camera = new THREE.PerspectiveCamera(
  50,                                       // fov
  window.innerWidth / window.innerHeight,   // aspect
  0.5,                                      // near
  20000                                     // far
);
camera.position.set(320, 180, 420);

const controls = new OrbitControls(camera, renderer.domElement);
controls.target.set(320, 20, 300);
controls.enableDamping = true;
controls.dampingFactor = 0.08;
controls.minDistance = 40;
controls.maxDistance = 6000;
controls.maxPolarAngle = THREE.MathUtils.degToRad(85);   // 不允许转到地下
controls.update();
import { MapControls } from 'three/addons/controls/MapControls.js';

const mapControls = new MapControls(camera, renderer.domElement);

mapControls.enableRotate = true;
mapControls.screenSpacePanning = false;   // 平移贴着地面,而不是屏幕平面
mapControls.zoomSpeed = 0.8;
mapControls.rotateSpeed = 0.5;
mapControls.keyPanSpeed = 12;
mapControls.minTargetRadius = 0;
mapControls.maxTargetRadius = 2500;
Notes
Runnable examplesChinese originalAll Tutorials
English edition written for Atlaslog. Code is taken from the original Chinese page and runs unchanged.
Cite this page

Atlaslog (2026). Cameras and view control. https://www.jingweizhi.com/en/three/tutorials/camera-controls.html (accessed 2026-11-03).