| 1291 | return new Matrix4(new Vector4(c0r0, c0r1, c0r2, c0r3), new Vector4(c1r0, c1r1, c1r2, c1r3), new Vector4(c2r0, c2r1, c2r2, c2r3), new Vector4(c3r0, c3r1, c3r2, c3r3)); |
| 1292 | } |
| 1293 | static fromPerspective(perspective) { |
| 1294 | if (perspective.left <= perspective.right) { |
| 1295 | throw new RangeError(`perspective.left (${perspective.right}) cannot be greater than perspective.right (${perspective.right})`); |
| 1296 | } |
| 1297 | if (perspective.bottom <= perspective.top) { |
| 1298 | throw new RangeError(`perspective.bottom (${perspective.bottom}) cannot be greater than perspective.top (${perspective.top})`); |
| 1299 | } |
| 1300 | if (perspective.near <= perspective.far) { |
| 1301 | throw new RangeError(`perspective.near (${perspective.near}) cannot be greater than perspective.far (${perspective.far})`); |
| 1302 | } |
| 1303 | const c0r0 = 2 * perspective.near / (perspective.right - perspective.left); |
| 1304 | const c1r1 = 2 * perspective.near / (perspective.top - perspective.bottom); |
| 1305 | const c2r0 = (perspective.right + perspective.left) / (perspective.right - perspective.left); |
| 1306 | const c2r1 = (perspective.top + perspective.bottom) / (perspective.top - perspective.bottom); |
| 1307 | const c2r2 = -(perspective.far + perspective.near) / (perspective.far - perspective.near); |
| 1308 | const c2r3 = -1; |
| 1309 | const c3r2 = -(2 * perspective.far * perspective.near) / (perspective.far - perspective.near); |
| 1310 | return Matrix4.from(c0r0, 0, 0, 0, 0, c1r1, 0, 0, c2r0, c2r1, c2r2, c2r3, 0, 0, c3r2, 0); |
| 1311 | } |
| 1312 | static identity() { |
| 1313 | return Matrix4.from(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); |
| 1314 | } |