Skip to content

Commit

Permalink
Add the ability to specify an alternative Object3D to the camera to a…
Browse files Browse the repository at this point in the history
…pply the pose coming from a VRDevice
  • Loading branch information
dmarcos committed Nov 15, 2017
1 parent dfff0c8 commit ee58f54
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/renderers/webvr/WebVRManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ function WebVRManager( renderer ) {
var device = null;
var frameData = null;

var poseTarget = null;

if ( typeof window !== 'undefined' && 'VRFrameData' in window ) {

frameData = new window.VRFrameData();
Expand Down Expand Up @@ -85,6 +87,12 @@ function WebVRManager( renderer ) {

};

this.setPoseTarget = function ( object ) {

if ( object !== undefined ) poseTarget = object;

};

this.getCamera = function ( camera ) {

if ( device === null ) return camera;
Expand All @@ -97,20 +105,31 @@ function WebVRManager( renderer ) {
//

var pose = frameData.pose;
var poseObject;

if ( poseTarget !== null ) {

poseObject = poseTarget;

} else {

poseObject = camera;

}

if ( pose.position !== null ) {

camera.position.fromArray( pose.position );
poseObject.position.fromArray( pose.position );

} else {

camera.position.set( 0, 0, 0 );
poseObject.position.set( 0, 0, 0 );

}

if ( pose.orientation !== null ) {

camera.quaternion.fromArray( pose.orientation );
poseObject.quaternion.fromArray( pose.orientation );

}

Expand Down

0 comments on commit ee58f54

Please sign in to comment.