ViveController.js 990 B

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