Skip to content

Commit

Permalink
Update all scripts from dev branch of three.js
Browse files Browse the repository at this point in the history
  • Loading branch information
borismus committed Aug 9, 2015
1 parent a6294c6 commit dbf41fc
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 27 deletions.
12 changes: 9 additions & 3 deletions js/deps/VRControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ THREE.VRControls = function ( object, onError ) {

var oculusDevices = devices.filter( function ( device ) {

return device.deviceName.toLowerCase().indexOf('oculus') !== -1;
return device.deviceName.toLowerCase().indexOf( 'oculus' ) !== - 1;

} );

if ( oculusDevices.length >= 1 ) {

return devices.filter( function ( device ) {

return device.deviceName.toLowerCase().indexOf('cardboard') === -1;
return device.deviceName.toLowerCase().indexOf( 'cardboard' ) === - 1;

} );

Expand Down Expand Up @@ -111,9 +111,15 @@ THREE.VRControls = function ( object, onError ) {

this.zeroSensor = function () {

THREE.warn( 'THREE.VRControls: .zeroSensor() is now .resetSensor().' );
console.warn( 'THREE.VRControls: .zeroSensor() is now .resetSensor().' );
this.resetSensor();

};

this.dispose = function () {

vrInputs = [];

};

};
49 changes: 25 additions & 24 deletions js/deps/VREffect.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ THREE.VREffect = function ( renderer, onError ) {

var sceneL, sceneR;

if ( scene instanceof Array ) {
if ( Array.isArray( scene ) ) {

sceneL = scene[ 0 ];
sceneR = scene[ 1 ];
Expand Down Expand Up @@ -162,7 +162,7 @@ THREE.VREffect = function ( renderer, onError ) {

// Regular render mode if not HMD

if ( scene instanceof Array ) scene = scene[ 0 ];
if ( Array.isArray( scene ) ) scene = scene[ 0 ];

renderer.render( scene, camera );

Expand All @@ -172,10 +172,10 @@ THREE.VREffect = function ( renderer, onError ) {

function fovToNDCScaleOffset( fov ) {

var pxscale = 2.0 / (fov.leftTan + fov.rightTan);
var pxoffset = (fov.leftTan - fov.rightTan) * pxscale * 0.5;
var pyscale = 2.0 / (fov.upTan + fov.downTan);
var pyoffset = (fov.upTan - fov.downTan) * pyscale * 0.5;
var pxscale = 2.0 / ( fov.leftTan + fov.rightTan );
var pxoffset = ( fov.leftTan - fov.rightTan ) * pxscale * 0.5;
var pyscale = 2.0 / ( fov.upTan + fov.downTan );
var pyoffset = ( fov.upTan - fov.downTan ) * pyscale * 0.5;
return { scale: [ pxscale, pyscale ], offset: [ pxoffset, pyoffset ] };

}
Expand All @@ -186,44 +186,45 @@ THREE.VREffect = function ( renderer, onError ) {
zNear = zNear === undefined ? 0.01 : zNear;
zFar = zFar === undefined ? 10000.0 : zFar;

var handednessScale = rightHanded ? -1.0 : 1.0;
var handednessScale = rightHanded ? - 1.0 : 1.0;

// start with an identity matrix
var mobj = new THREE.Matrix4();
var m = mobj.elements;

// and with scale/offset info for normalized device coords
var scaleAndOffset = fovToNDCScaleOffset(fov);
var scaleAndOffset = fovToNDCScaleOffset( fov );

// X result, map clip edges to [-w,+w]
m[0 * 4 + 0] = scaleAndOffset.scale[0];
m[0 * 4 + 1] = 0.0;
m[0 * 4 + 2] = scaleAndOffset.offset[0] * handednessScale;
m[0 * 4 + 3] = 0.0;
m[ 0 * 4 + 0 ] = scaleAndOffset.scale[ 0 ];
m[ 0 * 4 + 1 ] = 0.0;
m[ 0 * 4 + 2 ] = scaleAndOffset.offset[ 0 ] * handednessScale;
m[ 0 * 4 + 3 ] = 0.0;

// Y result, map clip edges to [-w,+w]
// Y offset is negated because this proj matrix transforms from world coords with Y=up,
// but the NDC scaling has Y=down (thanks D3D?)
m[1 * 4 + 0] = 0.0;
m[1 * 4 + 1] = scaleAndOffset.scale[1];
m[1 * 4 + 2] = -scaleAndOffset.offset[1] * handednessScale;
m[1 * 4 + 3] = 0.0;
m[ 1 * 4 + 0 ] = 0.0;
m[ 1 * 4 + 1 ] = scaleAndOffset.scale[ 1 ];
m[ 1 * 4 + 2 ] = - scaleAndOffset.offset[ 1 ] * handednessScale;
m[ 1 * 4 + 3 ] = 0.0;

// Z result (up to the app)
m[2 * 4 + 0] = 0.0;
m[2 * 4 + 1] = 0.0;
m[2 * 4 + 2] = zFar / (zNear - zFar) * -handednessScale;
m[2 * 4 + 3] = (zFar * zNear) / (zNear - zFar);
m[ 2 * 4 + 0 ] = 0.0;
m[ 2 * 4 + 1 ] = 0.0;
m[ 2 * 4 + 2 ] = zFar / ( zNear - zFar ) * - handednessScale;
m[ 2 * 4 + 3 ] = ( zFar * zNear ) / ( zNear - zFar );

// W result (= Z in)
m[3 * 4 + 0] = 0.0;
m[3 * 4 + 1] = 0.0;
m[3 * 4 + 2] = handednessScale;
m[3 * 4 + 3] = 0.0;
m[ 3 * 4 + 0 ] = 0.0;
m[ 3 * 4 + 1 ] = 0.0;
m[ 3 * 4 + 2 ] = handednessScale;
m[ 3 * 4 + 3 ] = 0.0;

mobj.transpose();

return mobj;

}

function fovToProjection( fov, rightHanded, zNear, zFar ) {
Expand Down
7 changes: 7 additions & 0 deletions update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
# Fetch the latest versions of three.js, VRControls and VREffect from the
# three.js repository.

curl -o js/deps/VRControls.js https://raw.githubusercontent.com/mrdoob/three.js/dev/examples/js/controls/VRControls.js
curl -o js/deps/VREffect.js https://raw.githubusercontent.com/mrdoob/three.js/dev/examples/js/effects/VREffect.js
curl -o js/deps/three.js http://threejs.org/build/three.js

0 comments on commit dbf41fc

Please sign in to comment.