-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added a new transformation and a sandCastle example
- Loading branch information
Showing
6 changed files
with
662 additions
and
198 deletions.
There are no files selected for viewing
231 changes: 231 additions & 0 deletions
231
Apps/Sandcastle/gallery/development/HeadingPitchRoll.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,231 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no"> | ||
<meta name="description" content="Create 3D models using glTF."> | ||
<meta name="cesium-sandcastle-labels" content="Development"> | ||
<title>Cesium Demo</title> | ||
<script type="text/javascript" src="../Sandcastle-header.js"></script> | ||
<script type="text/javascript" src="../../../ThirdParty/requirejs-2.1.20/require.js"></script> | ||
<script type="text/javascript"> | ||
require.config({ | ||
baseUrl: '../../../Source', | ||
waitSeconds: 60 | ||
}); | ||
</script> | ||
</head> | ||
|
||
<body class="sandcastle-loading" data-sandcastle-bucket="bucket-requirejs.html"> | ||
<style> | ||
@import url(../templates/bucket.css); | ||
</style> | ||
<div id="cesiumContainer" class="fullSize"></div> | ||
<div id="loadingOverlay"> | ||
<h1>Loading...</h1></div> | ||
<div id="toolbar"> | ||
<table> | ||
<tbody> | ||
<tr> | ||
<td>Heading: <span id='heading'></span>°</td> | ||
</tr> | ||
<tr> | ||
<td>← to left/→ to right</td> | ||
</tr> | ||
<tr> | ||
<td>Pitch: <span id='pitch'></span>°</td> | ||
</tr> | ||
<tr> | ||
<td>↑ to up/↓ to down</td> | ||
</tr> | ||
<tr> | ||
<td>roll: <span id='roll'></span>°</td> | ||
</tr> | ||
<tr> | ||
<td>← + ⇧ left/→ + ⇧ right</td> | ||
</tr> | ||
<tr> | ||
<td>Speed: <span id='speed'></span>m/s</td> | ||
</tr> | ||
<tr> | ||
<td>↑ + ⇧ to speed up/↓ + ⇧ to speed down</td> | ||
</tr> | ||
<tr> | ||
<td>following aircraft | ||
<input id='fromBehind' type='checkbox'></input> | ||
</td> | ||
</tr> | ||
|
||
</tbody> | ||
</table> | ||
</div> | ||
<script id="cesium_sandcastle_script"> | ||
function startup(Cesium) { | ||
'use strict'; | ||
//Sandcastle_Begin | ||
var viewer = new Cesium.Viewer('cesiumContainer'); | ||
var scene = viewer.scene; | ||
// viewer.extend(Cesium.viewerCesiumInspectorMixin); | ||
|
||
var pathPosition = new Cesium.SampledPositionProperty(); | ||
var entityPath = viewer.entities.add({ | ||
position: pathPosition, | ||
name: 'path', | ||
path: { | ||
show: true, | ||
leadTime: 0, | ||
trailTime: 60, | ||
width: 10, | ||
resolution: 1, | ||
material: new Cesium.PolylineGlowMaterialProperty({ | ||
glowPower: 0.3, | ||
color: Cesium.Color.PALEGOLDENROD | ||
}) | ||
} | ||
}); | ||
|
||
var camera = viewer.camera; | ||
var controller = scene.screenSpaceCameraController; | ||
var r = 0; | ||
var center = new Cesium.Cartesian3(); | ||
|
||
var hpRoll = new Cesium.HeadingPitchRoll(); | ||
var hpRange = new Cesium.HeadingPitchRange(); | ||
var speed = 100.0; | ||
|
||
var position = Cesium.Cartesian3.fromDegrees(-123.0744619, 44.0503706, 5000.0); | ||
var speedVector = new Cesium.Cartesian3(); | ||
|
||
var planePrimitive = scene.primitives.add(Cesium.Model.fromGltf({ | ||
url: '../../SampleData/models/CesiumAir/Cesium_Air.glb', | ||
modelMatrix: Cesium.Transforms.aircraftHeadingPitchRollToFixedFrame(position, hpRoll), | ||
minimumPixelSize: 128 | ||
})); | ||
|
||
planePrimitive.readyPromise.then(function(model) { | ||
// Play and loop all animations at half-speed | ||
model.activeAnimations.addAll({ | ||
speedup: 0.5, | ||
loop: Cesium.ModelAnimationLoop.REPEAT | ||
}); | ||
|
||
// Zoom to model | ||
r = 2.0 * Math.max(model.boundingSphere.radius, camera.frustum.near); | ||
controller.minimumZoomDistance = r * 0.5; | ||
Cesium.Matrix4.multiplyByPoint(model.modelMatrix, model.boundingSphere.center, center); | ||
var heading = Cesium.Math.toRadians(230.0); | ||
var pitch = Cesium.Math.toRadians(-20.0); | ||
hpRange.heading = heading; | ||
hpRange.pitch = pitch; | ||
hpRange.range = r * 50.0; | ||
camera.lookAt(center, hpRange); | ||
update(); | ||
}).otherwise(function(error) { | ||
window.alert(error); | ||
}); | ||
|
||
document.addEventListener("keypress", function(e) { | ||
switch (e.key) { | ||
case 'ArrowDown': | ||
if (e.shiftKey) { | ||
// speed down | ||
speed -= 10; | ||
if (speed < 10) { | ||
speed = 10; | ||
} | ||
} else { | ||
// pitch down until | ||
hpRoll.pitch -= Cesium.Math.RADIANS_PER_DEGREE; | ||
if (hpRoll.pitch < -Cesium.Math.TWO_PI) { | ||
hpRoll.pitch += Cesium.Math.TWO_PI; | ||
} | ||
} | ||
break; | ||
case 'ArrowUp': | ||
if (e.shiftKey) { | ||
// speed up | ||
speed += 10; | ||
if (speed > 340) { | ||
speed = 340; | ||
} | ||
} else { | ||
// pitch up until Math.PI/2 | ||
hpRoll.pitch += Cesium.Math.RADIANS_PER_DEGREE; | ||
if (hpRoll.pitch > Cesium.Math.TWO_PI) { | ||
hpRoll.pitch -= Cesium.Math.TWO_PI; | ||
} | ||
} | ||
break; | ||
case 'ArrowRight': | ||
if (e.shiftKey) { | ||
// roll right until Math.PI/2 | ||
hpRoll.roll += Cesium.Math.RADIANS_PER_DEGREE; | ||
if (hpRoll.roll > Cesium.Math.TWO_PI) { | ||
hpRoll.roll -= Cesium.Math.TWO_PI; | ||
} | ||
} else { | ||
// turn right | ||
hpRoll.heading += Cesium.Math.RADIANS_PER_DEGREE; | ||
if (hpRoll.heading > Cesium.Math.TWO_PI) { | ||
hpRoll.heading -= Cesium.Math.TWO_PI; | ||
} | ||
} | ||
break; | ||
case 'ArrowLeft': | ||
if (e.shiftKey) { | ||
// roll left until | ||
hpRoll.roll -= Cesium.Math.RADIANS_PER_DEGREE; | ||
if (hpRoll.roll < 0.0) { | ||
hpRoll.roll += Cesium.Math.TWO_PI; | ||
} | ||
} else { | ||
// turn left | ||
hpRoll.heading -= Cesium.Math.RADIANS_PER_DEGREE; | ||
if (hpRoll.heading < 0.0) { | ||
hpRoll.heading += Cesium.Math.TWO_PI; | ||
} | ||
} | ||
break; | ||
default: | ||
} | ||
}); | ||
|
||
var headingSpan = document.getElementById('heading'); | ||
var pitchSpan = document.getElementById('pitch'); | ||
var rollSpan = document.getElementById('roll'); | ||
var speedSpan = document.getElementById('speed'); | ||
|
||
function update() { | ||
headingSpan.innerHTML = Cesium.Math.toDegrees(hpRoll.heading).toFixed(1); | ||
pitchSpan.innerHTML = Cesium.Math.toDegrees(hpRoll.pitch).toFixed(1); | ||
rollSpan.innerHTML = Cesium.Math.toDegrees(hpRoll.roll).toFixed(1); | ||
speedSpan.innerHTML = speed.toFixed(1); | ||
|
||
speedVector = Cesium.Cartesian3.multiplyByScalar(Cesium.Cartesian3.UNIT_X, speed / 10, speedVector); | ||
position = Cesium.Matrix4.multiplyByPoint(planePrimitive.modelMatrix, speedVector, position); | ||
pathPosition.addSample(Cesium.JulianDate.now(), position); | ||
Cesium.Transforms.aircraftHeadingPitchRollToFixedFrame(position, hpRoll,undefined,planePrimitive.modelMatrix); | ||
|
||
if (document.getElementById('fromBehind').checked) { | ||
// Zoom to model | ||
Cesium.Matrix4.multiplyByPoint(planePrimitive.modelMatrix, planePrimitive.boundingSphere.center, center); | ||
hpRange.heading = hpRoll.heading; | ||
hpRange.pitch = hpRoll.pitch; | ||
camera.lookAt(center, hpRange); | ||
} | ||
setTimeout(update, 100); | ||
} | ||
//Sandcastle_End | ||
Sandcastle.finishedLoading(); | ||
} | ||
if (typeof Cesium !== "undefined") { | ||
startup(Cesium); | ||
} else if (typeof require === "function") { | ||
require(["Cesium"], startup); | ||
} | ||
</script> | ||
</body> | ||
|
||
</html> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.