Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clipping planes invert distance sign #6073

Merged
merged 1 commit into from
Jan 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions Apps/Sandcastle/gallery/3D Tiles Clipping Planes.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
var moveHandler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
moveHandler.setInputAction(function(movement) {
if (Cesium.defined(selectedPlane)) {
var deltaY = movement.endPosition.y - movement.startPosition.y;
var deltaY = movement.startPosition.y - movement.endPosition.y;
targetY += deltaY;
}
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
Expand All @@ -106,10 +106,7 @@
function createPlaneUpdateFunction(plane, transform) {
return function () {
plane.distance = targetY;

var transformedPlane = Cesium.Plane.transform(plane, transform, scratchPlane);
transformedPlane.distance = -transformedPlane.distance;
return transformedPlane;
return Cesium.Plane.transform(plane, transform, scratchPlane);
};
}

Expand Down
8 changes: 4 additions & 4 deletions Apps/Sandcastle/gallery/Terrain Clipping Planes.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@
globe.clippingPlanes = new Cesium.ClippingPlaneCollection({
modelMatrix : entity.computeModelMatrix(Cesium.JulianDate.now()),
planes : [
new Cesium.Plane(new Cesium.Cartesian3( 1.0, 0.0, 0.0), 700.0),
new Cesium.Plane(new Cesium.Cartesian3(-1.0, 0.0, 0.0), 700.0),
new Cesium.Plane(new Cesium.Cartesian3( 0.0, 1.0, 0.0), 700.0),
new Cesium.Plane(new Cesium.Cartesian3( 0.0, -1.0, 0.0), 700.0)
new Cesium.Plane(new Cesium.Cartesian3( 1.0, 0.0, 0.0), -700.0),
new Cesium.Plane(new Cesium.Cartesian3(-1.0, 0.0, 0.0), -700.0),
new Cesium.Plane(new Cesium.Cartesian3( 0.0, 1.0, 0.0), -700.0),
new Cesium.Plane(new Cesium.Cartesian3( 0.0, -1.0, 0.0), -700.0)
],
edgeWidth: 1.0,
edgeColor: Cesium.Color.WHITE
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Plane.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ define([
Matrix4.multiplyByPointAsVector(transform, plane.normal, scratchNormal);
Cartesian3.normalize(scratchNormal, scratchNormal);

Cartesian3.multiplyByScalar(plane.normal, plane.distance, scratchPosition);
Cartesian3.multiplyByScalar(plane.normal, -plane.distance, scratchPosition);
Matrix4.multiplyByPoint(transform, scratchPosition, scratchPosition);

return Plane.fromPointNormal(scratchPosition, scratchNormal, result);
Expand Down
2 changes: 1 addition & 1 deletion Source/DataSources/PlaneGeometryUpdater.js
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ define([
dimensions = new Cartesian2(1.0, 1.0);
}

var translation = Cartesian3.multiplyByScalar(normal, distance, scratchTranslation);
var translation = Cartesian3.multiplyByScalar(normal, -distance, scratchTranslation);
translation = Matrix4.multiplyByPoint(modelMatrix, translation, translation);

var transformedNormal = Matrix4.multiplyByPointAsVector(modelMatrix, normal, scratchNormal);
Expand Down
14 changes: 7 additions & 7 deletions Specs/Core/ClippingPlaneCollectionSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ defineSuite([
new Plane(Cartesian3.UNIT_Y, 2.0)
];

var transform = new Matrix4.fromTranslation(new Cartesian3(1.0, 2.0, 3.0));
var transform = new Matrix4.fromTranslation(new Cartesian3(1.0, 3.0, 2.0));
var boundingVolume = new BoundingSphere(Cartesian3.ZERO, 1.0);

it('default constructor', function() {
Expand Down Expand Up @@ -125,8 +125,8 @@ defineSuite([

var result = clippingPlanes.transformAndPackPlanes(transform);
expect(result.length).toEqual(2);
expect(result[0]).toEqual(new Cartesian4(1.0, 0.0, 0.0, -2.0));
expect(result[1]).toEqual(new Cartesian4(0.0, 1.0, 0.0, -4.0));
expect(result[0]).toEqual(new Cartesian4(1.0, 0.0, 0.0, 0.0));
expect(result[1]).toEqual(new Cartesian4(0.0, 1.0, 0.0, -1.0));
});

it('transforms and packs planes with no result parameter creates new array', function() {
Expand Down Expand Up @@ -203,15 +203,15 @@ defineSuite([
var intersect = clippingPlanes.computeIntersectionWithBoundingVolume(boundingVolume);
expect(intersect).toEqual(Intersect.INSIDE);

clippingPlanes.add(new Plane(Cartesian3.UNIT_X, 2.0));
clippingPlanes.add(new Plane(Cartesian3.UNIT_X, -2.0));
intersect = clippingPlanes.computeIntersectionWithBoundingVolume(boundingVolume);
expect(intersect).toEqual(Intersect.OUTSIDE);

clippingPlanes.add(new Plane(Cartesian3.UNIT_Y, 0.0));
intersect = clippingPlanes.computeIntersectionWithBoundingVolume(boundingVolume);
expect(intersect).toEqual(Intersect.INTERSECTING);

clippingPlanes.add(new Plane(Cartesian3.UNIT_Z, -1.0));
clippingPlanes.add(new Plane(Cartesian3.UNIT_Z, 1.0));
intersect = clippingPlanes.computeIntersectionWithBoundingVolume(boundingVolume);
expect(intersect).toEqual(Intersect.INSIDE);

Expand All @@ -228,11 +228,11 @@ defineSuite([
var intersect = clippingPlanes.computeIntersectionWithBoundingVolume(boundingVolume);
expect(intersect).toEqual(Intersect.INSIDE);

clippingPlanes.add(new Plane(Cartesian3.UNIT_Z, -1.0));
clippingPlanes.add(new Plane(Cartesian3.UNIT_Z, 1.0));
intersect = clippingPlanes.computeIntersectionWithBoundingVolume(boundingVolume);
expect(intersect).toEqual(Intersect.INSIDE);

var temp = new Plane(Cartesian3.UNIT_Y, 2.0);
var temp = new Plane(Cartesian3.UNIT_Y, -2.0);
clippingPlanes.add(temp);
intersect = clippingPlanes.computeIntersectionWithBoundingVolume(boundingVolume);
expect(intersect).toEqual(Intersect.OUTSIDE);
Expand Down
2 changes: 1 addition & 1 deletion Specs/Core/PlaneSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ defineSuite([
transform = Matrix4.multiplyByMatrix3(transform, Matrix3.fromRotationY(Math.PI), transform);

var transformedPlane = Plane.transform(plane, transform);
expect(transformedPlane.distance).toEqual(-plane.distance * 2.0);
expect(transformedPlane.distance).toEqual(plane.distance * 2.0);
expect(transformedPlane.normal.x).toEqualEpsilon(-plane.normal.x, CesiumMath.EPSILON10);
expect(transformedPlane.normal.y).toEqual(plane.normal.y);
expect(transformedPlane.normal.z).toEqual(-plane.normal.z);
Expand Down
12 changes: 6 additions & 6 deletions Specs/Scene/Cesium3DTilesetSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2815,7 +2815,7 @@ defineSuite([

expect(visibility).not.toBe(CullingVolume.MASK_OUTSIDE);

var plane = new Plane(Cartesian3.UNIT_Z, 100000000.0);
var plane = new Plane(Cartesian3.UNIT_Z, -100000000.0);
tileset.clippingPlanes = new ClippingPlaneCollection({
planes : [
plane
Expand All @@ -2839,7 +2839,7 @@ defineSuite([

expect(visibility).not.toBe(Intersect.OUTSIDE);

var plane = new Plane(Cartesian3.UNIT_Z, 100000000.0);
var plane = new Plane(Cartesian3.UNIT_Z, -100000000.0);
tileset.clippingPlanes = new ClippingPlaneCollection({
planes : [
plane
Expand Down Expand Up @@ -2881,15 +2881,15 @@ defineSuite([
expect(statistics.numberOfCommands).toEqual(5);
expect(root._isClipped).toBe(false);

plane.distance = 4081630.311150717; // center
plane.distance = -4081630.311150717; // center

tileset.update(scene.frameState);
scene.renderForSpecs();

expect(statistics.numberOfCommands).toEqual(3);
expect(root._isClipped).toBe(true);

plane.distance = 4081630.31115071 + 287.0736139905632; // center + radius
plane.distance = -4081630.31115071 - 287.0736139905632; // center + radius

tileset.update(scene.frameState);
scene.renderForSpecs();
Expand Down Expand Up @@ -2923,15 +2923,15 @@ defineSuite([
expect(statistics.numberOfCommands).toEqual(6);
expect(root._isClipped).toBe(false);

plane.distance = 4081608.4377916814; // center
plane.distance = -4081608.4377916814; // center

tileset.update(scene.frameState);
scene.renderForSpecs();

expect(statistics.numberOfCommands).toEqual(6);
expect(root._isClipped).toBe(true);

plane.distance = 4081608.4377916814 + 142.19001637409772; // center + radius
plane.distance = -4081608.4377916814 - 142.19001637409772; // center + radius

tileset.update(scene.frameState);
scene.renderForSpecs();
Expand Down
12 changes: 6 additions & 6 deletions Specs/Scene/GlobeSurfaceTileProviderSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ defineSuite([
expect(rgba).not.toEqual([0, 0, 0, 255]);
});

var clipPlane = new Plane(Cartesian3.UNIT_Z, 10000.0);
var clipPlane = new Plane(Cartesian3.UNIT_Z, -10000.0);
scene.globe.clippingPlanes = new ClippingPlaneCollection ({
planes : [
clipPlane
Expand Down Expand Up @@ -745,7 +745,7 @@ defineSuite([
expect(rgba).not.toEqual([0, 0, 0, 255]);
});

var clipPlane = new Plane(Cartesian3.UNIT_Z, 1000.0);
var clipPlane = new Plane(Cartesian3.UNIT_Z, -1000.0);
scene.globe.clippingPlanes = new ClippingPlaneCollection ({
planes : [
clipPlane
Expand Down Expand Up @@ -780,8 +780,8 @@ defineSuite([

scene.globe.clippingPlanes = new ClippingPlaneCollection ({
planes : [
new Plane(Cartesian3.UNIT_Z, 10000.0),
new Plane(Cartesian3.UNIT_X, 1000.0)
new Plane(Cartesian3.UNIT_Z, -10000.0),
new Plane(Cartesian3.UNIT_X, -1000.0)
],
unionClippingRegions: true
});
Expand Down Expand Up @@ -809,7 +809,7 @@ defineSuite([
var globe = scene.globe;
globe.clippingPlanes = new ClippingPlaneCollection ({
planes : [
new Plane(Cartesian3.UNIT_Z, 1000000.0)
new Plane(Cartesian3.UNIT_Z, -1000000.0)
]
});

Expand Down Expand Up @@ -845,7 +845,7 @@ defineSuite([
var globe = scene.globe;
globe.clippingPlanes = new ClippingPlaneCollection ({
planes : [
new Plane(Cartesian3.UNIT_Z, -10000000.0)
new Plane(Cartesian3.UNIT_Z, 10000000.0)
]
});

Expand Down
6 changes: 3 additions & 3 deletions Specs/Scene/ModelSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2588,7 +2588,7 @@ defineSuite([
expect(rgba).not.toEqual(modelColor);
});

plane.distance = -10.0;
plane.distance = 10.0;
model.update(scene.frameState);
expect(scene).toRenderAndCall(function(rgba) {
expect(rgba).toEqual(modelColor);
Expand Down Expand Up @@ -2623,7 +2623,7 @@ defineSuite([
expect(rgba).not.toEqual(modelColor);
});

plane.distance = -5.0;
plane.distance = 5.0;
model.update(scene.frameState);
expect(scene).toRenderAndCall(function(rgba) {
expect(rgba).toEqual([0, 0, 255, 255]);
Expand All @@ -2646,7 +2646,7 @@ defineSuite([

model.clippingPlanes = new ClippingPlaneCollection({
planes : [
new Plane(Cartesian3.UNIT_Z, -5.0),
new Plane(Cartesian3.UNIT_Z, 5.0),
new Plane(Cartesian3.UNIT_X, 0.0)
],
unionClippingRegions: true
Expand Down
6 changes: 3 additions & 3 deletions Specs/Scene/PointCloud3DTileContentSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ defineSuite([
color = rgba;
});

var clipPlane = new Plane(Cartesian3.UNIT_Z, 10.0);
var clipPlane = new Plane(Cartesian3.UNIT_Z, -10.0);
tileset.clippingPlanes = new ClippingPlaneCollection({
planes : [
clipPlane
Expand All @@ -763,7 +763,7 @@ defineSuite([
color = rgba;
});

var clipPlane = new Plane(Cartesian3.UNIT_Z, 10.0);
var clipPlane = new Plane(Cartesian3.UNIT_Z, -10.0);
tileset.clippingPlanes = new ClippingPlaneCollection ({
planes : [
clipPlane
Expand All @@ -786,7 +786,7 @@ defineSuite([

tileset.clippingPlanes = new ClippingPlaneCollection ({
planes : [
new Plane(Cartesian3.UNIT_Z, 10.0),
new Plane(Cartesian3.UNIT_Z, -10.0),
new Plane(Cartesian3.UNIT_X, 0.0)
],
modelMatrix : Transforms.eastNorthUpToFixedFrame(tileset.boundingSphere.center),
Expand Down