Skip to content

Commit

Permalink
Merge pull request #24 from Larcius/master
Browse files Browse the repository at this point in the history
Handling tracked entities
  • Loading branch information
alberto-acevedo authored Jul 14, 2016
2 parents 3366f0a + 2d0340b commit e5a0cef
Show file tree
Hide file tree
Showing 22 changed files with 1,842 additions and 719 deletions.
476 changes: 465 additions & 11 deletions Examples/Build/amd.min.js

Large diffs are not rendered by default.

134 changes: 134 additions & 0 deletions Examples/Source/SpirographPositionProperty.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/**
* Created by G.Cordes on 01.06.16.
*/

(function (Cesium) {
/**
* A position property that simulates a spirograph
* @constructor
*
* @param {Cesium.Cartographic} center The center of the spirograph
* @param {Number} radiusMedian The radius of the median circle
* @param {Number} radiusSubCircle the maximum distance to the median circle
* @param {Number} durationMedianCircle The duration in milliseconds to orbit the median circle
* @param {Number} durationSubCircle The duration in milliseconds to orbit the sub circle
* @param {Cesium.Ellipsoid} [ellipsoid=Cesium.Ellipsoid.WGS84] The ellipsoid to convert cartographic to cartesian
*/
var SpirographPositionProperty = function (center, radiusMedian, radiusSubCircle, durationMedianCircle, durationSubCircle, ellipsoid) {
this._center = center;
this._radiusMedian = radiusMedian;
this._radiusSubCircle = radiusSubCircle;

this._durationMedianCircle = durationMedianCircle;
this._durationSubCircle = durationSubCircle;

if (!Cesium.defined(ellipsoid)) {
ellipsoid = Cesium.Ellipsoid.WGS84;
}
this._ellipsoid = ellipsoid;

this._definitionChanged = new Cesium.Event();
};

Cesium.defineProperties(SpirographPositionProperty.prototype, {
/**
* Gets a value indicating if this property is constant. A property is considered
* constant if getValue always returns the same result for the current definition.
* @memberof PositionProperty.prototype
*
* @type {Boolean}
* @readonly
*/
isConstant: {
get: function () {
return this._radiusMedian == 0 && this._radiusSubCircle == 0;
}
},
/**
* Gets the event that is raised whenever the definition of this property changes.
* The definition is considered to have changed if a call to getValue would return
* a different result for the same time.
* @memberof PositionProperty.prototype
*
* @type {Event}
* @readonly
*/
definitionChanged: {
get: function () {
return this._definitionChanged;
}
},
/**
* Gets the reference frame that the position is defined in.
* @memberof PositionProperty.prototype
* @type {ReferenceFrame}
*/
referenceFrame: {
get: function () {
return Cesium.ReferenceFrame.FIXED;
}
}
});

/**
* Gets the value of the property at the provided time in the fixed frame.
* @function
*
* @param {JulianDate} time The time for which to retrieve the value.
* @param {Cartesian3} [result] The object to store the value into, if omitted, a new instance is created and returned.
* @returns {Cartesian3} The modified result parameter or a new instance if the result parameter was not supplied.
*/
SpirographPositionProperty.prototype.getValue = function (time, result) {
return this.getValueInReferenceFrame(time, Cesium.ReferenceFrame.FIXED, result);
};

var cartographicScratch = new Cesium.Cartographic();

/**
* Gets the value of the property at the provided time and in the provided reference frame.
* @function
*
* @param {JulianDate} time The time for which to retrieve the value.
* @param {ReferenceFrame} referenceFrame The desired referenceFrame of the result.
* @param {Cartesian3} [result] The object to store the value into, if omitted, a new instance is created and returned.
* @returns {Cartesian3} The modified result parameter or a new instance if the result parameter was not supplied.
*/
SpirographPositionProperty.prototype.getValueInReferenceFrame = function (time, referenceFrame, result) {
var milliseconds = Cesium.JulianDate.toDate(time).getTime();

var radius = this._radiusMedian + this._radiusSubCircle * Math.sin(2 * Math.PI * (milliseconds / this._durationSubCircle));

cartographicScratch.latitude = this._center.latitude + radius * Math.cos(2 * Math.PI * (milliseconds / this._durationMedianCircle));
cartographicScratch.longitude = this._center.longitude + radius * Math.sin(2 * Math.PI * (milliseconds / this._durationMedianCircle));
cartographicScratch.height = this._center.height;

result = this._ellipsoid.cartographicToCartesian(cartographicScratch, result);

if (referenceFrame == Cesium.ReferenceFrame.FIXED) {
return result;
}

return Cesium.PositionProperty.convertToReferenceFrame(time, result, Cesium.ReferenceFrame.FIXED, referenceFrame, result);
};

/**
* Compares this property to the provided property and returns
* <code>true</code> if they are equal, <code>false</code> otherwise.
* @function
*
* @param {Property} [other] The other property.
* @returns {Boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
*/
SpirographPositionProperty.prototype.equals = function (other) {
return other instanceof SpirographPositionProperty
&& this._center.equals(other._center)
&& this._radiusMedian == other._radiusMedian
&& this._radiusSubCircle == other._radiusSubCircle
&& this._durationMedianCircle == other._durationMedianCircle
&& this._durationSubCircle == other._durationSubCircle
&& this._ellipsoid.equals(other._ellipsoid);
};

Cesium.SpirographPositionProperty = SpirographPositionProperty;

})(Cesium);
137 changes: 137 additions & 0 deletions Examples/Source/SpirographPositionProperty_amd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/**
* Created by G.Cordes on 01.06.16.
*/

define([
'Cesium/Cesium'
], function (Cesium) {
"use strict";

/**
* A position property that simulates a spirograph
* @constructor
*
* @param {Cesium.Cartographic} center The center of the spirograph
* @param {Number} radiusMedian The radius of the median circle
* @param {Number} radiusSubCircle the maximum distance to the median circle
* @param {Number} durationMedianCircle The duration in milliseconds to orbit the median circle
* @param {Number} durationSubCircle The duration in milliseconds to orbit the sub circle
* @param {Cesium.Ellipsoid} [ellipsoid=Cesium.Ellipsoid.WGS84] The ellipsoid to convert cartographic to cartesian
*/
var SpirographPositionProperty = function(center, radiusMedian, radiusSubCircle, durationMedianCircle, durationSubCircle, ellipsoid) {
this._center = center;
this._radiusMedian = radiusMedian;
this._radiusSubCircle = radiusSubCircle;

this._durationMedianCircle = durationMedianCircle;
this._durationSubCircle = durationSubCircle;

if(!Cesium.defined(ellipsoid)) {
ellipsoid = Cesium.Ellipsoid.WGS84;
}
this._ellipsoid = ellipsoid;

this._definitionChanged = new Cesium.Event();
};

Cesium.defineProperties(SpirographPositionProperty.prototype, {
/**
* Gets a value indicating if this property is constant. A property is considered
* constant if getValue always returns the same result for the current definition.
* @memberof PositionProperty.prototype
*
* @type {Boolean}
* @readonly
*/
isConstant : {
get : function() {
return this._radiusMedian == 0 && this._radiusSubCircle == 0;
}
},
/**
* Gets the event that is raised whenever the definition of this property changes.
* The definition is considered to have changed if a call to getValue would return
* a different result for the same time.
* @memberof PositionProperty.prototype
*
* @type {Event}
* @readonly
*/
definitionChanged : {
get : function() {
return this._definitionChanged;
}
},
/**
* Gets the reference frame that the position is defined in.
* @memberof PositionProperty.prototype
* @type {ReferenceFrame}
*/
referenceFrame : {
get : function() {
return Cesium.ReferenceFrame.FIXED;
}
}
});

/**
* Gets the value of the property at the provided time in the fixed frame.
* @function
*
* @param {JulianDate} time The time for which to retrieve the value.
* @param {Cartesian3} [result] The object to store the value into, if omitted, a new instance is created and returned.
* @returns {Cartesian3} The modified result parameter or a new instance if the result parameter was not supplied.
*/
SpirographPositionProperty.prototype.getValue = function(time, result) {
return this.getValueInReferenceFrame(time, Cesium.ReferenceFrame.FIXED, result);
};

var cartographicScratch = new Cesium.Cartographic();

/**
* Gets the value of the property at the provided time and in the provided reference frame.
* @function
*
* @param {JulianDate} time The time for which to retrieve the value.
* @param {ReferenceFrame} referenceFrame The desired referenceFrame of the result.
* @param {Cartesian3} [result] The object to store the value into, if omitted, a new instance is created and returned.
* @returns {Cartesian3} The modified result parameter or a new instance if the result parameter was not supplied.
*/
SpirographPositionProperty.prototype.getValueInReferenceFrame = function(time, referenceFrame, result) {
var milliseconds = Cesium.JulianDate.toDate(time).getTime();

var radius = this._radiusMedian + this._radiusSubCircle * Math.sin(2 * Math.PI * (milliseconds / this._durationSubCircle));

cartographicScratch.latitude = this._center.latitude + radius * Math.cos(2 * Math.PI * (milliseconds / this._durationMedianCircle));
cartographicScratch.longitude = this._center.longitude + radius * Math.sin(2 * Math.PI * (milliseconds / this._durationMedianCircle));
cartographicScratch.height = this._center.height;

result = this._ellipsoid.cartographicToCartesian(cartographicScratch, result);

if(referenceFrame == Cesium.ReferenceFrame.FIXED) {
return result;
}

return Cesium.PositionProperty.convertToReferenceFrame(time, result, Cesium.ReferenceFrame.FIXED, referenceFrame, result);
};

/**
* Compares this property to the provided property and returns
* <code>true</code> if they are equal, <code>false</code> otherwise.
* @function
*
* @param {Property} [other] The other property.
* @returns {Boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
*/
SpirographPositionProperty.prototype.equals = function(other) {
return other instanceof SpirographPositionProperty
&& this._center.equals(other._center)
&& this._radiusMedian == other._radiusMedian
&& this._radiusSubCircle == other._radiusSubCircle
&& this._durationMedianCircle == other._durationMedianCircle
&& this._durationSubCircle == other._durationSubCircle
&& this._ellipsoid.equals(other._ellipsoid);
};

return SpirographPositionProperty;
});
40 changes: 18 additions & 22 deletions Examples/Source/amd/main.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,39 @@
require([
'Cesium/Core/Cartesian3',
'Cesium/Core/Math',
'Cesium/Core/Transforms',
'Cesium/Widgets/Viewer/Viewer',
'Cesium/Cesium',
'Source/SpirographPositionProperty_amd',
'viewerCesiumNavigationMixin'
], function(
Cartesian3,
CesiumMath,
Transforms,
Viewer,
Cesium,
SpirographPositionProperty,
viewerCesiumNavigationMixin) {
"use strict";

var cesiumViewer = new Viewer('cesiumContainer');
var cesiumViewer = new Cesium.Viewer('cesiumContainer');

// extend our view by the cesium navigaton mixin
// extend our view by the cesium navigation mixin
cesiumViewer.extend(viewerCesiumNavigationMixin, {});
// you can access the cesium navigation by cesiumViewer.cesiumNavigation or cesiumViewer.cesiumWidget.cesiumNavigation

// just some entities
function createModel(url, longitude, latitude, height) {
var position = Cartesian3.fromDegrees(longitude, latitude, height);
var heading = CesiumMath.toRadians(135);
var pitch = 0;
var roll = 0;
var orientation = Transforms.headingPitchRollQuaternion(position, heading, pitch, roll);
function createSpirographEntity(url, longitude, latitude, height, radiusMedian, radiusSubCircle,
durationMedianCircle, durationSubCircle) {
var centerPosition = Cesium.Cartographic.fromDegrees(longitude, latitude, height);
var spirographPositionProperty = new SpirographPositionProperty(centerPosition, radiusMedian, radiusSubCircle,
durationMedianCircle, durationSubCircle, cesiumViewer.scene.globe.ellipsoid);

var entity = cesiumViewer.entities.add({
cesiumViewer.entities.add({
name : url,
description: 'It is supposed to have a useful desciption here<br />but instead there is just a placeholder to get a larger info box',
position : position,
orientation : orientation,
position: spirographPositionProperty,
orientation: new Cesium.VelocityOrientationProperty(spirographPositionProperty, cesiumViewer.scene.globe.ellipsoid),
model : {
uri : url,
minimumPixelSize : 96
}
});
}

createModel('models/Cesium_Air.glb', -100, 44, 10000.0);
createModel('models/Cesium_Ground.glb', -122, 45, 0);
createSpirographEntity('models/Cesium_Air.glb', -100, 44, 10000.0,
Cesium.Math.toRadians(0.5), Cesium.Math.toRadians(2), 1e6, 2e5);
createSpirographEntity('models/Cesium_Ground.glb', -122, 45, 0,
Cesium.Math.toRadians(0.1), Cesium.Math.toRadians(1), 5e6, 7e5);
});
2 changes: 1 addition & 1 deletion Examples/Source/mainConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ requirejs.config({
paths: {
// IMPORTANT: this path has to be set because
// viewerCesiumNavigationMixin uses 'Cesium/...' for dependencies
Cesium: "empty:",
Cesium: "../node_modules/cesium/Source",
viewerCesiumNavigationMixin: "../dist/amd/viewerCesiumNavigationMixin.min"
}
});
11 changes: 2 additions & 9 deletions Examples/amd.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,8 @@
<head>
<title>Cesium-Navigation Example (using requirejs.optimize)</title>
<script type="text/javascript" src="node_modules/requirejs/require.js"></script>
<script type="text/javascript">
requirejs.config({
paths: {
Cesium: "node_modules/cesium/Source"
}
});
</script>
<style>
@import url(node_modules/cesium/Source/Widgets/widgets.css);
@import url(node_modules/cesium/Build/Cesium/Widgets/widgets.css);
html, body, #cesiumContainer {
width: 100%; height: 100%; margin: 0; padding: 0; overflow: hidden;
}
Expand All @@ -21,7 +14,7 @@
<div id="cesiumContainer"></div>
<!-- This file was built with nodejs and requirejs.optimize -->
<!-- The main file was Source/amd/main.js -->
<!-- To build this file on your own, simply run `node build.js` (first you might need to run `npm install` once) -->
<!-- To build this file on your own, simply run `node build.js` (for the first time you might need to run `npm install`) -->
<script type="text/javascript" src="Build/amd.min.js"></script>

<script type="text/javascript">
Expand Down
Loading

0 comments on commit e5a0cef

Please sign in to comment.