Skip to content

Instantly share code, notes, and snippets.

@kennu
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kennu/151501d89e7e71412b39 to your computer and use it in GitHub Desktop.
Save kennu/151501d89e7e71412b39 to your computer and use it in GitHub Desktop.
Oculus Web GL Examples
function render(time) {
// Render next frame
requestAnimationFrame(render);
// Update camera with VR head tracking data
updateVRDevice();
// Render screen in VR mode or in regular 3D mode
if (inFullscreen && displayDevice) {
renderer.enableScissorTest(true);
// Render left eye
renderer.setScissor(0, 0, windowHalfWidth, windowHeight);
renderer.setViewport(0, 0, windowHalfWidth, windowHeight);
renderer.render(scene, cameraLeft);
// Render right eye
renderer.setScissor(windowHalfWidth, 0, windowHalfWidth, windowHeight);
renderer.setViewport(windowHalfWidth, 0, windowHalfWidth, windowHeight);
renderer.render(scene, cameraRight);
} else {
// Render without VR device
renderer.enableScissorTest(false);
renderer.setViewport(0, 0, windowWidth, windowHeight);
renderer.render(scene, camera);
}
}
function updateVRDevice() {
if (sensorDevice) {
var state = sensorDevice.getState();
// Update camera according to VR state
cameraRotation.set(state.orientation.x, state.orientation.y, state.orientation.z, state.orientation.w);
cameraLeft.setRotationFromQuaternion(cameraRotation);
cameraRight.setRotationFromQuaternion(cameraRotation);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment