Skip to content

Commit

Permalink
Merge pull request #4047 from kaktus40/adding_toHeadingPitchRoll
Browse files Browse the repository at this point in the history
adding a method to retrieve pitch, roll and heading from a quaternion
  • Loading branch information
pjcozzi committed Oct 20, 2016
2 parents 9690838 + edcc1d8 commit c0dc341
Show file tree
Hide file tree
Showing 9 changed files with 1,058 additions and 209 deletions.
237 changes: 237 additions & 0 deletions Apps/Sandcastle/gallery/development/HeadingPitchRoll.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
<!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 canvas = viewer.canvas;
canvas.setAttribute('tabindex', '0'); // needed to put focus on the canvas
canvas.onclick = function() {
canvas.focus();
};

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.keyCode) {
case 40:
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 38:
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 39:
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 37:
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.
9 changes: 9 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ Change Log
* Added the ability to specify retina options, such as `@2x.png`, via the `MapboxImageryProvider` `format` option.
* Removed an unnecessary reprojection of Web Mercator imagery tiles to the Geographic projection on load. This should improve both visual quality and load performance slightly.
* Fix a issue where a billboard entity would not render after toggling the show propery. [#4408](https://github.com/AnalyticalGraphicsInc/cesium/issues/4408)
* Added `Transforms.northUpEastToFixedFrame` to compute a 4x4 local transformation matrix from a reference frame with an north-west-up axes.
* Added `Transforms.aircraftHeadingPitchRollToFixedFrame` to create a local frame from a position and heading/pitch/roll angles. The local frame is north-west-up axed.
* Added `Transforms.aircraftHeadingPitchRollQuaternion` which is the quaternion rotation from `Transforms.aircraftHeadingPitchRollToFixedFrame`.
* Added `HeadingPitchRoll` :
* `HeadingPitchRoll.fromQuaternion` function for retrieving heading-pitch-roll angles from a quaternion.
* `HeadingPitchRoll.fromDegrees` function that returns a new HeadingPitchRoll instance from angles given in degrees.
* `HeadingPitchRoll.clone` function to duplicate HeadingPitchRoll instance.
* `HeadingPitchRoll.equals` and `HeadingPitchRoll.equalsEpsilon` functions for comparing two instances.
* Added `Matrix3.fromHeadingPitchRoll` Computes a 3x3 rotation matrix from the provided headingPitchRoll.

### 1.26 - 2016-10-03

Expand Down
Loading

0 comments on commit c0dc341

Please sign in to comment.