Skip to content

Commit 2ebf16a

Browse files
committed
Fix minor issues
1 parent 3da9555 commit 2ebf16a

File tree

3 files changed

+29
-24
lines changed

3 files changed

+29
-24
lines changed

‎examples/basic/index.html‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
changeTask: { label: 'Change task' },
5757
logdefault: { label: 'Test Log' },
5858
logtask1: { label: 'Test Log Task 1' },
59+
logtask2: { label: 'Test Log Task 2' },
5960
lefthand: { label: 'Left hand' },
6061
righthand: { label: 'Right hand' },
6162
longpress: { label: 'Long press' },
@@ -86,10 +87,10 @@
8687
},
8788
'vive-controls': {
8889
'grip.down': 'changeTask',
89-
'trackpad.down': 'logdefault',
90+
'trackpad.down': 'logtask1',
9091
'trackpad.doubletouch': 'doubletouch',
9192
'trackpad.doublepress': 'doublepress',
92-
//'trackpad.longpress': 'longpress',
93+
// Activators for down, up, touchstart and touchend are optionals you can just write the event without the .
9394
'trackpaddpadleftdown': 'dpadleft',
9495
'trackpaddpadright.longpress': 'dpadrightlong'
9596
},
@@ -106,19 +107,19 @@
106107
},
107108
task2: {
108109
'vive-controls': {
109-
'trigger.down': 'logtask1',
110+
'trigger.down': 'logtask2',
110111
'grip.down': 'changeTask'
111112
},
112113
'oculus-touch-controls': {
113-
'trigger.down': 'logtask1',
114+
'trigger.down': 'logtask2',
114115
'abutton.down': 'changeTask'
115116
},
116117
'windows-motion-controls': {
117-
'trigger.down': 'logtask1',
118+
'trigger.down': 'logtask2',
118119
'grip.down': 'changeTask'
119120
},
120121
keyboard: {
121-
'y_up': 'logtask1',
122+
'y_up': 'logtask2',
122123
'c_up': 'changeTask'
123124
}
124125
}
@@ -159,7 +160,7 @@
159160
logEvent(event);
160161
});
161162

162-
var events = ['dpadleft', 'dpadrightlong', 'dpad', 'logtask1', 'logdefault', 'righthand', 'lefthand', 'doubletouch', 'doublepress', 'longpress'];
163+
var events = ['dpadleft', 'dpadrightlong', 'dpad', 'logtask1', 'logtask2', 'logdefault', 'righthand', 'lefthand', 'doubletouch', 'doublepress', 'longpress'];
163164
for (var i = 0; i < events.length; i++) {
164165
scene.addEventListener(events[i], function(event) {
165166
logEvent(event);

‎src/activators/doublepress.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ DoublePress.prototype = {
2020
}
2121
},
2222

23-
destroy () {
23+
removeListeners () {
2424
this.el.removeEventListener(this.eventName, this.onButtonDown);
2525
}
2626
}

‎src/behaviours/dpad.js‎

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,13 @@ function DPad (el, buttonName) {
99
this.el = el;
1010
};
1111

12-
const angleToDirection = function(angle) {
13-
angle = (angle * THREE.Math.RAD2DEG + 180 + 45) % 360;
14-
if (angle > 0 && angle < 90) {
15-
return "down";
16-
} else if (angle >= 90 && angle < 180) {
17-
return "left";
18-
} else if (angle >= 180 && angle < 270) {
19-
return "up";
20-
} else {
21-
return "right";
22-
}
23-
};
24-
2512
DPad.prototype = {
2613
onAxisMove: function(event) {
2714
this.lastPos = event.detail.axis;
2815
},
2916

3017
onButtonPresed: function (event) {
3118
const [x, y] = this.lastPos;
32-
//const { upEvents, centerZone } = this.data;
3319
const state = 'trackpadup'.includes(event.type) ? "up" : "down";
3420
var centerZone = 0.5;
3521
const direction =
@@ -40,14 +26,32 @@ DPad.prototype = {
4026
: angleToDirection(Math.atan2(x, y));
4127

4228
this.el.emit(`${this.buttonName}dpad${direction}${state}`);
43-
console.log(`${this.buttonName}dpad${direction}${state}`);
4429

4530
if (state === "down") {
4631
this.lastDirection = direction;
4732
} else {
4833
delete this.lastDirection;
4934
}
35+
},
36+
37+
removeListeners: function () {
38+
el.removeEventListener('trackpaddown', this.onButtonPresed);
39+
el.removeEventListener('trackpadup', this.onButtonPresed);
40+
el.removeEventListener('axismove', this.onAxisMove);
41+
}
42+
};
43+
44+
const angleToDirection = function (angle) {
45+
angle = (angle * THREE.Math.RAD2DEG + 180 + 45) % 360;
46+
if (angle > 0 && angle < 90) {
47+
return "down";
48+
} else if (angle >= 90 && angle < 180) {
49+
return "left";
50+
} else if (angle >= 180 && angle < 270) {
51+
return "up";
52+
} else {
53+
return "right";
5054
}
5155
};
5256

53-
AFRAME.registerInputBehaviour('dpad', DPad);
57+
AFRAME.registerInputBehaviour('dpad', DPad);

0 commit comments

Comments
 (0)