Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

aframe-gamepad-controls

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aframe-gamepad-controls - npm Package Compare versions

Comparing version 0.1.2 to 0.2.0

15

dist/aframe-gamepad-controls.js

@@ -93,3 +93,3 @@ /******/ (function(modules) { // webpackBootstrap

movementEnabled: { default: true },
lookEnabled: { default: true },
lookEnabled: { default: 'auto', oneOf: ['auto', 'true', 'false']},
flyEnabled: { default: false },

@@ -234,3 +234,3 @@

updateRotation: function () {
if (this.data.lookEnabled && this.getGamepad()) {
if (this.isLookEnabled() && this.getGamepad()) {
var lookVector = this.getJoystick(1);

@@ -355,2 +355,13 @@ if (Math.abs(lookVector.x) <= JOYSTICK_EPS) lookVector.x = 0;

return this.getGamepad().id;
},
isLookEnabled: function () {
if (this.data.lookEnabled === 'true') return true;
// TODO: This isn't a reliable way to detect VR mode.
var isVRMode = document.fullscreen || document.mozFullScreen || document.webkitIsFullScreen,
hasLookControls = !!this.el.components['look-controls'];
// For 'auto', look-controls component takes priority in VR mode.
return !(this.data.lookEnabled === 'auto' && isVRMode && hasLookControls);
}

@@ -357,0 +368,0 @@

2

dist/aframe-gamepad-controls.min.js

@@ -1,1 +0,1 @@

!function(t){function e(o){if(i[o])return i[o].exports;var n=i[o]={exports:{},id:o,loaded:!1};return t[o].call(n.exports,n,n.exports,e),n.loaded=!0,n.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,i){var o=i(2),n=.2,a=Math.PI/2,s=.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),this.buttons={},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(),this.updateButtonState()},remove:function(){},updatePosition:function(t){var e=this.data,i=e.acceleration,o=e.easing,a=this.velocity,r=window.performance.now(),d=(r-this.prevTime)/1e3,h=e.rollAxis,c=e.pitchAxis,u=this.el,l=this.getGamepad();if(this.prevTime=r,t||d>n)return a[h]=0,void(a[c]=0);a[h]-=a[h]*o*d,a[c]-=a[c]*o*d;var p=u.getComputedAttribute("position");e.enabled&&e.movementEnabled&&l&&(Math.abs(this.getJoystick(0).x)>s&&(a[c]+=this.getJoystick(0).x*i*d),Math.abs(this.getJoystick(0).y)>s&&(a[h]+=this.getJoystick(0).y*i*d));var y=this.getMovementVector(d);u.object3D.translateX(y.x),u.object3D.translateY(y.y),u.object3D.translateZ(y.z),u.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)<=s&&(t.x=0),Math.abs(t.y)<=s&&(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})}},updateButtonState:function(){var t=this.getGamepad();if(this.data.enabled&&t)for(var e=0;e<t.buttons.length;e++)t.buttons[e].pressed&&!this.buttons[e]?this.emit(new o("gamepadbuttondown",e,t.buttons[e])):!t.buttons[e].pressed&&this.buttons[e]&&this.emit(new o("gamepadbuttonup",e,t.buttons[e])),this.buttons[e]=t.buttons[e].pressed;else Object.keys(this.buttons)&&(this.buttons={})},emit:function(t){this.el.emit(t.type,t),this.el.emit(t.type+":"+t.index,new o(t.type,t.index,t))},getGamepad:function(){var t=navigator.getGamepads()[this.data.controller],e=this.el.components["proxy-controls"],i=e&&e.isConnected()&&e.getGamepad(this.data.controller);return i||t},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(){var t=this.getGamepad();return!(!t||!t.connected)},getID:function(){return this.getGamepad().id}}},function(t,e){function i(t,e,i){this.type=t,this.index=e,this.pressed=i.pressed,this.value=i.value}t.exports=i}]);
!function(t){function e(o){if(i[o])return i[o].exports;var n=i[o]={exports:{},id:o,loaded:!1};return t[o].call(n.exports,n,n.exports,e),n.loaded=!0,n.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,i){var o=i(2),n=.2,a=Math.PI/2,s=.2;t.exports={dependencies:["proxy-controls"],schema:{controller:{"default":0,oneOf:[0,1,2,3]},enabled:{"default":!0},movementEnabled:{"default":!0},lookEnabled:{"default":"auto",oneOf:["auto","true","false"]},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),this.buttons={},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(),this.updateButtonState()},remove:function(){},updatePosition:function(t){var e=this.data,i=e.acceleration,o=e.easing,a=this.velocity,r=window.performance.now(),d=(r-this.prevTime)/1e3,u=e.rollAxis,c=e.pitchAxis,h=this.el,l=this.getGamepad();if(this.prevTime=r,t||d>n)return a[u]=0,void(a[c]=0);a[u]-=a[u]*o*d,a[c]-=a[c]*o*d;var p=h.getComputedAttribute("position");e.enabled&&e.movementEnabled&&l&&(Math.abs(this.getJoystick(0).x)>s&&(a[c]+=this.getJoystick(0).x*i*d),Math.abs(this.getJoystick(0).y)>s&&(a[u]+=this.getJoystick(0).y*i*d));var f=this.getMovementVector(d);h.object3D.translateX(f.x),h.object3D.translateY(f.y),h.object3D.translateZ(f.z),h.setAttribute("position",{x:p.x+f.x,y:p.y+f.y,z:p.z+f.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.isLookEnabled()&&this.getGamepad()){var t=this.getJoystick(1);Math.abs(t.x)<=s&&(t.x=0),Math.abs(t.y)<=s&&(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})}},updateButtonState:function(){var t=this.getGamepad();if(this.data.enabled&&t)for(var e=0;e<t.buttons.length;e++)t.buttons[e].pressed&&!this.buttons[e]?this.emit(new o("gamepadbuttondown",e,t.buttons[e])):!t.buttons[e].pressed&&this.buttons[e]&&this.emit(new o("gamepadbuttonup",e,t.buttons[e])),this.buttons[e]=t.buttons[e].pressed;else Object.keys(this.buttons)&&(this.buttons={})},emit:function(t){this.el.emit(t.type,t),this.el.emit(t.type+":"+t.index,new o(t.type,t.index,t))},getGamepad:function(){var t=navigator.getGamepads()[this.data.controller],e=this.el.components["proxy-controls"],i=e&&e.isConnected()&&e.getGamepad(this.data.controller);return i||t},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(){var t=this.getGamepad();return!(!t||!t.connected)},getID:function(){return this.getGamepad().id},isLookEnabled:function(){if("true"===this.data.lookEnabled)return!0;var t=document.fullscreen||document.mozFullScreen||document.webkitIsFullScreen,e=!!this.el.components["look-controls"];return!("auto"===this.data.lookEnabled&&t&&e)}}},function(t,e){function i(t,e,i){this.type=t,this.index=e,this.pressed=i.pressed,this.value=i.value}t.exports=i}]);

@@ -30,3 +30,3 @@ /**

movementEnabled: { default: true },
lookEnabled: { default: true },
lookEnabled: { default: 'auto', oneOf: ['auto', 'true', 'false']},
flyEnabled: { default: false },

@@ -171,3 +171,3 @@

updateRotation: function () {
if (this.data.lookEnabled && this.getGamepad()) {
if (this.isLookEnabled() && this.getGamepad()) {
var lookVector = this.getJoystick(1);

@@ -292,4 +292,15 @@ if (Math.abs(lookVector.x) <= JOYSTICK_EPS) lookVector.x = 0;

return this.getGamepad().id;
},
isLookEnabled: function () {
if (this.data.lookEnabled === 'true') return true;
// TODO: This isn't a reliable way to detect VR mode.
var isVRMode = document.fullscreen || document.mozFullScreen || document.webkitIsFullScreen,
hasLookControls = !!this.el.components['look-controls'];
// For 'auto', look-controls component takes priority in VR mode.
return !(this.data.lookEnabled === 'auto' && isVRMode && hasLookControls);
}
};
{
"name": "aframe-gamepad-controls",
"version": "0.1.2",
"version": "0.2.0",
"description": "Gamepad controls for A-Frame.",

@@ -5,0 +5,0 @@ "main": "gamepad-controls.js",

@@ -74,2 +74,6 @@ # A-Frame `gamepad-controls` Component

## Mobile / Cardboard + Gamepad
In Chrome on Android, USB gamepads can be connected with an OTG adapter. For a Nexus 5X, I use [this](http://www.amazon.com/gp/product/B00XHOGEZG). I'm not aware of a way to connect a gamepad in iOS, but definitely let me know if there's something I'm missing.
## Button Events

@@ -119,4 +123,4 @@

movementEnabled | true | Enables movement via the left thumbstick.
lookEnabled | true | Enables view rotation via the right thumbstick.
lookEnabled | auto | `auto`, `true`, or `false`. Enables view rotation via the right thumbstick. With `auto`, view rotation is disabled in VR mode if a `look-controls` component is active.
flyEnabled | false | Whether or not movement is restricted to the entity’s initial plane.
debug | false | When true, shows debugging info in the console.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc