Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding a method to retrieve pitch, roll and heading from a quaternion #4047

Merged
merged 19 commits into from
Oct 20, 2016
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
22d3875
adding a method to retrieve pitch, roll and heading from a quaternion
kaktus40 Jun 25, 2016
f1684c3
update files following recommendations.
kaktus40 Jun 25, 2016
7d9c475
Merge remote-tracking branch 'upstream/master' into adding_toHeadingP…
kaktus40 Jul 1, 2016
00a32b0
Merge branch 'master' into adding_toHeadingPitchRoll
kaktus40 Jul 5, 2016
2c7be6c
Merge remote-tracking branch 'upstream/master' into adding_toHeadingP…
kaktus40 Jul 9, 2016
4aa7eee
added a new transformation and a sandCastle example
kaktus40 Jul 9, 2016
4552bc5
works after review
kaktus40 Jul 10, 2016
449cbe7
remove unnecessary semicolon
kaktus40 Jul 12, 2016
63d90ec
Merge remote-tracking branch 'upstream/master' into adding_toHeadingP…
kaktus40 Jul 12, 2016
1c72b36
Merge remote-tracking branch 'upstream/master' into adding_toHeadingP…
kaktus40 Jul 12, 2016
f860079
Merge remote-tracking branch 'upstream/master' into adding_toHeadingP…
kaktus40 Jul 16, 2016
05af96e
Correct some typos and examples
kaktus40 Jul 18, 2016
8fe6ec2
hack to obtain the focus in the canvas
kaktus40 Jul 20, 2016
dba1f75
Merge remote-tracking branch 'upstream/master' into adding_toHeadingP…
kaktus40 Jul 20, 2016
e2fa9f0
Merge remote-tracking branch 'upstream/master' into adding_toHeadingP…
kaktus40 Aug 24, 2016
74114c1
Merge remote-tracking branch 'upstream/master' into adding_toHeadingP…
kaktus40 Oct 19, 2016
26854a1
Merge remote-tracking branch 'upstream/master' into adding_toHeadingP…
kaktus40 Oct 19, 2016
39bab2c
Merge remote-tracking branch 'upstream/master' into adding_toHeadingP…
kaktus40 Oct 20, 2016
edcc1d8
update example
kaktus40 Oct 20, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
231 changes: 231 additions & 0 deletions Apps/Sandcastle/gallery/development/HeadingPitchRoll.html
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>&larr; to left/&rarr; to right</td>
</tr>
<tr>
<td>Pitch: <span id='pitch'></span>°</td>
</tr>
<tr>
<td>&uarr; to up/&darr; to down</td>
</tr>
<tr>
<td>roll: <span id='roll'></span>°</td>
</tr>
<tr>
<td>&larr; + &#8679; left/&rarr; + &#8679; right</td>
</tr>
<tr>
<td>Speed: <span id='speed'></span>m/s</td>
</tr>
<tr>
<td>&uarr; + &#8679; to speed up/&darr; + &#8679; 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.
Loading