Skip to content

Commit 1d6930b

Browse files
committed
Removed example. Added to look-controls doc. Conditionally returning instead of conditionally managing event handlers.
1 parent 6420e61 commit 1d6930b

File tree

4 files changed

+12
-37
lines changed

4 files changed

+12
-37
lines changed

docs/components/look-controls.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ component](camera.md).
2727
| Property | Description | Default Value |
2828
|------------------|------------------------------------------------------------------|---------------|
2929
| enabled | Whether look controls are enabled. | true |
30+
| touchEnabled | Whether to use touch controls in magic window mode. | true |
3031
| hmdEnabled | Whether to use VR headset pose in VR mode. | true |
3132
| reverseMouseDrag | Whether to reverse mouse drag. | false |
3233
| standing | Whether standing mode is enabled (passed to `THREE.VRControls`). | true |

examples/boilerplate/hello-world-touch-disabled/index.html

Lines changed: 0 additions & 19 deletions
This file was deleted.

examples/index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ <h2>Boilerplates</h2>
172172

173173
<ul class="links">
174174
<li><a href="boilerplate/hello-world/">Hello World</a></li>
175-
<li><a href="boilerplate/hello-world-touch-disabled/">Hello World Touch Disabled</a></li>
176175
<li><a href="boilerplate/panorama/">360&deg; Image</a></li>
177176
<li><a href="boilerplate/360-video/">360&deg; Video</a></li>
178177
<li><a href="boilerplate/3d-model/">3D Model (COLLADA)</a></li>

src/components/look-controls.js

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,9 @@ module.exports.Component = registerComponent('look-controls', {
7878
this.onMouseDown = bind(this.onMouseDown, this);
7979
this.onMouseMove = bind(this.onMouseMove, this);
8080
this.onMouseUp = bind(this.onMouseUp, this);
81-
if (this.data.touchEnabled) {
82-
this.onTouchStart = bind(this.onTouchStart, this);
83-
this.onTouchMove = bind(this.onTouchMove, this);
84-
this.onTouchEnd = bind(this.onTouchEnd, this);
85-
}
81+
this.onTouchStart = bind(this.onTouchStart, this);
82+
this.onTouchMove = bind(this.onTouchMove, this);
83+
this.onTouchEnd = bind(this.onTouchEnd, this);
8684
this.onExitVR = bind(this.onExitVR, this);
8785
},
8886

@@ -126,11 +124,9 @@ module.exports.Component = registerComponent('look-controls', {
126124
window.addEventListener('mouseup', this.onMouseUp, false);
127125

128126
// Touch events.
129-
if (this.data.touchEnabled) {
130-
canvasEl.addEventListener('touchstart', this.onTouchStart);
131-
window.addEventListener('touchmove', this.onTouchMove);
132-
window.addEventListener('touchend', this.onTouchEnd);
133-
}
127+
canvasEl.addEventListener('touchstart', this.onTouchStart);
128+
window.addEventListener('touchmove', this.onTouchMove);
129+
window.addEventListener('touchend', this.onTouchEnd);
134130
},
135131

136132
/**
@@ -149,11 +145,9 @@ module.exports.Component = registerComponent('look-controls', {
149145
canvasEl.removeEventListener('mouseout', this.onMouseUp);
150146

151147
// Touch events.
152-
if (this.data.touchEnabled) {
153-
canvasEl.removeEventListener('touchstart', this.onTouchStart);
154-
canvasEl.removeEventListener('touchmove', this.onTouchMove);
155-
canvasEl.removeEventListener('touchend', this.onTouchEnd);
156-
}
148+
canvasEl.removeEventListener('touchstart', this.onTouchStart);
149+
canvasEl.removeEventListener('touchmove', this.onTouchMove);
150+
canvasEl.removeEventListener('touchend', this.onTouchEnd);
157151
},
158152

159153
/**
@@ -318,7 +312,7 @@ module.exports.Component = registerComponent('look-controls', {
318312
* Register touch down to detect touch drag.
319313
*/
320314
onTouchStart: function (evt) {
321-
if (evt.touches.length !== 1) { return; }
315+
if (evt.touches.length !== 1 || !this.data.touchEnabled) { return; }
322316
this.touchStart = {
323317
x: evt.touches[0].pageX,
324318
y: evt.touches[0].pageY
@@ -334,7 +328,7 @@ module.exports.Component = registerComponent('look-controls', {
334328
var deltaY;
335329
var yawObject = this.yawObject;
336330

337-
if (!this.touchStarted) { return; }
331+
if (!this.touchStarted || !this.data.touchEnabled) { return; }
338332

339333
deltaY = 2 * Math.PI * (evt.touches[0].pageX - this.touchStart.x) / canvas.clientWidth;
340334

0 commit comments

Comments
 (0)