Last active
August 29, 2015 14:06
-
-
Save kennu/151501d89e7e71412b39 to your computer and use it in GitHub Desktop.
Oculus Web GL Examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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