Merge pull request #23 from baleboy/touch-default

If the device supports touch input, set default controls to TOUCH
This commit is contained in:
Thibaut Despoulain
2014-08-22 11:09:02 -07:00
4 changed files with 82 additions and 58 deletions
+8
View File
@@ -175,6 +175,14 @@ class Utils
return req
###
Checks whether the device supports Touch input
###
@isTouchDevice: ()->
return ('ontouchstart' of window) or
(navigator.MaxTouchPoints > 0) or
(navigator.msMaxTouchPoints > 0)
###
Exports
+64 -54
View File
@@ -1,42 +1,41 @@
// Generated by CoffeeScript 1.4.0
// Generated by CoffeeScript 1.7.1
/*
Various useful methods
@class bkcore.Utils
@author Thibaut 'BKcore' Despoulain <http://bkcore.com>
*/
*/
(function() {
var Utils, exports;
Utils = (function() {
/*
Creates a bkcore.threejs.Shaders["normalV"|"normal"] material
with given parameters
*/
/*
Creates a bkcore.threejs.Shaders["normalV"|"normal"] material
with given parameters
*/
function Utils() {}
Utils.createNormalMaterial = function(opts) {
var material, parameters, shader, shadername, uniforms, _ref, _ref1, _ref2, _ref3, _ref4;
var material, parameters, shader, shadername, uniforms;
if (opts == null) {
opts = {};
}
if ((_ref = opts.ambient) == null) {
if (opts.ambient == null) {
opts.ambient = 0x444444;
}
if ((_ref1 = opts.normalScale) == null) {
if (opts.normalScale == null) {
opts.normalScale = 1.0;
}
if ((_ref2 = opts.reflectivity) == null) {
if (opts.reflectivity == null) {
opts.reflectivity = 0.9;
}
if ((_ref3 = opts.shininess) == null) {
if (opts.shininess == null) {
opts.shininess = 42;
}
if ((_ref4 = opts.metal) == null) {
if (opts.metal == null) {
opts.metal = false;
}
shadername = opts.perPixel ? "normalV" : "normal";
@@ -68,13 +67,13 @@
return material;
};
/*
Projects an object origin vector to screen using given camera
@param THREE.Object3D object The object which origin you want to project
@param THREE.Camera camera The camera of the projection
@return THEE.Vector3 Projected verctor
*/
/*
Projects an object origin vector to screen using given camera
@param THREE.Object3D object The object which origin you want to project
@param THREE.Camera camera The camera of the projection
@return THEE.Vector3 Projected verctor
*/
Utils.projectOnScreen = function(object, camera) {
var c, lPos, mat;
@@ -86,31 +85,32 @@
return lPos.multiplyScalar(0.5).addScalar(0.5);
};
/*
Get an url parameter
@param String name Parameter slug
@return Mixed
*/
/*
Get an url parameter
@param String name Parameter slug
@return Mixed
*/
Utils.URLParameters = null;
Utils.getURLParameter = function(name) {
var _this = this;
if (!(this.URLParameters != null)) {
if (this.URLParameters == null) {
this.URLParameters = {};
window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m, key, val) {
return _this.URLParameters[key] = val;
});
window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, (function(_this) {
return function(m, key, val) {
return _this.URLParameters[key] = val;
};
})(this));
}
return this.URLParameters[name];
};
/*
Get top offset of an element
@param obj HTMLElement
*/
/*
Get top offset of an element
@param obj HTMLElement
*/
Utils.getOffsetTop = function(obj) {
var curtop;
@@ -123,23 +123,23 @@
return curtop;
};
/*
Scrolls page to given element id
@param string id The ID of the element
*/
/*
Scrolls page to given element id
@param string id The ID of the element
*/
Utils.scrollTo = function(id) {
return window.scroll(0, this.getOffsetTop(document.getElementById(id)));
};
/*
Add or remove a class from an element
@param string id [description]
@param string cssclass [description]
@param bool active [description]
*/
/*
Add or remove a class from an element
@param string id [description]
@param string cssclass [description]
@param bool active [description]
*/
Utils.updateClass = function(id, cssclass, active) {
var e;
@@ -154,14 +154,14 @@
}
};
/*
Performs an XMLHttpRequest
@param string url [description]
@param bool postData true = POST, false = GET
@param {Function} callback [description]
@param {Object} data [description]
*/
/*
Performs an XMLHttpRequest
@param string url [description]
@param bool postData true = POST, false = GET
@param {Function} callback [description]
@param {Object} data [description]
*/
Utils.request = function(url, postData, callback, data) {
var XMLHttpFactories, createXMLHTTPObject, i, method, qdata, req, val;
@@ -177,12 +177,13 @@
}
];
createXMLHTTPObject = function() {
var i, xmlhttp, _i, _ref;
var e, i, xmlhttp, _i, _ref;
xmlhttp = false;
for (i = _i = 0, _ref = XMLHttpFactories.length; 0 <= _ref ? _i <= _ref : _i >= _ref; i = 0 <= _ref ? ++_i : --_i) {
try {
xmlhttp = XMLHttpFactories[i]();
} catch (e) {
} catch (_error) {
e = _error;
continue;
}
break;
@@ -221,15 +222,24 @@
return req;
};
/*
Checks whether the device supports Touch input
*/
Utils.isTouchDevice = function() {
return ('ontouchstart' in window) || (navigator.MaxTouchPoints > 0) || (navigator.msMaxTouchPoints > 0);
};
return Utils;
})();
/*
Exports
@package bkcore
*/
*/
exports = exports != null ? exports : this;
+5 -1
View File
@@ -33,8 +33,12 @@ init = (controlType, quality, hud, godmode) ->
)
u = bkcore.Utils.getURLParameter
defaultControls = if bkcore.Utils.isTouchDevice() then 1 else 0
s = [
['controlType', ['KEYBOARD', 'TOUCH', 'LEAP MOTION CONTROLLER', 'GAMEPAD'], 0, 0, 'Controls: ']
['controlType', ['KEYBOARD', 'TOUCH', 'LEAP MOTION CONTROLLER',
'GAMEPAD'], defaultControls, defaultControls, 'Controls: ']
['quality', ['LOW', 'MID', 'HIGH', 'VERY HIGH'], 3, 3, 'Quality: ']
['hud', ['OFF', 'ON'], 1, 1, 'HUD: ']
['godmode', ['OFF', 'ON'], 0, 1, 'Godmode: ']
+5 -3
View File
@@ -1,6 +1,6 @@
// Generated by CoffeeScript 1.6.3
// Generated by CoffeeScript 1.7.1
(function() {
var $, a, getWebGL, hasWebGL, init, s, u, _fn, _i, _len;
var $, a, defaultControls, getWebGL, hasWebGL, init, s, u, _fn, _i, _len;
$ = function(_) {
return document.getElementById(_);
@@ -44,7 +44,9 @@
u = bkcore.Utils.getURLParameter;
s = [['controlType', ['KEYBOARD', 'TOUCH', 'LEAP MOTION CONTROLLER', 'GAMEPAD'], 0, 0, 'Controls: '], ['quality', ['LOW', 'MID', 'HIGH', 'VERY HIGH'], 3, 3, 'Quality: '], ['hud', ['OFF', 'ON'], 1, 1, 'HUD: '], ['godmode', ['OFF', 'ON'], 0, 1, 'Godmode: ']];
defaultControls = bkcore.Utils.isTouchDevice() ? 1 : 0;
s = [['controlType', ['KEYBOARD', 'TOUCH', 'LEAP MOTION CONTROLLER', 'GAMEPAD'], defaultControls, defaultControls, 'Controls: '], ['quality', ['LOW', 'MID', 'HIGH', 'VERY HIGH'], 3, 3, 'Quality: '], ['hud', ['OFF', 'ON'], 1, 1, 'HUD: '], ['godmode', ['OFF', 'ON'], 0, 1, 'Godmode: ']];
_fn = function(a) {
var e, f, _ref;