Skip to content

Commit 35b55e5

Browse files
committed
Added Gyroscope object.
It's Object3D subclass that takes a position from the scene graph hierarchy but uses its local rotation as world rotation. It works like real-world gyroscope - you can move it around using hierarchy while its orientation stays fixed with respect to the world.
1 parent 8cf5336 commit 35b55e5

File tree

4 files changed

+73
-6
lines changed

4 files changed

+73
-6
lines changed

build/Three.js

Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/custom/ThreeExtras.js

Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/extras/core/Gyroscope.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* @author alteredq / http://alteredqualia.com/
3+
*/
4+
5+
THREE.Gyroscope = function () {
6+
7+
THREE.Object3D.call( this );
8+
9+
};
10+
11+
12+
THREE.Gyroscope.prototype = new THREE.Object3D();
13+
THREE.Gyroscope.prototype.constructor = THREE.Gyroscope;
14+
15+
THREE.Gyroscope.prototype.updateMatrixWorld = function ( force ) {
16+
17+
this.matrixAutoUpdate && this.updateMatrix();
18+
19+
// update matrixWorld
20+
21+
if ( this.matrixWorldNeedsUpdate || force ) {
22+
23+
if ( this.parent ) {
24+
25+
this.matrixWorld.multiply( this.parent.matrixWorld, this.matrix );
26+
27+
this.matrixWorld.decompose( this.translationWorld, this.rotationWorld, this.scaleWorld );
28+
this.matrix.decompose( this.translationObject, this.rotationObject, this.scaleObject );
29+
30+
this.matrixWorld.compose( this.translationWorld, this.rotationObject, this.scaleWorld );
31+
32+
33+
} else {
34+
35+
this.matrixWorld.copy( this.matrix );
36+
37+
}
38+
39+
40+
this.matrixWorldNeedsUpdate = false;
41+
42+
force = true;
43+
44+
}
45+
46+
// update children
47+
48+
for ( var i = 0, l = this.children.length; i < l; i ++ ) {
49+
50+
this.children[ i ].updateMatrixWorld( force );
51+
52+
}
53+
54+
};
55+
56+
THREE.Gyroscope.prototype.translationWorld = new THREE.Vector3();
57+
THREE.Gyroscope.prototype.translationObject = new THREE.Vector3();
58+
THREE.Gyroscope.prototype.rotationWorld = new THREE.Quaternion();
59+
THREE.Gyroscope.prototype.rotationObject = new THREE.Quaternion();
60+
THREE.Gyroscope.prototype.scaleWorld = new THREE.Vector3();
61+
THREE.Gyroscope.prototype.scaleObject = new THREE.Vector3();
62+

utils/build.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
'extras/core/BufferGeometry.js',
9595
'extras/core/Curve.js',
9696
'extras/core/CurvePath.js',
97+
'extras/core/Gyroscope.js',
9798
'extras/core/Path.js',
9899
'extras/core/Shape.js',
99100
'extras/core/TextPath.js',

0 commit comments

Comments
 (0)