0.2.4 • Published 10 months ago
frustum-intersects v0.2.4
Frustum-Intersects
A zero-dependency lib extracted from THREE.js to determine if camera's frustum intersects with given box or sphere.
Usage
npm
npm i frustum-intersects --save
import { intersectsBox, intersectsSphere } from 'frustum-intersects';
const ret = intersectsBox([
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1],
[[-1,-1,-1], [1,1,1]]);
const ret2 = intersectsSphere([
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1],
[[0, 0, 0], 1]);
Browser
<script src="https://cdn.jsdelivr.net/npm/frustum-intersects/dist/frustum-intersects.js"></script>
<script>
const ret = frustum.intersectsBox(matrix, box);
</script>
API
intersectsBox(matrix, box, mask)
matrix
camera's 4x4 projection view matrix array, compatible with gl-matrixbox
the aabb box, [minx, miny, minz, maxx, maxy, maxz]mask
A 6 chars string mask (e.g."111111"
) of frustum planes, plane with mask of0
will always returntrue
intersectsSphere(matrix, sphere, mask)
matrix
camera's 4x4 projection view matrix array, compatible with gl-matrixsphere
sphere, [centerx, centery, centerz, radius]mask
A 6 chars string mask (e.g."111111"
) of frustum planes, plane with mask of0
will always returntrue
the planes' order of mask is
{right}{left}{bottom}{top}{z-far}{z-near}
,