ViveController.js 944 B

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