Skip to content

Commit

Permalink
index.js: added a sensible navigation control scheme.
Browse files Browse the repository at this point in the history
README.md: documented the new navigation controls.
  • Loading branch information
pupitetris committed Jul 28, 2023
1 parent 30d9ba1 commit ce8beea
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 19 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,28 @@ For Oculus/Meta Quest, Pico, HTC Vive Focus, [etc](https://vr-compare.com/standa
### Interaction
#### Legacy
- Hit `Enter` to make the browser fullscreen and enter VR mode.
- The mouse can be used on the left eye to navigate. Number keys take
you to some pre-set locations. Hit `L` at any time to level the
camera to the globe surface.
- The `WASD` keys allow horizontal movement with `Q` and `E` allowing
vertical movement. Holding `Shift` speeds up all movement.
#### Meta Quest 2
- As expected, use the HMD to point the camera in 3DoF. You should
interact while standing or sitting on a rotating seat.
- Both left and right controls work the same, at the same time, but
all interaction can be achieved with one control.
- Relative to the camera orientation, the stick will translate forwards
and laterally (±X and ±Z).
- Use the thumb trigger to go up, relative to the camera orientation (+Y).
- Use the main trigger to amplify movement, up to 10 times faster.
- Tip: if you want advance while looking down but don't want to lose
altitude, press the thumb trigger lightly to compensate.
If you are having any problems, visit the [WebXR Sample
Pages](https://immersive-web.github.io/webxr-samples/) to check you
have correctly configured your VR device for use in your browser. If
Expand Down
44 changes: 25 additions & 19 deletions htdocs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,15 +211,17 @@ async function onSessionStarted(session) {

cesiumCamera = cesiumScene.camera;
cesiumCamera.setView({
destination: Cesium.Cartesian3.fromDegrees(-111.645898, 40.390810, 3600), // Timp
destination: Cesium.Cartesian3.fromDegrees(-100.1152739, 19.1835769, 2250), // Valle de Bravo
// destination: Cesium.Cartesian3.fromDegrees(-111.645898, 40.390810, 3600), // Timp
// destination: Cesium.Cartesian3.fromDegrees(-103.457939, 43.878265, 1650), // Mt Rushmore
// destination: Cesium.Cartesian3.fromDegrees(123.042885, 10.425316, 500), // Mt Rushmore
orientation: {
heading: Cesium.Math.toRadians(175.0),
heading: Cesium.Math.toRadians(90.0),
pitch: Cesium.Math.toRadians(0.0),
roll: 0.0
}
});
// cesiumCamera.frustum.far = 40000;

// Inform the session that we're ready to begin drawing.
session.requestAnimationFrame(onXRFrame);
Expand All @@ -245,26 +247,30 @@ function onXRFrame(t, frame) {
cesiumScene.webXRContext.frame = frame;
cesiumScene.initializeFrame();

let new_position = null;
for (const source of session.inputSources) {
if (source.gamepad && source.handedness == "right") {
// let gamepad_pose = frame.getPose(source.gripSpace, xrRefSpace);
const axes = source.gamepad.axes;
new_position = Cesium.Cartesian3.fromRadians(
cesiumCamera.positionCartographic.longitude + (axes[2] * 0.0001)*-1,
cesiumCamera.positionCartographic.latitude + (axes[3] * 0.0001),
cesiumCamera.positionCartographic.height
);
}
}

const pose = frame.getViewerPose(xrRefSpace);
if (pose) {
const camView = { orientation: { heading: 0, pitch: 0, roll: 0 } };
if (new_position)
camView.destination = new_position;
cesiumCamera.setView(camView);
cesiumCamera.setView({ orientation: { heading: 0, pitch: 0, roll: 0 } });
cVR.applyVRRotation(cesiumCamera, pose);
for (const source of session.inputSources) {
if (source.gamepad/* && source.handedness == "right"*/) {
const gamepad = source.gamepad;
// let gamepad_pose = frame.getPose(source.gripSpace, xrRefSpace);
//gamepad.buttons.forEach((button, idx) => { if (button.pressed) { console.log(`button ${idx}: ${button.value}`); } });
const multiplier = gamepad.buttons[0].value * 9 + 1;

if (gamepad.buttons[1].pressed) {
cesiumCamera.moveUp(gamepad.buttons[1].value * 10 * multiplier);
}

const axes = gamepad.axes;
if (axes[2] !== 0) {
cesiumCamera.moveRight(axes[2] * 10 * multiplier);
}
if (axes[3] !== 0) {
cesiumCamera.moveBackward(axes[3] * 10 * multiplier);
}
}
}
cesiumScene.render();
} else {
cesiumCamera.position = new_position;
Expand Down

0 comments on commit ce8beea

Please sign in to comment.