ViveController.js 881 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. THREE.ViveController = function ( id ) {
  2. THREE.Object3D.call( this );
  3. this.matrixAutoUpdate = false;
  4. this.standingMatrix = new THREE.Matrix4();
  5. var scope = this;
  6. function update() {
  7. requestAnimationFrame( update );
  8. var gamepad = navigator.getGamepads()[ id ];
  9. if ( gamepad !== undefined && gamepad.pose !== null ) {
  10. var pose = gamepad.pose;
  11. scope.position.fromArray( pose.position );
  12. scope.quaternion.fromArray( pose.orientation );
  13. scope.matrix.compose( scope.position, scope.quaternion, scope.scale );
  14. scope.matrix.multiplyMatrices( scope.standingMatrix, scope.matrix );
  15. scope.matrixWorldNeedsUpdate = true;
  16. scope.visible = true;
  17. } else {
  18. scope.visible = false;
  19. }
  20. }
  21. update();
  22. };
  23. THREE.ViveController.prototype = Object.create( THREE.Object3D.prototype );
  24. THREE.ViveController.prototype.constructor = THREE.ViveController;