Skip to content

Commit cd58907

Browse files
author
Edan Kwan
committed
mobile optimization
1 parent 5c20599 commit cd58907

File tree

5 files changed

+23
-6
lines changed

5 files changed

+23
-6
lines changed

app/js/index.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/3d/simulator.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,13 @@ function update(dt) {
151151

152152
if(settings.speed || settings.dieSpeed) {
153153

154+
var r = 200;
155+
var h = 60;
156+
if(settings.isMobile) {
157+
r = 100;
158+
h = 40;
159+
}
160+
154161
var autoClearColor = _renderer.autoClearColor;
155162
var clearColor = _renderer.getClearColor().getHex();
156163
var clearAlpha = _renderer.getClearAlpha();
@@ -169,9 +176,9 @@ function update(dt) {
169176
} else {
170177
_followPointTime += dt * 0.001 * settings.speed;
171178
_followPoint.set(
172-
Math.cos(_followPointTime) * 200.0,
173-
Math.cos(_followPointTime * 4.0) * 60.0,
174-
Math.sin(_followPointTime * 2.0) * 200.0
179+
Math.cos(_followPointTime) * r,
180+
Math.cos(_followPointTime * 4.0) * h,
181+
Math.sin(_followPointTime * 2.0) * r
175182
);
176183
_positionShader.uniforms.mouse3d.value.lerp(_followPoint, 0.2);
177184
}

src/core/settings.js

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var keys = require('mout/object/keys');
33
var query = exports.query = parse(window.location.href.replace('#','?'));
44

55
exports.useStats = false;
6+
exports.isMobile = /(iPad|iPhone|Android)/i.test(navigator.userAgent);
67

78
var amountMap = {
89
'4k' : [64, 64, 0.29],

src/fallback/mobile.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
var isMobile = /(iPad|iPhone|Android)/i.test(navigator.userAgent);
1+
var settings = require('../core/settings');
22

33
exports.pass = pass;
44

55
var _callback;
66

77
function pass(func) {
8-
if(isMobile) {
8+
if(settings.isMobile) {
99
_callback = func;
1010
init();
1111
} else {

src/index.js

+9
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ function init() {
105105
_control.update();
106106

107107
_gui = new dat.GUI();
108+
109+
if(settings.isMobile) {
110+
_gui.close();
111+
_control.enabled = false;
112+
}
113+
108114
var simulatorGui = _gui.addFolder('Simulator');
109115
simulatorGui.add(settings.query, 'amount', settings.amountList).onChange(function(){
110116
if (confirm('It will restart the demo')) {
@@ -194,6 +200,9 @@ function _onKeyUp(evt) {
194200

195201
function _bindTouch(func) {
196202
return function (evt) {
203+
if(settings.isMobile && evt.preventDefault) {
204+
evt.preventDefault();
205+
}
197206
func(evt.changedTouches[0]);
198207
};
199208
}

0 commit comments

Comments
 (0)