* Returns a camera's local axes: left-right, up-down, and forward-backward, * as defined by vectors in world-space. * @private
()
| 1822 | * @private |
| 1823 | */ |
| 1824 | _getLocalAxes() { |
| 1825 | // calculate camera local Z vector |
| 1826 | let z0 = this.eyeX - this.centerX; |
| 1827 | let z1 = this.eyeY - this.centerY; |
| 1828 | let z2 = this.eyeZ - this.centerZ; |
| 1829 | |
| 1830 | // normalize camera local Z vector |
| 1831 | const eyeDist = Math.sqrt(z0 * z0 + z1 * z1 + z2 * z2); |
| 1832 | if (eyeDist !== 0) { |
| 1833 | z0 /= eyeDist; |
| 1834 | z1 /= eyeDist; |
| 1835 | z2 /= eyeDist; |
| 1836 | } |
| 1837 | |
| 1838 | // calculate camera Y vector |
| 1839 | let y0 = this.upX; |
| 1840 | let y1 = this.upY; |
| 1841 | let y2 = this.upZ; |
| 1842 | |
| 1843 | // compute camera local X vector as up vector (local Y) cross local Z |
| 1844 | let x0 = y1 * z2 - y2 * z1; |
| 1845 | let x1 = -y0 * z2 + y2 * z0; |
| 1846 | let x2 = y0 * z1 - y1 * z0; |
| 1847 | |
| 1848 | // recompute y = z cross x |
| 1849 | y0 = z1 * x2 - z2 * x1; |
| 1850 | y1 = -z0 * x2 + z2 * x0; |
| 1851 | y2 = z0 * x1 - z1 * x0; |
| 1852 | |
| 1853 | // cross product gives area of parallelogram, which is < 1.0 for |
| 1854 | // non-perpendicular unit-length vectors; so normalize x, y here: |
| 1855 | const xmag = Math.sqrt(x0 * x0 + x1 * x1 + x2 * x2); |
| 1856 | if (xmag !== 0) { |
| 1857 | x0 /= xmag; |
| 1858 | x1 /= xmag; |
| 1859 | x2 /= xmag; |
| 1860 | } |
| 1861 | |
| 1862 | const ymag = Math.sqrt(y0 * y0 + y1 * y1 + y2 * y2); |
| 1863 | if (ymag !== 0) { |
| 1864 | y0 /= ymag; |
| 1865 | y1 /= ymag; |
| 1866 | y2 /= ymag; |
| 1867 | } |
| 1868 | |
| 1869 | return { |
| 1870 | x: [x0, x1, x2], |
| 1871 | y: [y0, y1, y2], |
| 1872 | z: [z0, z1, z2] |
| 1873 | }; |
| 1874 | } |
| 1875 | |
| 1876 | /** |
| 1877 | * Orbits the camera about center point. For use with orbitControl(). |
no outgoing calls
no test coverage detected