(p5, fn)
| 8 | import { Vector } from '../math/p5.Vector'; |
| 9 | |
| 10 | function interaction(p5, fn){ |
| 11 | /** |
| 12 | * Allows the user to orbit around a 3D sketch using a mouse, trackpad, or |
| 13 | * touchscreen. |
| 14 | * |
| 15 | * 3D sketches are viewed through an imaginary camera. Calling |
| 16 | * `orbitControl()` within the <a href="#/p5/draw">draw()</a> function allows |
| 17 | * the user to change the camera’s position: |
| 18 | * |
| 19 | * ```js |
| 20 | * function draw() { |
| 21 | * background(200); |
| 22 | * |
| 23 | * // Enable orbiting with the mouse. |
| 24 | * orbitControl(); |
| 25 | * |
| 26 | * // Rest of sketch. |
| 27 | * } |
| 28 | * ``` |
| 29 | * |
| 30 | * Left-clicking and dragging or swipe motion will rotate the camera position |
| 31 | * about the center of the sketch. Right-clicking and dragging or multi-swipe |
| 32 | * will pan the camera position without rotation. Using the mouse wheel |
| 33 | * (scrolling) or pinch in/out will move the camera further or closer from the |
| 34 | * center of the sketch. |
| 35 | * |
| 36 | * The first three parameters, `sensitivityX`, `sensitivityY`, and |
| 37 | * `sensitivityZ`, are optional. They’re numbers that set the sketch’s |
| 38 | * sensitivity to movement along each axis. For example, calling |
| 39 | * `orbitControl(1, 2, -1)` keeps movement along the x-axis at its default |
| 40 | * value, makes the sketch twice as sensitive to movement along the y-axis, |
| 41 | * and reverses motion along the z-axis. By default, all sensitivity values |
| 42 | * are 1. |
| 43 | * |
| 44 | * The fourth parameter, `options`, is also optional. It’s an object that |
| 45 | * changes the behavior of orbiting. For example, calling |
| 46 | * `orbitControl(1, 1, 1, options)` keeps the default sensitivity values while |
| 47 | * changing the behaviors set with `options`. The object can have the |
| 48 | * following properties: |
| 49 | * |
| 50 | * ```js |
| 51 | * let options = { |
| 52 | * // Setting this to false makes mobile interactions smoother by |
| 53 | * // preventing accidental interactions with the page while orbiting. |
| 54 | * // By default, it's true. |
| 55 | * disableTouchActions: true, |
| 56 | * |
| 57 | * // Setting this to true makes the camera always rotate in the |
| 58 | * // direction the mouse/touch is moving. |
| 59 | * // By default, it's false. |
| 60 | * freeRotation: false |
| 61 | * }; |
| 62 | * |
| 63 | * orbitControl(1, 1, 1, options); |
| 64 | * ``` |
| 65 | * |
| 66 | * @method orbitControl |
| 67 | * @for p5 |
no test coverage detected