Skip to content

Commit

Permalink
clean up plane generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiaoji Chen committed Dec 20, 2019
1 parent 2e704e9 commit 70b51b7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 26 deletions.
9 changes: 2 additions & 7 deletions modules/culling/src/lib/culling-volume.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default class CullingVolume {
.add(center);
const plane0Distance = -faceNormal.dot(plane0Center);

plane0.fromCoefficients(faceNormal.x, faceNormal.y, faceNormal.z, plane0Distance);
plane0.fromPointNormal(plane0Center, faceNormal);

const plane1Center = scratchPlaneCenter
.copy(faceNormal)
Expand All @@ -77,12 +77,7 @@ export default class CullingVolume {

const plane1Distance = -negatedFaceNormal.dot(plane1Center);

plane1.fromCoefficients(
negatedFaceNormal.x,
negatedFaceNormal.y,
negatedFaceNormal.z,
plane1Distance
);
plane1.fromPointNormal(plane1Center, negatedFaceNormal);

planeIndex += 2;
}
Expand Down
28 changes: 9 additions & 19 deletions modules/culling/src/lib/perspective-off-center-frustum.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,9 @@ export default class PerspectiveOffCenterFrustum {
.multiplyByScalar(this.left)
.add(nearCenter)
.subtract(position)
.cross(up)
.normalize();
.cross(up);

let plane = planes[0];
plane.fromCoefficients(normal.x, normal.y, normal.z, -normal.dot(position));
planes[0].fromPointNormal(position, normal);

// Right plane computation
normal
Expand All @@ -227,11 +225,9 @@ export default class PerspectiveOffCenterFrustum {
.add(nearCenter)
.subtract(position)
.cross(up)
.normalize()
.negate();

plane = planes[1];
plane.fromCoefficients(normal.x, normal.y, normal.z, -normal.dot(position));
planes[1].fromPointNormal(position, normal);

// Bottom plane computation
normal
Expand All @@ -240,35 +236,29 @@ export default class PerspectiveOffCenterFrustum {
.add(nearCenter)
.subtract(position)
.cross(right)
.normalize()
.negate();

plane = planes[2];
plane.fromCoefficients(normal.x, normal.y, normal.z, -normal.dot(position));
planes[2].fromPointNormal(position, normal);

// Top plane computation
normal
.copy(up)
.multiplyByScalar(this.top)
.add(nearCenter)
.subtract(position)
.cross(right)
.normalize();
.cross(right);

plane = planes[3];
plane.fromCoefficients(normal.x, normal.y, normal.z, -normal.dot(position));
planes[3].fromPointNormal(position, normal);

normal = new Vector3().copy(direction).normalize();
normal = new Vector3().copy(direction);

// Near plane computation
plane = planes[4];
plane.fromCoefficients(normal.x, normal.y, normal.z, -normal.dot(nearCenter));
planes[4].fromPointNormal(nearCenter, normal);

// Far plane computation
normal.negate();

plane = planes[5];
plane.fromCoefficients(normal.x, normal.y, normal.z, -normal.dot(farCenter));
planes[5].fromPointNormal(farCenter, normal);

return this._cullingVolume;
}
Expand Down

0 comments on commit 70b51b7

Please sign in to comment.