aframe-gamepad-controls
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -131,2 +131,9 @@ /******/ (function(modules) { // webpackBootstrap | ||
scene.addBehavior(this); | ||
if (!this.getGamepad()) { | ||
console.warn( | ||
'Gamepad #%d not found. Connect controller and press any button to continue.', | ||
this.data.controller | ||
); | ||
} | ||
}, | ||
@@ -221,3 +228,3 @@ | ||
updateRotation: function () { | ||
if (this.data.lookEnabled) { | ||
if (this.data.lookEnabled && this.getGamepad()) { | ||
var lookVector = this.getJoystick(1); | ||
@@ -224,0 +231,0 @@ if (Math.abs(lookVector.x) <= JOYSTICK_EPS) lookVector.x = 0; |
@@ -1,1 +0,1 @@ | ||
!function(t){function e(a){if(i[a])return i[a].exports;var o=i[a]={exports:{},id:a,loaded:!1};return t[a].call(o.exports,o,o.exports,e),o.loaded=!0,o.exports}var i={};return e.m=t,e.c=i,e.p="",e(0)}([function(t,e,i){!function(t){return t?void(t.aframeCore||t).registerComponent("gamepad-controls",i(1)):void console.error("Component attempted to register before AFRAME was available.")}(window.AFRAME)},function(t,e){var i=.2,a=Math.PI/2,o=.2;t.exports={dependencies:["proxy-controls"],schema:{controller:{"default":0,oneOf:[0,1,2,3]},enabled:{"default":!0},movementEnabled:{"default":!0},lookEnabled:{"default":!0},flyEnabled:{"default":!1},easing:{"default":20},acceleration:{"default":65},sensitivity:{"default":.04},pitchAxis:{"default":"x",oneOf:["x","y","z"]},yawAxis:{"default":"y",oneOf:["x","y","z"]},rollAxis:{"default":"z",oneOf:["x","y","z"]},debug:{"default":!1}},init:function(){var t=this.el.sceneEl;this.prevTime=Date.now(),this.velocity=new THREE.Vector3(0,0,0),this.direction=new THREE.Vector3(0,0,0),this.rotation=new THREE.Euler(0,0,0,"YXZ"),this.pitch=new THREE.Object3D,this.yaw=new THREE.Object3D,this.yaw.position.y=10,this.yaw.add(this.pitch),t.addBehavior(this)},update:function(t){this.updatePosition(!!t),this.updateRotation()},remove:function(){},updatePosition:function(t){var e=this.data,a=e.acceleration,n=e.easing,r=this.velocity,s=window.performance.now(),d=(s-this.prevTime)/1e3,c=e.rollAxis,h=e.pitchAxis,l=this.el,u=this.getGamepad();if(this.prevTime=s,t||d>i)return r[c]=0,void(r[h]=0);r[c]-=r[c]*n*d,r[h]-=r[h]*n*d;var p=l.getComputedAttribute("position");e.enabled&&e.movementEnabled&&u&&(Math.abs(this.getJoystick(0).x)>o&&(r[h]+=this.getJoystick(0).x*a*d),Math.abs(this.getJoystick(0).y)>o&&(r[c]+=this.getJoystick(0).y*a*d));var y=this.getMovementVector(d);l.object3D.translateX(y.x),l.object3D.translateY(y.y),l.object3D.translateZ(y.z),l.setAttribute("position",{x:p.x+y.x,y:p.y+y.y,z:p.z+y.z})},getMovementVector:function(t){var e=this.el.getAttribute("rotation");return this.direction.copy(this.velocity),this.direction.multiplyScalar(t),e?(this.data.flyEnabled||(e.x=0),this.rotation.set(THREE.Math.degToRad(e.x),THREE.Math.degToRad(e.y),0),this.direction.applyEuler(this.rotation),this.direction):this.direction},updateRotation:function(){if(this.data.lookEnabled){var t=this.getJoystick(1);Math.abs(t.x)<=o&&(t.x=0),Math.abs(t.y)<=o&&(t.y=0),t.multiplyScalar(this.data.sensitivity),this.yaw.rotation.y-=t.x,this.pitch.rotation.x-=t.y,this.pitch.rotation.x=Math.max(-a,Math.min(a,this.pitch.rotation.x)),this.el.setAttribute("rotation",{x:THREE.Math.radToDeg(this.pitch.rotation.x),y:THREE.Math.radToDeg(this.yaw.rotation.y),z:0})}},getGamepad:function(){return navigator.getGamepads()[this.data.controller]},getButton:function(t){return this.getGamepad().buttons[t]},getAxis:function(t){return this.getGamepad().axes[t]},getJoystick:function(t){var e=this.getGamepad();switch(t){case 0:return new THREE.Vector2(e.axes[0],e.axes[1]);case 1:return new THREE.Vector2(e.axes[2],e.axes[3]);default:throw new Error('Unexpected joystick index "%d".',t)}},isConnected:function(){return this.getGamepad().connected},getId:function(){return this.getGamepad().id}}}]); | ||
!function(t){function e(a){if(i[a])return i[a].exports;var o=i[a]={exports:{},id:a,loaded:!1};return t[a].call(o.exports,o,o.exports,e),o.loaded=!0,o.exports}var i={};return e.m=t,e.c=i,e.p="",e(0)}([function(t,e,i){!function(t){return t?void(t.aframeCore||t).registerComponent("gamepad-controls",i(1)):void console.error("Component attempted to register before AFRAME was available.")}(window.AFRAME)},function(t,e){var i=.2,a=Math.PI/2,o=.2;t.exports={dependencies:["proxy-controls"],schema:{controller:{"default":0,oneOf:[0,1,2,3]},enabled:{"default":!0},movementEnabled:{"default":!0},lookEnabled:{"default":!0},flyEnabled:{"default":!1},easing:{"default":20},acceleration:{"default":65},sensitivity:{"default":.04},pitchAxis:{"default":"x",oneOf:["x","y","z"]},yawAxis:{"default":"y",oneOf:["x","y","z"]},rollAxis:{"default":"z",oneOf:["x","y","z"]},debug:{"default":!1}},init:function(){var t=this.el.sceneEl;this.prevTime=Date.now(),this.velocity=new THREE.Vector3(0,0,0),this.direction=new THREE.Vector3(0,0,0),this.rotation=new THREE.Euler(0,0,0,"YXZ"),this.pitch=new THREE.Object3D,this.yaw=new THREE.Object3D,this.yaw.position.y=10,this.yaw.add(this.pitch),t.addBehavior(this),this.getGamepad()||console.warn("Gamepad #%d not found. Connect controller and press any button to continue.",this.data.controller)},update:function(t){this.updatePosition(!!t),this.updateRotation()},remove:function(){},updatePosition:function(t){var e=this.data,a=e.acceleration,n=e.easing,r=this.velocity,s=window.performance.now(),d=(s-this.prevTime)/1e3,c=e.rollAxis,h=e.pitchAxis,l=this.el,u=this.getGamepad();if(this.prevTime=s,t||d>i)return r[c]=0,void(r[h]=0);r[c]-=r[c]*n*d,r[h]-=r[h]*n*d;var p=l.getComputedAttribute("position");e.enabled&&e.movementEnabled&&u&&(Math.abs(this.getJoystick(0).x)>o&&(r[h]+=this.getJoystick(0).x*a*d),Math.abs(this.getJoystick(0).y)>o&&(r[c]+=this.getJoystick(0).y*a*d));var y=this.getMovementVector(d);l.object3D.translateX(y.x),l.object3D.translateY(y.y),l.object3D.translateZ(y.z),l.setAttribute("position",{x:p.x+y.x,y:p.y+y.y,z:p.z+y.z})},getMovementVector:function(t){var e=this.el.getAttribute("rotation");return this.direction.copy(this.velocity),this.direction.multiplyScalar(t),e?(this.data.flyEnabled||(e.x=0),this.rotation.set(THREE.Math.degToRad(e.x),THREE.Math.degToRad(e.y),0),this.direction.applyEuler(this.rotation),this.direction):this.direction},updateRotation:function(){if(this.data.lookEnabled&&this.getGamepad()){var t=this.getJoystick(1);Math.abs(t.x)<=o&&(t.x=0),Math.abs(t.y)<=o&&(t.y=0),t.multiplyScalar(this.data.sensitivity),this.yaw.rotation.y-=t.x,this.pitch.rotation.x-=t.y,this.pitch.rotation.x=Math.max(-a,Math.min(a,this.pitch.rotation.x)),this.el.setAttribute("rotation",{x:THREE.Math.radToDeg(this.pitch.rotation.x),y:THREE.Math.radToDeg(this.yaw.rotation.y),z:0})}},getGamepad:function(){return navigator.getGamepads()[this.data.controller]},getButton:function(t){return this.getGamepad().buttons[t]},getAxis:function(t){return this.getGamepad().axes[t]},getJoystick:function(t){var e=this.getGamepad();switch(t){case 0:return new THREE.Vector2(e.axes[0],e.axes[1]);case 1:return new THREE.Vector2(e.axes[2],e.axes[3]);default:throw new Error('Unexpected joystick index "%d".',t)}},isConnected:function(){return this.getGamepad().connected},getId:function(){return this.getGamepad().id}}}]); |
@@ -68,2 +68,9 @@ /** | ||
scene.addBehavior(this); | ||
if (!this.getGamepad()) { | ||
console.warn( | ||
'Gamepad #%d not found. Connect controller and press any button to continue.', | ||
this.data.controller | ||
); | ||
} | ||
}, | ||
@@ -158,3 +165,3 @@ | ||
updateRotation: function () { | ||
if (this.data.lookEnabled) { | ||
if (this.data.lookEnabled && this.getGamepad()) { | ||
var lookVector = this.getJoystick(1); | ||
@@ -161,0 +168,0 @@ if (Math.abs(lookVector.x) <= JOYSTICK_EPS) lookVector.x = 0; |
{ | ||
"name": "aframe-gamepad-controls", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Gamepad controls for A-Frame VR.", | ||
"main": "gamepad-controls.js", | ||
"scripts": { | ||
"dev": "budo examples/example.js --dir examples --port 8000 --live --open", | ||
"dev": "budo browser.js:bundle.js --dir examples --port 8000 --live --open", | ||
"dist": "webpack browser.js dist/aframe-gamepad-controls.js && webpack -p browser.js dist/aframe-gamepad-controls.min.js", | ||
"postpublish": "npm run dist", | ||
"test": "karma start ./tests/karma.conf.js", | ||
"preversion": "npm test", | ||
"version": "npm run dist && git add -A dist", | ||
@@ -40,20 +38,6 @@ "postversion": "git push && git push --tags" | ||
"devDependencies": { | ||
"aframe-core": "*", | ||
"browserify": "^12.0.1", | ||
"browserify-css": "^0.8.3", | ||
"budo": "^7.1.0", | ||
"chai": "^3.4.1", | ||
"chai-shallow-deep-equal": "^1.3.0", | ||
"ghpages": "0.0.3", | ||
"karma": "^0.13.15", | ||
"karma-browserify": "^4.4.2", | ||
"karma-chai-shallow-deep-equal": "0.0.4", | ||
"karma-firefox-launcher": "^0.1.7", | ||
"karma-mocha": "^0.2.1", | ||
"karma-mocha-reporter": "^1.1.3", | ||
"karma-sinon-chai": "^1.1.0", | ||
"lodash": "^3.10.1", | ||
"mocha": "^2.3.4", | ||
"webpack": "^1.12.9" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
121142
3
15
462