Skip to content

Commit

Permalink
feat(culling): Addd transforms to bounding boxes
Browse files Browse the repository at this point in the history
feat(culling): Addd transforms to bounding boxes

lint

Merge branch ib/bounding-box-transforms of github.com:atomicra/math.gl into ib/bounding-box-transforms

feat(culling): Add transforms to bounding boxes

ib/bounding-box-transform conflict repaired
  • Loading branch information
ibgreen committed May 30, 2021
1 parent 10f802c commit 279c7e8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
3 changes: 3 additions & 0 deletions modules/culling/src/lib/axis-aligned-bounding-box.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ export default class AxisAlignedBoundingBox {

transform(transformation) {
this.center.transformAsPoint(transformation);
// TODO - this.halfDiagonal.transformAsVector(transformation);
this.halfDiagonal.transform(transformation);
this.minimum.transform(transformation);
this.maximum.transform(transformation);
return this;
}

Expand Down
10 changes: 3 additions & 7 deletions modules/culling/src/lib/oriented-bounding-box.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ const scratchVectorW = new Vector3();
const scratchCorner = new Vector3();
const scratchToCenter = new Vector3();

const fromOrientedBoundingBoxScratchU = new Vector3();
const fromOrientedBoundingBoxScratchV = new Vector3();
const fromOrientedBoundingBoxScratchW = new Vector3();

const MATRIX3 = {
COLUMN0ROW0: 0,
COLUMN0ROW1: 1,
Expand Down Expand Up @@ -86,9 +82,9 @@ export default class OrientedBoundingBox {
// Computes a tight-fitting bounding sphere enclosing the provided oriented bounding box.
getBoundingSphere(result = new BoundingSphere()) {
const halfAxes = this.halfAxes;
const u = halfAxes.getColumn(0, fromOrientedBoundingBoxScratchU);
const v = halfAxes.getColumn(1, fromOrientedBoundingBoxScratchV);
const w = halfAxes.getColumn(2, fromOrientedBoundingBoxScratchW);
const u = halfAxes.getColumn(0, scratchVectorU);
const v = halfAxes.getColumn(1, scratchVectorV);
const w = halfAxes.getColumn(2, scratchVectorW);

// Calculate "corner" vector
const cornerVector = scratchVector3
Expand Down
15 changes: 9 additions & 6 deletions modules/culling/test/lib/axis-aligned-bounding-box.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import {
INTERSECTION,
Plane
} from '@math.gl/culling';
import {Vector3} from '@math.gl/core';
// import {Vector3, Matrix4} from '@math.gl/core';
import {Vector3, Matrix4} from '@math.gl/core';

const positions = [
new Vector3(3, -1, -3),
Expand Down Expand Up @@ -109,7 +108,6 @@ it('makeAxisAlignedBoundingBoxFromPoints computes the bounding box for a single
expect(box.center).toEqual(positions[0]);
});

/*
it('AxisAlignedBoundingBox#applies transform: translation, rotation, scale', () => {
const min = new Vector3(1, 1, 1);
const max = new Vector3(3, 3, 3);
Expand All @@ -118,11 +116,16 @@ it('AxisAlignedBoundingBox#applies transform: translation, rotation, scale', ()
.translate(new Vector3(1.0, 2.0, 3.0))
.rotateZ(Math.PI / 2)
.scale(2);
const expected = new AxisAlignedBoundingBox(min, max, new Vector3(-2.9999999999999996, 6, 7));
const center = new Vector3(-2.9999999999999996, 6, 7);
const halfDiagonal = new Vector3(-0.9999999999999998, 4, 5);
const minimum = new Vector3(-0.9999999999999998, 4, 5);
const maximum = new Vector3(-5, 8, 9);
const result = abb.transform(transform);
expect(expected).toEqual(result);
expect(center).toEqual(result.center);
expect(halfDiagonal).toEqual(result.halfDiagonal);
expect(minimum).toEqual(result.minimum);
expect(maximum).toEqual(result.maximum);
});
*/

it('AxisAlignedBoundingBox#intersectPlane works with box on the positive side of a plane', () => {
const box = new AxisAlignedBoundingBox(new Vector3(VECTOR3_UNIT_X).negate(), VECTOR3_ZERO);
Expand Down
7 changes: 3 additions & 4 deletions modules/culling/test/lib/oriented-bounding-box.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -650,8 +650,7 @@ test('OrientedBoundingBox#computePlaneDistances throws without a direction', t =
t.end();
});

/*
test.skip('OrientedBoundingBox#applies transform: translation, rotation, scale', t => {
test('OrientedBoundingBox#applies transform: translation, rotation, scale', t => {
const VECTOR3_ZERO = new Vector3(0, 0, 0);
const obb = new OrientedBoundingBox(VECTOR3_ZERO, [1, 0, 0, 0, 1, 0, 0, 0, 1]);
const transform = new Matrix4()
Expand All @@ -670,10 +669,10 @@ test.skip('OrientedBoundingBox#applies transform: translation, rotation, scale',
5
]);
const result = obb.transform(transform);
tapeEquals(t, result, expected);
tapeEquals(t, result.center, expected.center);
tapeEquals(t, result.halfAxes, expected.halfAxes);
t.end();
});
*/

/*
test('OrientedBoundingBox#isOccluded', t => {
Expand Down

0 comments on commit 279c7e8

Please sign in to comment.