-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12831 from sebavan/projectOnPlane
Reinstate original version of projectOnPlaneToRef with small amendment
- Loading branch information
Showing
2 changed files
with
38 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 17 additions & 26 deletions
43
packages/dev/core/test/unit/Math/babylon.math.vector.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,34 @@ | ||
import { Plane, Vector3 } from 'core/Maths' | ||
import { Plane, Vector3 } from "core/Maths"; | ||
|
||
/** | ||
* Describes the test suite. | ||
*/ | ||
describe("Babylon Vectors", () => { | ||
describe("#Vector3", () => { | ||
it("can project a direction vector onto a plane", () => { | ||
it("can project from an origin onto a plane", () => { | ||
// A ground plane at origin | ||
const simplePlane = Plane.FromPositionAndNormal( | ||
Vector3.Zero(), | ||
Vector3.Up(), | ||
); | ||
const simplePlane = Plane.FromPositionAndNormal(Vector3.Zero(), Vector3.Up()); | ||
|
||
const rayOrigin = new Vector3(0, 10, 0); | ||
const rayAngle = new Vector3(0.5, -0.5, 0); | ||
const rayGoingThrough = new Vector3(1, 8, 0); | ||
|
||
/* | ||
* At 45 degrees this should form a perfect right triangle, | ||
* so the result should be the same as the distance to the origin. | ||
*/ | ||
const expected = new Vector3(10, 0, 0); | ||
// Going left 1 unit for each 2 units downs | ||
const expected = new Vector3(5, 0, 0); | ||
|
||
expect(rayAngle.projectOnPlane(simplePlane, rayOrigin)).toEqual(expected) | ||
}) | ||
expect(rayGoingThrough.projectOnPlane(simplePlane, rayOrigin)).toEqual(expected); | ||
}); | ||
|
||
it("can project a direction vector onto an offset plane", () => { | ||
it("can project from an origin onto an offset plane", () => { | ||
// A ground plane 10 units below origin | ||
const simplePlane = Plane.FromPositionAndNormal( | ||
new Vector3(0, -10, 0), | ||
Vector3.Up(), | ||
); | ||
const simplePlane = Plane.FromPositionAndNormal(new Vector3(0, -10, 0), Vector3.Up()); | ||
|
||
const rayOrigin = new Vector3(0, 10, 0); | ||
const rayAngle = new Vector3(0.5, -0.5, 0); | ||
const rayGoingThrough = new Vector3(1, 8, 0); | ||
|
||
// This is also a right triangle, but the plane is offset so the hit point is offset and the distance increases | ||
const expected = new Vector3(20, -10, 0); | ||
// Going left 1 unit for each 2 units downs | ||
const expected = new Vector3(10, -10, 0); | ||
|
||
expect(rayAngle.projectOnPlane(simplePlane, rayOrigin)).toEqual(expected) | ||
}) | ||
}) | ||
}) | ||
expect(rayGoingThrough.projectOnPlane(simplePlane, rayOrigin)).toEqual(expected); | ||
}); | ||
}); | ||
}); |