|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | + <meta charset="utf-8"> |
| 5 | + <meta http-equiv="X-UA-Compatible" content="IE=edge"> |
| 6 | + <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no"> |
| 7 | + <meta name="description" content="Use localFrameToFixedFrameGenerator for adequate rotation."> |
| 8 | + <meta name="cesium-sandcastle-labels" content="Tutorials"> |
| 9 | + <title>Cesium Demo</title> |
| 10 | + <script type="text/javascript" src="../Sandcastle-header.js"></script> |
| 11 | + <script type="text/javascript" src="../../../ThirdParty/requirejs-2.1.20/require.js"></script> |
| 12 | + <script type="text/javascript"> |
| 13 | + require.config({ |
| 14 | + baseUrl : '../../../Source', |
| 15 | + waitSeconds : 60 |
| 16 | + }); |
| 17 | + </script> |
| 18 | +</head> |
| 19 | +<body class="sandcastle-loading" data-sandcastle-bucket="bucket-requirejs.html"> |
| 20 | +<style> |
| 21 | + @import url(../templates/bucket.css); |
| 22 | + </style> |
| 23 | + <div id="cesiumContainer" class="fullSize"></div> |
| 24 | + <div id="loadingOverlay"> |
| 25 | + <h1>Loading...</h1> |
| 26 | + </div> |
| 27 | + <div id="toolbar"> |
| 28 | + <table> |
| 29 | + <tbody> |
| 30 | + <tr> |
| 31 | + <td>Click on the 3D window then use the keyboard to change settings.</td> |
| 32 | + </tr> |
| 33 | + <tr> |
| 34 | + <td>Heading: <span id="heading"></span>°</td> |
| 35 | + </tr> |
| 36 | + <tr> |
| 37 | + <td>← to left/→ to right</td> |
| 38 | + </tr> |
| 39 | + <tr> |
| 40 | + <td>Pitch: <span id="pitch"></span>°</td> |
| 41 | + </tr> |
| 42 | + <tr> |
| 43 | + <td>↑ to up/↓ to down</td> |
| 44 | + </tr> |
| 45 | + <tr> |
| 46 | + <td>roll: <span id="roll"></span>°</td> |
| 47 | + </tr> |
| 48 | + <tr> |
| 49 | + <td>← + ⇧ left/→ + ⇧ right</td> |
| 50 | + </tr> |
| 51 | + </tbody> |
| 52 | + </table> |
| 53 | + </div> |
| 54 | + <script id="cesium_sandcastle_script"> |
| 55 | +function startup(Cesium) { |
| 56 | + 'use strict'; |
| 57 | +//Sandcastle_Begin |
| 58 | +var viewer = new Cesium.Viewer('cesiumContainer'); |
| 59 | +var canvas = viewer.canvas; |
| 60 | +canvas.setAttribute('tabindex', '0'); // needed to put focus on the canvas |
| 61 | +canvas.addEventListener('click', function() { |
| 62 | + canvas.focus(); |
| 63 | +}); |
| 64 | +canvas.focus(); |
| 65 | + |
| 66 | +var scene = viewer.scene; |
| 67 | +var camera = viewer.camera; |
| 68 | +var controller = scene.screenSpaceCameraController; |
| 69 | +var r = 0; |
| 70 | +var center = new Cesium.Cartesian3(); |
| 71 | + |
| 72 | +var hpRoll = new Cesium.HeadingPitchRoll(); |
| 73 | +var hpRange = new Cesium.HeadingPitchRange(); |
| 74 | +var deltaRadians = Cesium.Math.toRadians(1.0); |
| 75 | + |
| 76 | +var localFrames = [ |
| 77 | + { |
| 78 | + pos : Cesium.Cartesian3.fromDegrees(-123.075, 44.045000, 5000.0), |
| 79 | + converter : Cesium.Transforms.eastNorthUpToFixedFrame, |
| 80 | + comments : 'Classical East North Up\nlocal Frame' |
| 81 | + }, |
| 82 | + { |
| 83 | + pos : Cesium.Cartesian3.fromDegrees(-123.075, 44.050000, 5500.0), |
| 84 | + converter : Cesium.Transforms.localFrameToFixedFrameGenerator('north', 'west'), |
| 85 | + comments : 'North West Up\nlocal Frame' |
| 86 | + }, |
| 87 | + { |
| 88 | + pos : Cesium.Cartesian3.fromDegrees(-123.075, 44.040000, 4500.0), |
| 89 | + converter : Cesium.Transforms.localFrameToFixedFrameGenerator('south', 'up'), |
| 90 | + comments : 'South Up West\nlocal Frame' |
| 91 | + }, |
| 92 | + { |
| 93 | + pos : Cesium.Cartesian3.fromDegrees(-123.075, 44.050000, 4500.0), |
| 94 | + converter : Cesium.Transforms.localFrameToFixedFrameGenerator('up', 'east'), |
| 95 | + comments : 'Up East North\nlocal Frame' |
| 96 | + }, |
| 97 | + { |
| 98 | + pos : Cesium.Cartesian3.fromDegrees(-123.075, 44.040000, 5500.0), |
| 99 | + converter : Cesium.Transforms.localFrameToFixedFrameGenerator('down', 'east'), |
| 100 | + comments : 'Down East South\nlocal Frame' |
| 101 | + }, |
| 102 | +]; |
| 103 | + |
| 104 | +var primitives = []; |
| 105 | +var hprRollZero = new Cesium.HeadingPitchRoll(); |
| 106 | + |
| 107 | +for (var i = 0; i < localFrames.length; i++) { |
| 108 | + var position = localFrames[i].pos; |
| 109 | + var converter = localFrames[i].converter; |
| 110 | + var comments = localFrames[i].comments; |
| 111 | + var planePrimitive = scene.primitives.add(Cesium.Model.fromGltf({ |
| 112 | + url : '../../SampleData/models/CesiumAir/Cesium_Air.glb', |
| 113 | + modelMatrix : Cesium.Transforms.headingPitchRollToFixedFrame(position, hpRoll, Cesium.Ellipsoid.WGS84, converter), |
| 114 | + minimumPixelSize : 128 |
| 115 | + })); |
| 116 | + |
| 117 | + primitives.push({primitive : planePrimitive, converter : converter, position : position}); |
| 118 | + var modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(position, hprRollZero, Cesium.Ellipsoid.WGS84, converter); |
| 119 | + scene.primitives.add(new Cesium.DebugModelMatrixPrimitive({ |
| 120 | + modelMatrix : modelMatrix, |
| 121 | + length : 300.0, |
| 122 | + width : 10.0 |
| 123 | + })); |
| 124 | + |
| 125 | + var positionLabel = position.clone(); |
| 126 | + positionLabel.z = position.z + 300.0; |
| 127 | + viewer.entities.add({ |
| 128 | + position : positionLabel, |
| 129 | + label : { |
| 130 | + text : comments, |
| 131 | + font : '24px Helvetica', |
| 132 | + fillColor : Cesium.Color.SKYBLUE, |
| 133 | + outlineColor : Cesium.Color.BLACK, |
| 134 | + outlineWidth : 2, |
| 135 | + style : Cesium.LabelStyle.FILL_AND_OUTLINE, |
| 136 | + verticalOrigin : Cesium.VerticalOrigin.CENTER, |
| 137 | + HorizontalOrigin : Cesium.HorizontalOrigin.RIGHT |
| 138 | + } |
| 139 | + }); |
| 140 | +} |
| 141 | + |
| 142 | +primitives[0].primitive.readyPromise.then(function(model) { |
| 143 | + // Play and loop all animations at half-speed |
| 144 | + model.activeAnimations.addAll({ |
| 145 | + speedup : 0.5, |
| 146 | + loop : Cesium.ModelAnimationLoop.REPEAT |
| 147 | + }); |
| 148 | + |
| 149 | + // Zoom to model |
| 150 | + r = 2.0 * Math.max(model.boundingSphere.radius, camera.frustum.near); |
| 151 | + controller.minimumZoomDistance = r * 0.5; |
| 152 | + Cesium.Matrix4.multiplyByPoint(model.modelMatrix, model.boundingSphere.center, center); |
| 153 | + var heading = Cesium.Math.toRadians(90.0); |
| 154 | + var pitch = Cesium.Math.toRadians(0.0); |
| 155 | + hpRange.heading = heading; |
| 156 | + hpRange.pitch = pitch; |
| 157 | + hpRange.range = r * 100.0; |
| 158 | + camera.lookAt(center, hpRange); |
| 159 | +}); |
| 160 | + |
| 161 | +document.addEventListener('keydown', function(e) { |
| 162 | + switch (e.keyCode) { |
| 163 | + case 40: |
| 164 | + // pitch down |
| 165 | + hpRoll.pitch -= deltaRadians; |
| 166 | + if (hpRoll.pitch < -Cesium.Math.TWO_PI) { |
| 167 | + hpRoll.pitch += Cesium.Math.TWO_PI; |
| 168 | + } |
| 169 | + break; |
| 170 | + case 38: |
| 171 | + // pitch up |
| 172 | + hpRoll.pitch += deltaRadians; |
| 173 | + if (hpRoll.pitch > Cesium.Math.TWO_PI) { |
| 174 | + hpRoll.pitch -= Cesium.Math.TWO_PI; |
| 175 | + } |
| 176 | + break; |
| 177 | + case 39: |
| 178 | + if (e.shiftKey) { |
| 179 | + // roll right |
| 180 | + hpRoll.roll += deltaRadians; |
| 181 | + if (hpRoll.roll > Cesium.Math.TWO_PI) { |
| 182 | + hpRoll.roll -= Cesium.Math.TWO_PI; |
| 183 | + } |
| 184 | + } else { |
| 185 | + // turn right |
| 186 | + hpRoll.heading += deltaRadians; |
| 187 | + if (hpRoll.heading > Cesium.Math.TWO_PI) { |
| 188 | + hpRoll.heading -= Cesium.Math.TWO_PI; |
| 189 | + } |
| 190 | + } |
| 191 | + break; |
| 192 | + case 37: |
| 193 | + if (e.shiftKey) { |
| 194 | + // roll left until |
| 195 | + hpRoll.roll -= deltaRadians; |
| 196 | + if (hpRoll.roll < 0.0) { |
| 197 | + hpRoll.roll += Cesium.Math.TWO_PI; |
| 198 | + } |
| 199 | + } else { |
| 200 | + // turn left |
| 201 | + hpRoll.heading -= deltaRadians; |
| 202 | + if (hpRoll.heading < 0.0) { |
| 203 | + hpRoll.heading += Cesium.Math.TWO_PI; |
| 204 | + } |
| 205 | + } |
| 206 | + break; |
| 207 | + default: |
| 208 | + } |
| 209 | +}); |
| 210 | + |
| 211 | +var headingSpan = document.getElementById('heading'); |
| 212 | +var pitchSpan = document.getElementById('pitch'); |
| 213 | +var rollSpan = document.getElementById('roll'); |
| 214 | + |
| 215 | +viewer.scene.preRender.addEventListener(function(scene, time) { |
| 216 | + headingSpan.innerHTML = Cesium.Math.toDegrees(hpRoll.heading).toFixed(1); |
| 217 | + pitchSpan.innerHTML = Cesium.Math.toDegrees(hpRoll.pitch).toFixed(1); |
| 218 | + rollSpan.innerHTML = Cesium.Math.toDegrees(hpRoll.roll).toFixed(1); |
| 219 | + |
| 220 | + for (var i = 0; i < primitives.length; i++) { |
| 221 | + var primitive = primitives[i].primitive; |
| 222 | + var converter = primitives[i].converter; |
| 223 | + var position = primitives[i].position; |
| 224 | + Cesium.Transforms.headingPitchRollToFixedFrame(position, hpRoll, Cesium.Ellipsoid.WGS84, converter, primitive.modelMatrix); |
| 225 | + } |
| 226 | +}); |
| 227 | +//Sandcastle_End |
| 228 | + Sandcastle.finishedLoading(); |
| 229 | +} |
| 230 | +if (typeof Cesium !== "undefined") { |
| 231 | + startup(Cesium); |
| 232 | +} else if (typeof require === "function") { |
| 233 | + require(["Cesium"], startup); |
| 234 | +} |
| 235 | +</script> |
| 236 | +</body> |
| 237 | +</html> |
0 commit comments