| 64 | } |
| 65 | |
| 66 | function CameraController({ step }: CameraControllerProps) { |
| 67 | const { camera } = useThree(); |
| 68 | const targetRef = useRef(new THREE.Vector3()); |
| 69 | |
| 70 | useEffect(() => { |
| 71 | const config = stepCameras[step]; |
| 72 | const targetPosition = new THREE.Vector3(...config.position); |
| 73 | const targetLookAt = new THREE.Vector3(...config.target); |
| 74 | |
| 75 | // Animate camera position |
| 76 | const startPosition = camera.position.clone(); |
| 77 | const startTime = performance.now(); |
| 78 | const duration = 800; |
| 79 | |
| 80 | function animate() { |
| 81 | const elapsed = performance.now() - startTime; |
| 82 | const progress = Math.min(elapsed / duration, 1); |
| 83 | // Ease out cubic |
| 84 | const eased = 1 - Math.pow(1 - progress, 3); |
| 85 | |
| 86 | camera.position.lerpVectors(startPosition, targetPosition, eased); |
| 87 | targetRef.current.lerpVectors(targetRef.current, targetLookAt, eased * 0.1); |
| 88 | camera.lookAt(targetLookAt); |
| 89 | |
| 90 | if (progress < 1) { |
| 91 | requestAnimationFrame(animate); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | animate(); |
| 96 | }, [step, camera]); |
| 97 | |
| 98 | return null; |
| 99 | } |
| 100 | |
| 101 | interface SceneProps { |
| 102 | step: HowItWorksStep; |