提交 cfd22c2c 编写于 作者: D Diego Marcos

Reintroduce standing matrix

上级 25b71ec2
......@@ -40,6 +40,7 @@ THREE.ViveController = function ( id ) {
}
this.matrixAutoUpdate = false;
this.standingMatrix = new THREE.Matrix4();
this.getGamepad = function () {
......@@ -71,6 +72,7 @@ THREE.ViveController = function ( id ) {
if ( pose.position !== null ) scope.position.fromArray( pose.position );
if ( pose.orientation !== null ) scope.quaternion.fromArray( pose.orientation );
scope.matrix.compose( scope.position, scope.quaternion, scope.scale );
scope.matrix.multiplyMatrices( scope.standingMatrix, scope.matrix );
scope.matrixWorldNeedsUpdate = true;
scope.visible = true;
......
......@@ -58,7 +58,6 @@
scene.background = new THREE.Color( 0x505050 );
var user = new THREE.Group();
user.position.set( 0, 1.6, 0 );
scene.add( user );
camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.1, 10 );
......@@ -165,9 +164,11 @@
// controllers
controller1 = new THREE.ViveController( 0 );
controller1.standingMatrix = renderer.vr.getStandingMatrix();
user.add( controller1 );
controller2 = new THREE.ViveController( 1 );
controller2.standingMatrix = renderer.vr.getStandingMatrix();
user.add( controller2 );
var loader = new THREE.OBJLoader();
......
......@@ -59,7 +59,6 @@
scene.background = new THREE.Color( 0x808080 );
var user = new THREE.Group();
user.position.set( 0, 1.6, 0 );
scene.add( user );
camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.1, 10 );
......@@ -143,11 +142,13 @@
// controllers
controller1 = new THREE.ViveController( 0 );
controller1.standingMatrix = renderer.vr.getStandingMatrix();
controller1.addEventListener( 'triggerdown', onTriggerDown );
controller1.addEventListener( 'triggerup', onTriggerUp );
user.add( controller1 );
controller2 = new THREE.ViveController( 1 );
controller2.standingMatrix = renderer.vr.getStandingMatrix();
controller2.addEventListener( 'triggerdown', onTriggerDown );
controller2.addEventListener( 'triggerup', onTriggerUp );
user.add( controller2 );
......
......@@ -70,7 +70,6 @@
scene.background = new THREE.Color( 0x222222 );
var user = new THREE.Group();
user.position.set( 0, 1.6, 0 );
scene.add( user );
camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.01, 50 );
......@@ -142,11 +141,13 @@
// controllers
controller1 = new THREE.PaintViveController( 0 );
controller1.standingMatrix = renderer.vr.getStandingMatrix();
controller1.userData.points = [ new THREE.Vector3(), new THREE.Vector3() ];
controller1.userData.matrices = [ new THREE.Matrix4(), new THREE.Matrix4() ];
user.add( controller1 );
controller2 = new THREE.PaintViveController( 1 );
controller2.standingMatrix = renderer.vr.getStandingMatrix();
controller2.userData.points = [ new THREE.Vector3(), new THREE.Vector3() ];
controller2.userData.matrices = [ new THREE.Matrix4(), new THREE.Matrix4() ];
user.add( controller2 );
......
......@@ -60,7 +60,6 @@
scene.background = new THREE.Color( 0x222222 );
var user = new THREE.Group();
user.position.set( 0, 1.6, 0 );
scene.add( user );
camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.01, 50 );
......@@ -124,9 +123,11 @@
// controllers
controller1 = new THREE.ViveController( 0 );
controller1.standingMatrix = renderer.vr.getStandingMatrix();
user.add( controller1 );
controller2 = new THREE.ViveController( 1 );
controller2.standingMatrix = renderer.vr.getStandingMatrix();
user.add( controller2 );
var loader = new THREE.OBJLoader();
......
......@@ -1587,16 +1587,6 @@ Object.defineProperties( WebGLRenderTarget.prototype, {
//
Object.assign( WebVRManager.prototype, {
getStandingMatrix: function () {
console.warn( 'THREE.WebVRManager: .getStandingMatrix() has been removed.' );
}
} );
Object.defineProperties( WebVRManager.prototype, {
standing: {
......
......@@ -16,6 +16,11 @@ function WebVRManager( renderer ) {
var poseTarget = null;
var standingMatrix = new Matrix4();
var standingMatrixInverse = new Matrix4();
scope.userHeight = 1.6;
if ( typeof window !== 'undefined' && 'VRFrameData' in window ) {
frameData = new window.VRFrameData();
......@@ -109,7 +114,7 @@ function WebVRManager( renderer ) {
} else {
poseObject.position.set( 0, 0, 0 );
poseObject.position.set( 0, scope.userHeight, 0 );
}
......@@ -121,6 +126,18 @@ function WebVRManager( renderer ) {
poseObject.updateMatrixWorld();
var stageParameters = device.stageParameters;
if (stageParameters) {
standingMatrix.fromArray( stageParameters.sittingToStandingTransform );
} else {
standingMatrix.makeTranslation(0, scope.userHeight, 0);
}
standingMatrixInverse.getInverse( standingMatrix );
poseObject.matrixWorld.multiply( standingMatrix );
camera.matrixWorldInverse.multiply( standingMatrixInverse );
if ( device.isPresenting === false ) return camera;
//
......@@ -137,6 +154,9 @@ function WebVRManager( renderer ) {
cameraL.matrixWorldInverse.fromArray( frameData.leftViewMatrix );
cameraR.matrixWorldInverse.fromArray( frameData.rightViewMatrix );
cameraL.matrixWorldInverse.multiply( standingMatrixInverse );
cameraR.matrixWorldInverse.multiply( standingMatrixInverse );
var parent = poseObject.parent;
if ( parent !== null ) {
......@@ -187,6 +207,12 @@ function WebVRManager( renderer ) {
};
this.getStandingMatrix = function () {
return standingMatrix;
};
this.submitFrame = function () {
if ( device && device.isPresenting ) device.submitFrame();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册