Skip to content

Commit 1602bb2

Browse files
authored
Merge pull request #6073 from AnalyticalGraphicsInc/plane-distance
Clipping planes invert distance sign
2 parents 9178af1 + 5b53733 commit 1602bb2

10 files changed

+34
-37
lines changed

Apps/Sandcastle/gallery/3D Tiles Clipping Planes.html

+2-5
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
var moveHandler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
9898
moveHandler.setInputAction(function(movement) {
9999
if (Cesium.defined(selectedPlane)) {
100-
var deltaY = movement.endPosition.y - movement.startPosition.y;
100+
var deltaY = movement.startPosition.y - movement.endPosition.y;
101101
targetY += deltaY;
102102
}
103103
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
@@ -106,10 +106,7 @@
106106
function createPlaneUpdateFunction(plane, transform) {
107107
return function () {
108108
plane.distance = targetY;
109-
110-
var transformedPlane = Cesium.Plane.transform(plane, transform, scratchPlane);
111-
transformedPlane.distance = -transformedPlane.distance;
112-
return transformedPlane;
109+
return Cesium.Plane.transform(plane, transform, scratchPlane);
113110
};
114111
}
115112

Apps/Sandcastle/gallery/Terrain Clipping Planes.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@
7575
globe.clippingPlanes = new Cesium.ClippingPlaneCollection({
7676
modelMatrix : entity.computeModelMatrix(Cesium.JulianDate.now()),
7777
planes : [
78-
new Cesium.Plane(new Cesium.Cartesian3( 1.0, 0.0, 0.0), 700.0),
79-
new Cesium.Plane(new Cesium.Cartesian3(-1.0, 0.0, 0.0), 700.0),
80-
new Cesium.Plane(new Cesium.Cartesian3( 0.0, 1.0, 0.0), 700.0),
81-
new Cesium.Plane(new Cesium.Cartesian3( 0.0, -1.0, 0.0), 700.0)
78+
new Cesium.Plane(new Cesium.Cartesian3( 1.0, 0.0, 0.0), -700.0),
79+
new Cesium.Plane(new Cesium.Cartesian3(-1.0, 0.0, 0.0), -700.0),
80+
new Cesium.Plane(new Cesium.Cartesian3( 0.0, 1.0, 0.0), -700.0),
81+
new Cesium.Plane(new Cesium.Cartesian3( 0.0, -1.0, 0.0), -700.0)
8282
],
8383
edgeWidth: 1.0,
8484
edgeColor: Cesium.Color.WHITE

Source/Core/Plane.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ define([
174174
Matrix4.multiplyByPointAsVector(transform, plane.normal, scratchNormal);
175175
Cartesian3.normalize(scratchNormal, scratchNormal);
176176

177-
Cartesian3.multiplyByScalar(plane.normal, plane.distance, scratchPosition);
177+
Cartesian3.multiplyByScalar(plane.normal, -plane.distance, scratchPosition);
178178
Matrix4.multiplyByPoint(transform, scratchPosition, scratchPosition);
179179

180180
return Plane.fromPointNormal(scratchPosition, scratchNormal, result);

Source/DataSources/PlaneGeometryUpdater.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ define([
686686
dimensions = new Cartesian2(1.0, 1.0);
687687
}
688688

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

692692
var transformedNormal = Matrix4.multiplyByPointAsVector(modelMatrix, normal, scratchNormal);

Specs/Core/ClippingPlaneCollectionSpec.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ defineSuite([
2424
new Plane(Cartesian3.UNIT_Y, 2.0)
2525
];
2626

27-
var transform = new Matrix4.fromTranslation(new Cartesian3(1.0, 2.0, 3.0));
27+
var transform = new Matrix4.fromTranslation(new Cartesian3(1.0, 3.0, 2.0));
2828
var boundingVolume = new BoundingSphere(Cartesian3.ZERO, 1.0);
2929

3030
it('default constructor', function() {
@@ -125,8 +125,8 @@ defineSuite([
125125

126126
var result = clippingPlanes.transformAndPackPlanes(transform);
127127
expect(result.length).toEqual(2);
128-
expect(result[0]).toEqual(new Cartesian4(1.0, 0.0, 0.0, -2.0));
129-
expect(result[1]).toEqual(new Cartesian4(0.0, 1.0, 0.0, -4.0));
128+
expect(result[0]).toEqual(new Cartesian4(1.0, 0.0, 0.0, 0.0));
129+
expect(result[1]).toEqual(new Cartesian4(0.0, 1.0, 0.0, -1.0));
130130
});
131131

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

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

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

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

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

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

235-
var temp = new Plane(Cartesian3.UNIT_Y, 2.0);
235+
var temp = new Plane(Cartesian3.UNIT_Y, -2.0);
236236
clippingPlanes.add(temp);
237237
intersect = clippingPlanes.computeIntersectionWithBoundingVolume(boundingVolume);
238238
expect(intersect).toEqual(Intersect.OUTSIDE);

Specs/Core/PlaneSpec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ defineSuite([
201201
transform = Matrix4.multiplyByMatrix3(transform, Matrix3.fromRotationY(Math.PI), transform);
202202

203203
var transformedPlane = Plane.transform(plane, transform);
204-
expect(transformedPlane.distance).toEqual(-plane.distance * 2.0);
204+
expect(transformedPlane.distance).toEqual(plane.distance * 2.0);
205205
expect(transformedPlane.normal.x).toEqualEpsilon(-plane.normal.x, CesiumMath.EPSILON10);
206206
expect(transformedPlane.normal.y).toEqual(plane.normal.y);
207207
expect(transformedPlane.normal.z).toEqual(-plane.normal.z);

Specs/Scene/Cesium3DTilesetSpec.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -2815,7 +2815,7 @@ defineSuite([
28152815

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

2818-
var plane = new Plane(Cartesian3.UNIT_Z, 100000000.0);
2818+
var plane = new Plane(Cartesian3.UNIT_Z, -100000000.0);
28192819
tileset.clippingPlanes = new ClippingPlaneCollection({
28202820
planes : [
28212821
plane
@@ -2839,7 +2839,7 @@ defineSuite([
28392839

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

2842-
var plane = new Plane(Cartesian3.UNIT_Z, 100000000.0);
2842+
var plane = new Plane(Cartesian3.UNIT_Z, -100000000.0);
28432843
tileset.clippingPlanes = new ClippingPlaneCollection({
28442844
planes : [
28452845
plane
@@ -2881,15 +2881,15 @@ defineSuite([
28812881
expect(statistics.numberOfCommands).toEqual(5);
28822882
expect(root._isClipped).toBe(false);
28832883

2884-
plane.distance = 4081630.311150717; // center
2884+
plane.distance = -4081630.311150717; // center
28852885

28862886
tileset.update(scene.frameState);
28872887
scene.renderForSpecs();
28882888

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

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

28942894
tileset.update(scene.frameState);
28952895
scene.renderForSpecs();
@@ -2923,15 +2923,15 @@ defineSuite([
29232923
expect(statistics.numberOfCommands).toEqual(6);
29242924
expect(root._isClipped).toBe(false);
29252925

2926-
plane.distance = 4081608.4377916814; // center
2926+
plane.distance = -4081608.4377916814; // center
29272927

29282928
tileset.update(scene.frameState);
29292929
scene.renderForSpecs();
29302930

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

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

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

Specs/Scene/GlobeSurfaceTileProviderSpec.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ defineSuite([
714714
expect(rgba).not.toEqual([0, 0, 0, 255]);
715715
});
716716

717-
var clipPlane = new Plane(Cartesian3.UNIT_Z, 10000.0);
717+
var clipPlane = new Plane(Cartesian3.UNIT_Z, -10000.0);
718718
scene.globe.clippingPlanes = new ClippingPlaneCollection ({
719719
planes : [
720720
clipPlane
@@ -745,7 +745,7 @@ defineSuite([
745745
expect(rgba).not.toEqual([0, 0, 0, 255]);
746746
});
747747

748-
var clipPlane = new Plane(Cartesian3.UNIT_Z, 1000.0);
748+
var clipPlane = new Plane(Cartesian3.UNIT_Z, -1000.0);
749749
scene.globe.clippingPlanes = new ClippingPlaneCollection ({
750750
planes : [
751751
clipPlane
@@ -780,8 +780,8 @@ defineSuite([
780780

781781
scene.globe.clippingPlanes = new ClippingPlaneCollection ({
782782
planes : [
783-
new Plane(Cartesian3.UNIT_Z, 10000.0),
784-
new Plane(Cartesian3.UNIT_X, 1000.0)
783+
new Plane(Cartesian3.UNIT_Z, -10000.0),
784+
new Plane(Cartesian3.UNIT_X, -1000.0)
785785
],
786786
unionClippingRegions: true
787787
});
@@ -809,7 +809,7 @@ defineSuite([
809809
var globe = scene.globe;
810810
globe.clippingPlanes = new ClippingPlaneCollection ({
811811
planes : [
812-
new Plane(Cartesian3.UNIT_Z, 1000000.0)
812+
new Plane(Cartesian3.UNIT_Z, -1000000.0)
813813
]
814814
});
815815

@@ -845,7 +845,7 @@ defineSuite([
845845
var globe = scene.globe;
846846
globe.clippingPlanes = new ClippingPlaneCollection ({
847847
planes : [
848-
new Plane(Cartesian3.UNIT_Z, -10000000.0)
848+
new Plane(Cartesian3.UNIT_Z, 10000000.0)
849849
]
850850
});
851851

Specs/Scene/ModelSpec.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -2588,7 +2588,7 @@ defineSuite([
25882588
expect(rgba).not.toEqual(modelColor);
25892589
});
25902590

2591-
plane.distance = -10.0;
2591+
plane.distance = 10.0;
25922592
model.update(scene.frameState);
25932593
expect(scene).toRenderAndCall(function(rgba) {
25942594
expect(rgba).toEqual(modelColor);
@@ -2623,7 +2623,7 @@ defineSuite([
26232623
expect(rgba).not.toEqual(modelColor);
26242624
});
26252625

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

26472647
model.clippingPlanes = new ClippingPlaneCollection({
26482648
planes : [
2649-
new Plane(Cartesian3.UNIT_Z, -5.0),
2649+
new Plane(Cartesian3.UNIT_Z, 5.0),
26502650
new Plane(Cartesian3.UNIT_X, 0.0)
26512651
],
26522652
unionClippingRegions: true

Specs/Scene/PointCloud3DTileContentSpec.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ defineSuite([
740740
color = rgba;
741741
});
742742

743-
var clipPlane = new Plane(Cartesian3.UNIT_Z, 10.0);
743+
var clipPlane = new Plane(Cartesian3.UNIT_Z, -10.0);
744744
tileset.clippingPlanes = new ClippingPlaneCollection({
745745
planes : [
746746
clipPlane
@@ -763,7 +763,7 @@ defineSuite([
763763
color = rgba;
764764
});
765765

766-
var clipPlane = new Plane(Cartesian3.UNIT_Z, 10.0);
766+
var clipPlane = new Plane(Cartesian3.UNIT_Z, -10.0);
767767
tileset.clippingPlanes = new ClippingPlaneCollection ({
768768
planes : [
769769
clipPlane
@@ -786,7 +786,7 @@ defineSuite([
786786

787787
tileset.clippingPlanes = new ClippingPlaneCollection ({
788788
planes : [
789-
new Plane(Cartesian3.UNIT_Z, 10.0),
789+
new Plane(Cartesian3.UNIT_Z, -10.0),
790790
new Plane(Cartesian3.UNIT_X, 0.0)
791791
],
792792
modelMatrix : Transforms.eastNorthUpToFixedFrame(tileset.boundingSphere.center),

0 commit comments

Comments
 (0)