Skip to content

Commit

Permalink
More Cartographic cleanup
Browse files Browse the repository at this point in the history
1. Remove all usage of creating Cartographic instances using degrees as internal representation, Cartographics are always represented as radians.
2. Add fromDegrees helper function to aid in creating Cartographics from degrees.
3. Reaname toCartesian(s) and toCartographic(s) methods to cartesianToCartographic/cartesianArrayToCartographicArray and cartographicToCartesian and cartographicArrayToCartesianArray respectively.
4. Fix comment in Quaternion.fromAxisAngle to specify the correct unit.
  • Loading branch information
mramato committed Jul 16, 2012
1 parent e9f9b2d commit c1e68f1
Show file tree
Hide file tree
Showing 47 changed files with 336 additions and 371 deletions.
2 changes: 1 addition & 1 deletion Examples/Sandbox/CodeSnippets/Advanced.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
return Cesium.destroyObject(this);
};

primitives.add(new Sandbox.ExamplePrimitive(ellipsoid.cartographicDegreesToCartesian(new Cesium.Cartographic(-75.59777, 40.03883))));
primitives.add(new Sandbox.ExamplePrimitive(ellipsoid.cartographicToCartesian(Cesium.Cartographic.fromDegrees(-75.59777, 40.03883))));
};

this.clear = function () {
Expand Down
32 changes: 16 additions & 16 deletions Examples/Sandbox/CodeSnippets/Billboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
var textureAtlas = scene.getContext().createTextureAtlas({image : image});
billboards.setTextureAtlas(textureAtlas);
billboards.add({
position : ellipsoid.cartographicDegreesToCartesian(new Cesium.Cartographic(-75.59777, 40.03883)),
position : ellipsoid.cartographicToCartesian(Cesium.Cartographic.fromDegrees(-75.59777, 40.03883)),
imageIndex : 0
});
primitives.add(billboards);
Expand All @@ -37,17 +37,17 @@
billboards.setTextureAtlas(textureAtlas);

billboards.add({
position : ellipsoid.cartographicDegreesToCartesian(new Cesium.Cartographic(-75.59777, 40.03883)),
position : ellipsoid.cartographicToCartesian(Cesium.Cartographic.fromDegrees(-75.59777, 40.03883)),
imageIndex : 0 // Logo
});

billboards.add({
position : ellipsoid.cartographicDegreesToCartesian(new Cesium.Cartographic(-80.50, 35.14)),
position : ellipsoid.cartographicToCartesian(Cesium.Cartographic.fromDegrees(-80.50, 35.14)),
imageIndex : 1 // Facility
});

billboards.add({
position : ellipsoid.cartographicDegreesToCartesian(new Cesium.Cartographic(-80.12, 25.46)),
position : ellipsoid.cartographicToCartesian(Cesium.Cartographic.fromDegrees(-80.12, 25.46)),
imageIndex : 1 // Facility
});

Expand Down Expand Up @@ -78,18 +78,18 @@
var textureAtlas = scene.getContext().createTextureAtlas({image : canvas});
billboards.setTextureAtlas(textureAtlas);
billboards.add({
position : ellipsoid.cartographicDegreesToCartesian(new Cesium.Cartographic(-75.59777, 40.03883)),
position : ellipsoid.cartographicToCartesian(Cesium.Cartographic.fromDegrees(-75.59777, 40.03883)),
color : { red : 1.0, blue : 0.0, green : 0.0, alpha : 1.0 },
scale : 0.5
});

billboards.add({
position : ellipsoid.cartographicDegreesToCartesian(new Cesium.Cartographic(-80.50, 35.14)),
position : ellipsoid.cartographicToCartesian(Cesium.Cartographic.fromDegrees(-80.50, 35.14)),
color : { red : 0.0, blue : 1.0, green : 0.0, alpha : 1.0 }
});

billboards.add({
position : ellipsoid.cartographicDegreesToCartesian(new Cesium.Cartographic(-80.12, 25.46)),
position : ellipsoid.cartographicToCartesian(Cesium.Cartographic.fromDegrees(-80.12, 25.46)),
color : { red : 0.0, blue : 0.0, green : 1.0, alpha : 1.0 },
scale : 2
});
Expand Down Expand Up @@ -159,31 +159,31 @@
billboards.setTextureAtlas(textureAtlas);
// Add several billboards based on the above marker definitions.
billboards.add({
position: ellipsoid.cartographicDegreesToCartesian(new Cesium.Cartographic(-75.59777, 40.03883)),
position: ellipsoid.cartographicToCartesian(Cesium.Cartographic.fromDegrees(-75.59777, 40.03883)),
imageIndex: 10,
scale: 1,
color: { red: 0, green: 1, blue: 0, alpha: 1 }
});
billboards.add({
position: ellipsoid.cartographicDegreesToCartesian(new Cesium.Cartographic(-84.0, 39.0)),
position: ellipsoid.cartographicToCartesian(Cesium.Cartographic.fromDegrees(-84.0, 39.0)),
imageIndex: 16,
scale: 1,
color: { red: 0, green: 0.5, blue: 1, alpha: 1 }
});
billboards.add({
position: ellipsoid.cartographicDegreesToCartesian(new Cesium.Cartographic(-70.0, 41.0)),
position: ellipsoid.cartographicToCartesian(Cesium.Cartographic.fromDegrees(-70.0, 41.0)),
imageIndex: 21,
scale: 1,
color: { red: 0.5, green: 0.9, blue: 1, alpha: 1 }
});
billboards.add({
position: ellipsoid.cartographicDegreesToCartesian(new Cesium.Cartographic(-73.0, 37.0)),
position: ellipsoid.cartographicToCartesian(Cesium.Cartographic.fromDegrees(-73.0, 37.0)),
imageIndex: 35,
scale: 1,
color: { red: 1, green: 0, blue: 0, alpha: 1 }
});
billboards.add({
position: ellipsoid.cartographicDegreesToCartesian(new Cesium.Cartographic(-79.0, 35.0)),
position: ellipsoid.cartographicToCartesian(Cesium.Cartographic.fromDegrees(-79.0, 35.0)),
imageIndex: 40,
scale: 1,
color: { red: 1, green: 1, blue: 0, alpha: 1 }
Expand All @@ -203,7 +203,7 @@
billboards.setTextureAtlas(textureAtlas);
billboards.add({
show : true, // default
position : ellipsoid.cartographicDegreesToCartesian(new Cesium.Cartographic(-75.59777, 40.03883)),
position : ellipsoid.cartographicToCartesian(Cesium.Cartographic.fromDegrees(-75.59777, 40.03883)),
pixelOffset : new Cesium.Cartesian2(0, 50), // default: (0, 0)
eyeOffset : new Cesium.Cartesian3(0.0, 0.0, 0.0), // default
horizontalOrigin : Cesium.HorizontalOrigin.CENTER, // default
Expand All @@ -228,11 +228,11 @@
// add() returns a Billboard object containing functions to change
// the billboard's position and appearance.
var b = billboards.add({
position : ellipsoid.cartographicDegreesToCartesian(new Cesium.Cartographic(-75.59777, 40.03883)),
position : ellipsoid.cartographicToCartesian(Cesium.Cartographic.fromDegrees(-75.59777, 40.03883)),
imageIndex : 0
});

b.setPosition(ellipsoid.cartographicDegreesToCartesian(new Cesium.Cartographic(-75.59777, 40.03883, 300000.0)));
b.setPosition(ellipsoid.cartographicToCartesian(Cesium.Cartographic.fromDegrees(-75.59777, 40.03883, 300000.0)));
b.setScale(3.0);
b.setColor({ red : 1.0, green : 1.0, blue : 1.0, alpha : 0.25 });

Expand All @@ -251,7 +251,7 @@
var textureAtlas = scene.getContext().createTextureAtlas({image : image});
billboards.setTextureAtlas(textureAtlas);

var center = ellipsoid.cartographicDegreesToCartesian(new Cesium.Cartographic(-75.59777, 40.03883));
var center = ellipsoid.cartographicToCartesian(Cesium.Cartographic.fromDegrees(-75.59777, 40.03883));
billboards.modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(center);
billboards.add({ position : new Cesium.Cartesian3(0.0, 0.0, 0.0) }); // center
billboards.add({ position : new Cesium.Cartesian3(1000000.0, 0.0, 0.0) }); // east
Expand Down
16 changes: 8 additions & 8 deletions Examples/Sandbox/CodeSnippets/Camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

this.code = function() {
flight = scene.getCamera().getControllers().addFlight({
destination : ellipsoid.cartographicDegreesToCartesian(new Cesium.Cartographic(-118.26, 34.19, 100000.0)),
destination : ellipsoid.cartographicToCartesian(Cesium.Cartographic.fromDegrees(-118.26, 34.19, 100000.0)),
duration : 4.0
});
};
Expand All @@ -28,7 +28,7 @@

Sandbox.CameraReferenceFrame = function (scene, ellipsoid, primitives) {
this.code = function() {
var center = ellipsoid.cartographicDegreesToCartesian(new Cesium.Cartographic(-75.59777, 40.03883));
var center = ellipsoid.cartographicToCartesian(Cesium.Cartographic.fromDegrees(-75.59777, 40.03883));
var transform = Cesium.Transforms.eastNorthUpToFixedFrame(center);

var spindle = scene.getCamera().getControllers().get(0);
Expand Down Expand Up @@ -88,12 +88,12 @@
scene.getCamera().viewExtent(ellipsoid, west, south, east, north);

var polyline = new Cesium.Polyline(undefined);
polyline.setPositions(ellipsoid.cartographicDegreesToCartesians([
new Cesium.Cartographic(-78, 38),
new Cesium.Cartographic(-78, 42),
new Cesium.Cartographic(-72, 42),
new Cesium.Cartographic(-72, 38),
new Cesium.Cartographic(-78, 38)
polyline.setPositions(ellipsoid.cartographicArrayToCartesianArray([
Cesium.Cartographic.fromDegrees(-78, 38),
Cesium.Cartographic.fromDegrees(-78, 42),
Cesium.Cartographic.fromDegrees(-72, 42),
Cesium.Cartographic.fromDegrees(-72, 38),
Cesium.Cartographic.fromDegrees(-78, 38)
]));
primitives.add(polyline);
};
Expand Down
16 changes: 8 additions & 8 deletions Examples/Sandbox/CodeSnippets/Circle.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
this.code = function () {
var polyline = new Cesium.Polyline(undefined);
polyline.setPositions(Cesium.Shapes.computeCircleBoundary(
ellipsoid, ellipsoid.cartographicDegreesToCartesian(
new Cesium.Cartographic(-75.59777, 40.03883)), 300000.0));
ellipsoid, ellipsoid.cartographicToCartesian(
Cesium.Cartographic.fromDegrees(-75.59777, 40.03883)), 300000.0));

primitives.add(polyline);
};
Expand All @@ -17,8 +17,8 @@
this.code = function () {
var polygon = new Cesium.Polygon(undefined);
polygon.setPositions(Cesium.Shapes.computeCircleBoundary(
ellipsoid, ellipsoid.cartographicDegreesToCartesian(
new Cesium.Cartographic(-75.59777, 40.03883)), 300000.0));
ellipsoid, ellipsoid.cartographicToCartesian(
Cesium.Cartographic.fromDegrees(-75.59777, 40.03883)), 300000.0));

primitives.add(polygon);
};
Expand All @@ -28,8 +28,8 @@
this.code = function () {
var polygon = new Cesium.Polygon(undefined);
polygon.setPositions(Cesium.Shapes.computeCircleBoundary(
ellipsoid, ellipsoid.cartographicDegreesToCartesian(
new Cesium.Cartographic(-75.59777, 40.03883)), 300000.0));
ellipsoid, ellipsoid.cartographicToCartesian(
Cesium.Cartographic.fromDegrees(-75.59777, 40.03883)), 300000.0));
// Any polygon-compatible material can be used
polygon.material = new Cesium.TieDyeMaterial(undefined);

Expand All @@ -41,8 +41,8 @@
this.code = function () {
var polygon = new Cesium.Polygon(undefined);
polygon.setPositions(Cesium.Shapes.computeEllipseBoundary(
ellipsoid, ellipsoid.cartographicDegreesToCartesian(
new Cesium.Cartographic(-75.59777, 40.03883)), 500000.0, 300000.0, Cesium.Math.toRadians(60)));
ellipsoid, ellipsoid.cartographicToCartesian(
Cesium.Cartographic.fromDegrees(-75.59777, 40.03883)), 500000.0, 300000.0, Cesium.Math.toRadians(60)));

primitives.add(polygon);
};
Expand Down
30 changes: 15 additions & 15 deletions Examples/Sandbox/CodeSnippets/Composite.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@

// Setup code
var redPolygon = new Cesium.Polygon(undefined);
redPolygon.setPositions(ellipsoid.cartographicDegreesToCartesians([
new Cesium.Cartographic(-70.0, 30.0),
new Cesium.Cartographic(-60.0, 30.0),
new Cesium.Cartographic(-60.0, 40.0),
new Cesium.Cartographic(-70.0, 40.0)
redPolygon.setPositions(ellipsoid.cartographicArrayToCartesianArray([
Cesium.Cartographic.fromDegrees(-70.0, 30.0),
Cesium.Cartographic.fromDegrees(-60.0, 30.0),
Cesium.Cartographic.fromDegrees(-60.0, 40.0),
Cesium.Cartographic.fromDegrees(-70.0, 40.0)
]));
redPolygon.material.color = {
red : 1.0,
Expand All @@ -34,11 +34,11 @@
};

var bluePolygon = new Cesium.Polygon(undefined);
bluePolygon.setPositions(ellipsoid.cartographicDegreesToCartesians([
new Cesium.Cartographic(-75.0, 34.0),
new Cesium.Cartographic(-63.0, 34.0),
new Cesium.Cartographic(-63.0, 40.0),
new Cesium.Cartographic(-75.0, 40.0)
bluePolygon.setPositions(ellipsoid.cartographicArrayToCartesianArray([
Cesium.Cartographic.fromDegrees(-75.0, 34.0),
Cesium.Cartographic.fromDegrees(-63.0, 34.0),
Cesium.Cartographic.fromDegrees(-63.0, 40.0),
Cesium.Cartographic.fromDegrees(-75.0, 40.0)
]));
bluePolygon.material.color = {
red : 0.0,
Expand All @@ -48,11 +48,11 @@
};

var greenPolygon = new Cesium.Polygon(undefined);
greenPolygon.setPositions(ellipsoid.cartographicDegreesToCartesians([
new Cesium.Cartographic(-67.0, 36.0),
new Cesium.Cartographic(-55.0, 36.0),
new Cesium.Cartographic(-55.0, 30.0),
new Cesium.Cartographic(-67.0, 30.0)
greenPolygon.setPositions(ellipsoid.cartographicArrayToCartesianArray([
Cesium.Cartographic.fromDegrees(-67.0, 36.0),
Cesium.Cartographic.fromDegrees(-55.0, 36.0),
Cesium.Cartographic.fromDegrees(-55.0, 30.0),
Cesium.Cartographic.fromDegrees(-67.0, 30.0)
]));
greenPolygon.material.color = {
red : 0.0,
Expand Down
16 changes: 8 additions & 8 deletions Examples/Sandbox/CodeSnippets/Label.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
this.code = function () {
var labels = new Cesium.LabelCollection(undefined);
labels.add({
position : ellipsoid.cartographicDegreesToCartesian(new Cesium.Cartographic(-75.10, 39.57)),
position : ellipsoid.cartographicToCartesian(Cesium.Cartographic.fromDegrees(-75.10, 39.57)),
text : 'Philadelphia'
});

Expand All @@ -18,15 +18,15 @@
this.code = function () {
var labels = new Cesium.LabelCollection(undefined);
labels.add({
position : ellipsoid.cartographicDegreesToCartesian(new Cesium.Cartographic(-75.10, 39.57)),
position : ellipsoid.cartographicToCartesian(Cesium.Cartographic.fromDegrees(-75.10, 39.57)),
text : 'Philadelphia'
});
labels.add({
position : ellipsoid.cartographicDegreesToCartesian(new Cesium.Cartographic(-80.50, 35.14)),
position : ellipsoid.cartographicToCartesian(Cesium.Cartographic.fromDegrees(-80.50, 35.14)),
text : 'Charlotte'
});
labels.add({
position : ellipsoid.cartographicDegreesToCartesian(new Cesium.Cartographic(-80.12, 25.46)),
position : ellipsoid.cartographicToCartesian(Cesium.Cartographic.fromDegrees(-80.12, 25.46)),
text : 'Miami'
});

Expand All @@ -38,7 +38,7 @@
this.code = function () {
var labels = new Cesium.LabelCollection(undefined);
labels.add({
position : ellipsoid.cartographicDegreesToCartesian(new Cesium.Cartographic(-75.10, 39.57)),
position : ellipsoid.cartographicToCartesian(Cesium.Cartographic.fromDegrees(-75.10, 39.57)),
text : 'Philadelphia',
// CSS font-family
font : '36px Helvetica',
Expand All @@ -55,11 +55,11 @@
this.code = function () {
var labels = new Cesium.LabelCollection(undefined);
var l = labels.add({
position : ellipsoid.cartographicDegreesToCartesian(new Cesium.Cartographic(-75.10, 39.57)),
position : ellipsoid.cartographicToCartesian(Cesium.Cartographic.fromDegrees(-75.10, 39.57)),
text : 'Philadelphia'
});

l.setPosition(ellipsoid.cartographicDegreesToCartesian(new Cesium.Cartographic(-75.10, 39.57, 300000.0)));
l.setPosition(ellipsoid.cartographicToCartesian(Cesium.Cartographic.fromDegrees(-75.10, 39.57, 300000.0)));
l.setScale(2.0);

primitives.add(labels);
Expand All @@ -68,7 +68,7 @@

Sandbox.LabelReferenceFrame = function (scene, ellipsoid, primitives) {
this.code = function () {
var center = ellipsoid.cartographicDegreesToCartesian(new Cesium.Cartographic(-75.59777, 40.03883));
var center = ellipsoid.cartographicToCartesian(Cesium.Cartographic.fromDegrees(-75.59777, 40.03883));

var labels = new Cesium.LabelCollection(undefined);
labels.modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(center);
Expand Down
Loading

0 comments on commit c1e68f1

Please sign in to comment.