Skip to content

Commit 6d62670

Browse files
committed
Added THREE.ViveController.
1 parent 6b7ca21 commit 6d62670

File tree

4 files changed

+40293
-45
lines changed

4 files changed

+40293
-45
lines changed

examples/js/ViveController.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
THREE.ViveController = function ( id ) {
2+
3+
THREE.Object3D.call( this );
4+
5+
this.matrixAutoUpdate = false;
6+
this.standingMatrix = new THREE.Matrix4();
7+
8+
var scope = this;
9+
10+
function update() {
11+
12+
requestAnimationFrame( update );
13+
14+
var gamepad = navigator.getGamepads()[ id ];
15+
16+
if ( gamepad !== undefined && gamepad.pose !== null ) {
17+
18+
var pose = gamepad.pose;
19+
20+
scope.position.fromArray( pose.position );
21+
scope.quaternion.fromArray( pose.orientation );
22+
scope.matrix.compose( scope.position, scope.quaternion, scope.scale );
23+
scope.matrix.multiplyMatrices( scope.standingMatrix, scope.matrix );
24+
scope.matrixWorldNeedsUpdate = true;
25+
26+
scope.visible = true;
27+
28+
} else {
29+
30+
scope.visible = false;
31+
32+
}
33+
34+
}
35+
36+
update();
37+
38+
};
39+
40+
THREE.ViveController.prototype = Object.create( THREE.Object3D.prototype );
41+
THREE.ViveController.prototype.constructor = THREE.ViveController;

examples/js/controls/VRControls.js

100644100755
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ THREE.VRControls = function ( object, onError ) {
5858
// standing=true but the VRDisplay doesn't provide stageParameters.
5959
this.userHeight = 1.6;
6060

61+
this.getStandingMatrix = function () {
62+
63+
return standingMatrix;
64+
65+
};
66+
6167
this.update = function () {
6268

6369
if ( vrInput ) {

0 commit comments

Comments
 (0)