| 1464 | return (x > y ? x - y : x - y) <= epsilon; |
| 1465 | } |
| 1466 | class Perspective { |
| 1467 | left; |
| 1468 | right; |
| 1469 | bottom; |
| 1470 | top; |
| 1471 | near; |
| 1472 | far; |
| 1473 | constructor(left, right, bottom, top, near, far){ |
| 1474 | this.left = left; |
| 1475 | this.right = right; |
| 1476 | this.bottom = bottom; |
| 1477 | this.top = top; |
| 1478 | this.near = near; |
| 1479 | this.far = far; |
| 1480 | } |
| 1481 | toMatrix4() { |
| 1482 | if (this.left > this.right) { |
| 1483 | throw new RangeError(`perspective.left (${this.right}) cannot be greater than perspective.right (${this.right})`); |
| 1484 | } |
| 1485 | if (this.bottom > this.top) { |
| 1486 | throw new RangeError(`perspective.bottom (${this.bottom}) cannot be greater than perspective.top (${this.top})`); |
| 1487 | } |
| 1488 | if (this.near > this.far) { |
| 1489 | throw new RangeError(`perspective.near (${this.near}) cannot be greater than perspective.far (${this.far})`); |
| 1490 | } |
| 1491 | const c0r0 = 2 * this.near / (this.right - this.left); |
| 1492 | const c1r1 = 2 * this.near / (this.top - this.bottom); |
| 1493 | const c2r0 = (this.right + this.left) / (this.right - this.left); |
| 1494 | const c2r1 = (this.top + this.bottom) / (this.top - this.bottom); |
| 1495 | const c2r2 = -(this.far + this.near) / (this.far - this.near); |
| 1496 | const c2r3 = -1; |
| 1497 | const c3r2 = -(2 * this.far * this.near) / (this.far - this.near); |
| 1498 | return Matrix4.from(c0r0, 0, 0, 0, 0, c1r1, 0, 0, c2r0, c2r1, c2r2, c2r3, 0, 0, c3r2, 0); |
| 1499 | } |
| 1500 | } |
| 1501 | class PerspectiveFov { |
| 1502 | fovy; |
| 1503 | aspect; |
nothing calls this directly
no outgoing calls
no test coverage detected