Gyroscope.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /**
  2. * @author alteredq / http://alteredqualia.com/
  3. */
  4. THREE.Gyroscope = function () {
  5. THREE.Object3D.call( this );
  6. };
  7. THREE.Gyroscope.prototype = Object.create( THREE.Object3D.prototype );
  8. THREE.Gyroscope.prototype.constructor = THREE.Gyroscope;
  9. THREE.Gyroscope.prototype.updateMatrixWorld = ( function () {
  10. var translationObject = new THREE.Vector3();
  11. var quaternionObject = new THREE.Quaternion();
  12. var scaleObject = new THREE.Vector3();
  13. var translationWorld = new THREE.Vector3();
  14. var quaternionWorld = new THREE.Quaternion();
  15. var scaleWorld = new THREE.Vector3();
  16. return function updateMatrixWorld( force ) {
  17. this.matrixAutoUpdate && this.updateMatrix();
  18. // update matrixWorld
  19. if ( this.matrixWorldNeedsUpdate || force ) {
  20. if ( this.parent !== null ) {
  21. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  22. this.matrixWorld.decompose( translationWorld, quaternionWorld, scaleWorld );
  23. this.matrix.decompose( translationObject, quaternionObject, scaleObject );
  24. this.matrixWorld.compose( translationWorld, quaternionObject, scaleWorld );
  25. } else {
  26. this.matrixWorld.copy( this.matrix );
  27. }
  28. this.matrixWorldNeedsUpdate = false;
  29. force = true;
  30. }
  31. // update children
  32. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  33. this.children[ i ].updateMatrixWorld( force );
  34. }
  35. };
  36. }() );