提交 e79994e5 编写于 作者: M Mr.doob

Merge pull request #5478 from dmarcos/nullOrientation

Handling case when the orientation of VR state is null. For some devices...
...@@ -5,6 +5,11 @@ ...@@ -5,6 +5,11 @@
THREE.VRControls = function ( camera, done ) { THREE.VRControls = function ( camera, done ) {
this._camera = camera; this._camera = camera;
this._vrState = {
hmd : {
orientation: new THREE.Quaternion()
}
};
this._init = function () { this._init = function () {
var self = this; var self = this;
...@@ -49,28 +54,20 @@ THREE.VRControls = function ( camera, done ) { ...@@ -49,28 +54,20 @@ THREE.VRControls = function ( camera, done ) {
} }
// Applies head rotation from sensors data. // Applies head rotation from sensors data.
if ( camera ) { if ( camera ) {
camera.quaternion.fromArray( vrState.hmd.rotation ); camera.quaternion.copy( vrState.hmd.orientation );
} }
}; };
this.getVRState = function() { this.getVRState = function() {
var vrInput = this._vrInput; var vrInput = this._vrInput;
var vrState = this._vrState;
var orientation; var orientation;
var vrState;
if ( !vrInput ) { if ( !vrInput ) {
return null; return null;
} }
orientation = vrInput.getState().orientation; // If orientation is not available we return the identity quaternion (no rotation)
vrState = { orientation = vrInput.getState().orientation || { x: 0, y: 0, z:0, w:1 };
hmd : { vrState.hmd.orientation.set( orientation.x, orientation.y, orientation.z, orientation.w );
rotation : [
orientation.x,
orientation.y,
orientation.z,
orientation.w
]
}
};
return vrState; return vrState;
}; };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册