aframe-keyboard-controls
Advanced tools
Comparing version 0.2.4 to 1.0.0
@@ -66,3 +66,3 @@ /******/ (function(modules) { // webpackBootstrap | ||
var MAX_DELTA = 0.2, | ||
var MAX_DELTA = 200, | ||
PROXY_FLAG = '__keyboard-controls-proxy'; | ||
@@ -114,8 +114,3 @@ | ||
}; | ||
var sceneEl = this.el.sceneEl; | ||
if (sceneEl.addBehavior) { | ||
sceneEl.addBehavior(this); | ||
this.attachEventListeners(); | ||
} | ||
this.attachEventListeners(); | ||
}, | ||
@@ -127,5 +122,3 @@ | ||
tick: function () { this.update(); }, | ||
update: function (previousData) { | ||
tick: function (t, dt) { | ||
var data = this.data; | ||
@@ -135,5 +128,2 @@ var acceleration = data.acceleration; | ||
var velocity = this.velocity; | ||
var prevTime = this.prevTime = this.prevTime || Date.now(); | ||
var time = window.performance.now(); | ||
var delta = (time - prevTime) / 1000; | ||
var keys = this.getKeys(); | ||
@@ -146,6 +136,5 @@ var movementVector; | ||
var el = this.el; | ||
this.prevTime = time; | ||
// If data changed or FPS too low, reset velocity. | ||
if (previousData || delta > MAX_DELTA) { | ||
if (isNaN(dt) || dt > MAX_DELTA) { | ||
velocity[pitchAxis] = 0; | ||
@@ -156,4 +145,4 @@ velocity[rollAxis] = 0; | ||
velocity[pitchAxis] -= velocity[pitchAxis] * easing * delta; | ||
velocity[rollAxis] -= velocity[rollAxis] * easing * delta; | ||
velocity[pitchAxis] -= velocity[pitchAxis] * easing * dt / 1000; | ||
velocity[rollAxis] -= velocity[rollAxis] * easing * dt / 1000; | ||
@@ -165,6 +154,6 @@ var position = el.getComputedAttribute('position'); | ||
if (keys.KeyA || keys.ArrowLeft) { | ||
velocity[pitchAxis] -= pitchSign * acceleration * delta; | ||
velocity[pitchAxis] -= pitchSign * acceleration * dt / 1000; | ||
} | ||
if (keys.KeyD || keys.ArrowRight) { | ||
velocity[pitchAxis] += pitchSign * acceleration * delta; | ||
velocity[pitchAxis] += pitchSign * acceleration * dt / 1000; | ||
} | ||
@@ -174,6 +163,6 @@ } | ||
if (keys.KeyW || keys.ArrowUp) { | ||
velocity[rollAxis] -= rollSign * acceleration * delta; | ||
velocity[rollAxis] -= rollSign * acceleration * dt / 1000; | ||
} | ||
if (keys.KeyS || keys.ArrowDown) { | ||
velocity[rollAxis] += rollSign * acceleration * delta; | ||
velocity[rollAxis] += rollSign * acceleration * dt / 1000; | ||
} | ||
@@ -183,3 +172,3 @@ } | ||
movementVector = this.getMovementVector(delta); | ||
movementVector = this.getMovementVector(dt); | ||
el.object3D.translateX(movementVector.x); | ||
@@ -196,10 +185,10 @@ el.object3D.translateY(movementVector.y); | ||
getMovementVector: (function (delta) { | ||
getMovementVector: (function () { | ||
var direction = new THREE.Vector3(0, 0, 0); | ||
var rotation = new THREE.Euler(0, 0, 0, 'YXZ'); | ||
return function (delta) { | ||
return function (dt) { | ||
var velocity = this.velocity; | ||
var elRotation = this.el.getAttribute('rotation'); | ||
direction.copy(velocity); | ||
direction.multiplyScalar(delta); | ||
direction.multiplyScalar(dt / 1000); | ||
if (!elRotation) { return direction; } | ||
@@ -226,6 +215,2 @@ if (!this.data.fly) { elRotation.x = 0; } | ||
tick: function (t) { // jshint ignore:line | ||
this.update(); | ||
}, | ||
remove: function () { | ||
@@ -283,3 +268,3 @@ this.pause(); | ||
*/ | ||
isPressed: function (code) { | ||
@@ -286,0 +271,0 @@ return code in this.getKeys(); |
@@ -1,1 +0,1 @@ | ||
!function(e){function o(i){if(t[i])return t[i].exports;var c=t[i]={exports:{},id:i,loaded:!1};return e[i].call(c.exports,c,c.exports,o),c.loaded=!0,c.exports}var t={};return o.m=e,o.c=t,o.p="",o(0)}([function(e,o,t){!function(e){return e?void(e.aframeCore||e).registerComponent("keyboard-controls",t(1)):void console.error("Component attempted to register before AFRAME was available.")}(window.AFRAME)},function(e,o,t){t(2);var i=.2,c="__keyboard-controls-proxy",a=window.KeyboardEvent;e.exports={schema:{easing:{"default":20},acceleration:{"default":65},enabled:{"default":!0},fly:{"default":!1},rollAxis:{"default":"z",oneOf:["x","y","z"]},pitchAxis:{"default":"x",oneOf:["x","y","z"]},rollAxisInverted:{"default":!1},rollAxisEnabled:{"default":!0},pitchAxisInverted:{"default":!1},pitchAxisEnabled:{"default":!0},debug:{"default":!1}},init:function(){this.velocity=new THREE.Vector3,this.localKeys={},this.listeners={keydown:this.onKeyDown.bind(this),keyup:this.onKeyUp.bind(this),blur:this.onBlur.bind(this)};var e=this.el.sceneEl;e.addBehavior&&(e.addBehavior(this),this.attachEventListeners())},tick:function(){this.update()},update:function(e){var o,t=this.data,c=t.acceleration,a=t.easing,n=this.velocity,d=this.prevTime=this.prevTime||Date.now(),r=window.performance.now(),y=(r-d)/1e3,l=this.getKeys(),s=t.pitchAxis,p=t.rollAxis,k=t.pitchAxisInverted?-1:1,u=t.rollAxisInverted?-1:1,h=this.el;if(this.prevTime=r,e||y>i)return n[s]=0,void(n[p]=0);n[s]-=n[s]*a*y,n[p]-=n[p]*a*y;var f=h.getComputedAttribute("position");t.enabled&&(t.pitchAxisEnabled&&((l.KeyA||l.ArrowLeft)&&(n[s]-=k*c*y),(l.KeyD||l.ArrowRight)&&(n[s]+=k*c*y)),t.rollAxisEnabled&&((l.KeyW||l.ArrowUp)&&(n[p]-=u*c*y),(l.KeyS||l.ArrowDown)&&(n[p]+=u*c*y))),o=this.getMovementVector(y),h.object3D.translateX(o.x),h.object3D.translateY(o.y),h.object3D.translateZ(o.z),h.setAttribute("position",{x:f.x+o.x,y:f.y+o.y,z:f.z+o.z})},getMovementVector:function(e){var o=new THREE.Vector3(0,0,0),t=new THREE.Euler(0,0,0,"YXZ");return function(e){var i=this.velocity,c=this.el.getAttribute("rotation");return o.copy(i),o.multiplyScalar(e),c?(this.data.fly||(c.x=0),t.set(THREE.Math.degToRad(c.x),THREE.Math.degToRad(c.y),0),o.applyEuler(t),o):o}}(),play:function(){this.attachEventListeners()},pause:function(){this.removeEventListeners()},tick:function(e){this.update()},remove:function(){this.pause()},attachEventListeners:function(){window.addEventListener("keydown",this.listeners.keydown,!1),window.addEventListener("keyup",this.listeners.keyup,!1),window.addEventListener("blur",this.listeners.blur,!1)},removeEventListeners:function(){window.removeEventListener("keydown",this.listeners.keydown),window.removeEventListener("keyup",this.listeners.keyup),window.removeEventListener("blur",this.listeners.blur)},onKeyDown:function(e){this.localKeys[e.code]=!0,this.emit(e)},onKeyUp:function(e){delete this.localKeys[e.code],this.emit(e)},onBlur:function(){for(var e in this.localKeys)this.localKeys.hasOwnProperty(e)&&delete this.localKeys[e]},emit:function(e){c in e&&this.el.emit(e.type,e),this.el.emit(e.type+":"+e.code,new a(e.type,e)),this.data.debug&&console.log(e.type+":"+e.code)},isPressed:function(e){return e in this.getKeys()},getKeys:function(){return this.isProxied()?this.el.sceneEl.components["proxy-controls"].getKeyboard():this.localKeys},isProxied:function(){var e=this.el.sceneEl.components["proxy-controls"];return e&&e.isConnected()}}},function(e,o){!function(e){function o(e,o){return-1!==String(e).indexOf(o)}function t(e,o,t){(k===o||p===o||s===o)&&Object.keys(t).forEach(function(o){e[o]=t[o]})}function i(e,o){var t={};return Object.keys(e).forEach(function(i){var c=e[i];o in c&&(t[c[o]]=c)}),t}function c(e){var o="keyCode"in e?e.keyCode:"which"in e?e.which:0,t=function(){if(v||"keyLocation"in e){var t=v?e.location:e.keyLocation;if(t&&o in f[t])return f[t][o]}return"keyIdentifier"in e&&e.keyIdentifier in h?h[e.keyIdentifier]:o in u?u[o]:null}();if(!t)return null;var i=function(){var o=K[t.code];return o?e.shiftKey&&"shiftKey"in o?o.shiftKey:o.key:t.code}();return{code:t.code,key:i,location:t.location,keyCap:t.keyCap}}function a(e,o){if(e=String(e),!m.hasOwnProperty(e))return"Undefined";if(o&&"en-us"!==String(o).toLowerCase())throw Error("Unsupported locale");var t=m[e];return t.keyCap||t.code||"Undefined"}var n="KeyboardEvent"in e;n||(e.KeyboardEvent=function(){throw TypeError("Illegal constructor")}),e.KeyboardEvent.DOM_KEY_LOCATION_STANDARD=0,e.KeyboardEvent.DOM_KEY_LOCATION_LEFT=1,e.KeyboardEvent.DOM_KEY_LOCATION_RIGHT=2,e.KeyboardEvent.DOM_KEY_LOCATION_NUMPAD=3;var d=window.KeyboardEvent.DOM_KEY_LOCATION_STANDARD,r=window.KeyboardEvent.DOM_KEY_LOCATION_LEFT,y=window.KeyboardEvent.DOM_KEY_LOCATION_RIGHT,l=window.KeyboardEvent.DOM_KEY_LOCATION_NUMPAD,s=function(){return o(navigator.platform,"Win")?"win":o(navigator.platform,"Mac")?"mac":o(navigator.platform,"CrOS")?"cros":o(navigator.platform,"Linux")?"linux":o(navigator.userAgent,"iPad")||o(navigator.platform,"iPod")||o(navigator.platform,"iPhone")?"ios":""}(),p=function(){return o(navigator.userAgent,"Chrome/")?"chrome":o(navigator.vendor,"Apple")?"safari":o(navigator.userAgent,"MSIE")?"ie":o(navigator.userAgent,"Gecko/")?"moz":o(navigator.userAgent,"Opera/")?"opera":""}(),k=p+"-"+s,u={3:{code:"Cancel"},6:{code:"Help"},8:{code:"Backspace"},9:{code:"Tab"},12:{code:"Clear"},13:{code:"Enter"},16:{code:"Shift"},17:{code:"Control"},18:{code:"Alt"},19:{code:"Pause"},20:{code:"CapsLock"},21:{code:"KanaMode"},22:{code:"HangulMode"},23:{code:"JunjaMode"},24:{code:"FinalMode"},25:{code:"KanjiMode"},27:{code:"Escape"},28:{code:"Convert"},29:{code:"NonConvert"},30:{code:"Accept"},31:{code:"ModeChange"},32:{code:"Space"},33:{code:"PageUp"},34:{code:"PageDown"},35:{code:"End"},36:{code:"Home"},37:{code:"ArrowLeft"},38:{code:"ArrowUp"},39:{code:"ArrowRight"},40:{code:"ArrowDown"},41:{code:"Select"},42:{code:"Print"},43:{code:"Execute"},44:{code:"PrintScreen"},45:{code:"Insert"},46:{code:"Delete"},47:{code:"Help"},48:{code:"Digit0",keyCap:"0"},49:{code:"Digit1",keyCap:"1"},50:{code:"Digit2",keyCap:"2"},51:{code:"Digit3",keyCap:"3"},52:{code:"Digit4",keyCap:"4"},53:{code:"Digit5",keyCap:"5"},54:{code:"Digit6",keyCap:"6"},55:{code:"Digit7",keyCap:"7"},56:{code:"Digit8",keyCap:"8"},57:{code:"Digit9",keyCap:"9"},65:{code:"KeyA",keyCap:"a"},66:{code:"KeyB",keyCap:"b"},67:{code:"KeyC",keyCap:"c"},68:{code:"KeyD",keyCap:"d"},69:{code:"KeyE",keyCap:"e"},70:{code:"KeyF",keyCap:"f"},71:{code:"KeyG",keyCap:"g"},72:{code:"KeyH",keyCap:"h"},73:{code:"KeyI",keyCap:"i"},74:{code:"KeyJ",keyCap:"j"},75:{code:"KeyK",keyCap:"k"},76:{code:"KeyL",keyCap:"l"},77:{code:"KeyM",keyCap:"m"},78:{code:"KeyN",keyCap:"n"},79:{code:"KeyO",keyCap:"o"},80:{code:"KeyP",keyCap:"p"},81:{code:"KeyQ",keyCap:"q"},82:{code:"KeyR",keyCap:"r"},83:{code:"KeyS",keyCap:"s"},84:{code:"KeyT",keyCap:"t"},85:{code:"KeyU",keyCap:"u"},86:{code:"KeyV",keyCap:"v"},87:{code:"KeyW",keyCap:"w"},88:{code:"KeyX",keyCap:"x"},89:{code:"KeyY",keyCap:"y"},90:{code:"KeyZ",keyCap:"z"},91:{code:"OSLeft",location:r},92:{code:"OSRight",location:y},93:{code:"ContextMenu"},95:{code:"Standby"},96:{code:"Numpad0",keyCap:"0",location:l},97:{code:"Numpad1",keyCap:"1",location:l},98:{code:"Numpad2",keyCap:"2",location:l},99:{code:"Numpad3",keyCap:"3",location:l},100:{code:"Numpad4",keyCap:"4",location:l},101:{code:"Numpad5",keyCap:"5",location:l},102:{code:"Numpad6",keyCap:"6",location:l},103:{code:"Numpad7",keyCap:"7",location:l},104:{code:"Numpad8",keyCap:"8",location:l},105:{code:"Numpad9",keyCap:"9",location:l},106:{code:"NumpadMultiply",keyCap:"*",location:l},107:{code:"NumpadAdd",keyCap:"+",location:l},108:{code:"NumpadComma",keyCap:",",location:l},109:{code:"NumpadSubtract",keyCap:"-",location:l},110:{code:"NumpadDecimal",keyCap:".",location:l},111:{code:"NumpadDivide",keyCap:"/",location:l},112:{code:"F1"},113:{code:"F2"},114:{code:"F3"},115:{code:"F4"},116:{code:"F5"},117:{code:"F6"},118:{code:"F7"},119:{code:"F8"},120:{code:"F9"},121:{code:"F10"},122:{code:"F11"},123:{code:"F12"},124:{code:"F13"},125:{code:"F14"},126:{code:"F15"},127:{code:"F16"},128:{code:"F17"},129:{code:"F18"},130:{code:"F19"},131:{code:"F20"},132:{code:"F21"},133:{code:"F22"},134:{code:"F23"},135:{code:"F24"},144:{code:"NumLock",location:l},145:{code:"ScrollLock"},160:{code:"ShiftLeft",location:r},161:{code:"ShiftRight",location:y},162:{code:"ControlLeft",location:r},163:{code:"ControlRight",location:y},164:{code:"AltLeft",location:r},165:{code:"AltRight",location:y},166:{code:"BrowserBack"},167:{code:"BrowserForward"},168:{code:"BrowserRefresh"},169:{code:"BrowserStop"},170:{code:"BrowserSearch"},171:{code:"BrowserFavorites"},172:{code:"BrowserHome"},173:{code:"VolumeMute"},174:{code:"VolumeDown"},175:{code:"VolumeUp"},176:{code:"MediaTrackNext"},177:{code:"MediaTrackPrevious"},178:{code:"MediaStop"},179:{code:"MediaPlayPause"},180:{code:"LaunchMail"},181:{code:"MediaSelect"},182:{code:"LaunchApp1"},183:{code:"LaunchApp2"},186:{code:"Semicolon",keyCap:";"},187:{code:"Equal",keyCap:"="},188:{code:"Comma",keyCap:","},189:{code:"Minus",keyCap:"-"},190:{code:"Period",keyCap:"."},191:{code:"Slash",keyCap:"/"},192:{code:"Backquote",keyCap:"`"},219:{code:"BracketLeft",keyCap:"["},220:{code:"Backslash",keyCap:"\\"},221:{code:"BracketRight",keyCap:"]"},222:{code:"Quote",keyCap:"'"},226:{code:"IntlBackslash",keyCap:"\\"},229:{code:"Process"},246:{code:"Attn"},247:{code:"CrSel"},248:{code:"ExSel"},249:{code:"EraseEof"},250:{code:"Play"},251:{code:"ZoomToggle"},254:{code:"Clear"}};t(u,"moz",{59:{code:"Semicolon",keyCap:";"},61:{code:"Equal",keyCap:"="},107:{code:"Equal",keyCap:"="},109:{code:"Minus",keyCap:"-"},187:{code:"NumpadAdd",keyCap:"+",location:l},189:{code:"NumpadSubtract",keyCap:"-",location:l}}),t(u,"moz-mac",{12:{code:"NumLock",location:l},173:{code:"Minus",keyCap:"-"}}),t(u,"moz-win",{173:{code:"Minus",keyCap:"-"}}),t(u,"chrome-mac",{93:{code:"OSRight",location:y}}),t(u,"safari",{3:{code:"Enter"},25:{code:"Tab"}}),t(u,"ios",{10:{code:"Enter",location:d}}),t(u,"safari-mac",{91:{code:"OSLeft",location:r},93:{code:"OSRight",location:y},229:{code:"KeyQ",keyCap:"Q"}});var h={};"cros"===s&&(h["U+00A0"]={code:"ShiftLeft",location:r},h["U+00A1"]={code:"ShiftRight",location:y},h["U+00A2"]={code:"ControlLeft",location:r},h["U+00A3"]={code:"ControlRight",location:y},h["U+00A4"]={code:"AltLeft",location:r},h["U+00A5"]={code:"AltRight",location:y}),"chrome-mac"===k&&(h["U+0010"]={code:"ContextMenu"}),"safari-mac"===k&&(h["U+0010"]={code:"ContextMenu"}),"ios"===s&&(h["U+0010"]={code:"Function"},h["U+001C"]={code:"ArrowLeft"},h["U+001D"]={code:"ArrowRight"},h["U+001E"]={code:"ArrowUp"},h["U+001F"]={code:"ArrowDown"},h["U+0001"]={code:"Home"},h["U+0004"]={code:"End"},h["U+000B"]={code:"PageUp"},h["U+000C"]={code:"PageDown"});var f=[];f[r]={16:{code:"ShiftLeft",location:r},17:{code:"ControlLeft",location:r},18:{code:"AltLeft",location:r}},f[y]={16:{code:"ShiftRight",location:y},17:{code:"ControlRight",location:y},18:{code:"AltRight",location:y}},f[l]={13:{code:"NumpadEnter",location:l}},t(f[l],"moz",{109:{code:"NumpadSubtract",location:l},107:{code:"NumpadAdd",location:l}}),t(f[r],"moz-mac",{224:{code:"OSLeft",location:r}}),t(f[y],"moz-mac",{224:{code:"OSRight",location:y}}),t(f[y],"moz-win",{91:{code:"OSRight",location:y}}),t(f[y],"mac",{93:{code:"OSRight",location:y}}),t(f[l],"chrome-mac",{12:{code:"NumLock",location:l}}),t(f[l],"safari-mac",{12:{code:"NumLock",location:l},187:{code:"NumpadAdd",location:l},189:{code:"NumpadSubtract",location:l},190:{code:"NumpadDecimal",location:l},191:{code:"NumpadDivide",location:l}});var K={ShiftLeft:{key:"Shift"},ShiftRight:{key:"Shift"},ControlLeft:{key:"Control"},ControlRight:{key:"Control"},AltLeft:{key:"Alt"},AltRight:{key:"Alt"},OSLeft:{key:"OS"},OSRight:{key:"OS"},NumpadEnter:{key:"Enter"},Space:{key:" "},Digit0:{key:"0",shiftKey:")"},Digit1:{key:"1",shiftKey:"!"},Digit2:{key:"2",shiftKey:"@"},Digit3:{key:"3",shiftKey:"#"},Digit4:{key:"4",shiftKey:"$"},Digit5:{key:"5",shiftKey:"%"},Digit6:{key:"6",shiftKey:"^"},Digit7:{key:"7",shiftKey:"&"},Digit8:{key:"8",shiftKey:"*"},Digit9:{key:"9",shiftKey:"("},KeyA:{key:"a",shiftKey:"A"},KeyB:{key:"b",shiftKey:"B"},KeyC:{key:"c",shiftKey:"C"},KeyD:{key:"d",shiftKey:"D"},KeyE:{key:"e",shiftKey:"E"},KeyF:{key:"f",shiftKey:"F"},KeyG:{key:"g",shiftKey:"G"},KeyH:{key:"h",shiftKey:"H"},KeyI:{key:"i",shiftKey:"I"},KeyJ:{key:"j",shiftKey:"J"},KeyK:{key:"k",shiftKey:"K"},KeyL:{key:"l",shiftKey:"L"},KeyM:{key:"m",shiftKey:"M"},KeyN:{key:"n",shiftKey:"N"},KeyO:{key:"o",shiftKey:"O"},KeyP:{key:"p",shiftKey:"P"},KeyQ:{key:"q",shiftKey:"Q"},KeyR:{key:"r",shiftKey:"R"},KeyS:{key:"s",shiftKey:"S"},KeyT:{key:"t",shiftKey:"T"},KeyU:{key:"u",shiftKey:"U"},KeyV:{key:"v",shiftKey:"V"},KeyW:{key:"w",shiftKey:"W"},KeyX:{key:"x",shiftKey:"X"},KeyY:{key:"y",shiftKey:"Y"},KeyZ:{key:"z",shiftKey:"Z"},Numpad0:{key:"0"},Numpad1:{key:"1"},Numpad2:{key:"2"},Numpad3:{key:"3"},Numpad4:{key:"4"},Numpad5:{key:"5"},Numpad6:{key:"6"},Numpad7:{key:"7"},Numpad8:{key:"8"},Numpad9:{key:"9"},NumpadMultiply:{key:"*"},NumpadAdd:{key:"+"},NumpadComma:{key:","},NumpadSubtract:{key:"-"},NumpadDecimal:{key:"."},NumpadDivide:{key:"/"},Semicolon:{key:";",shiftKey:":"},Equal:{key:"=",shiftKey:"+"},Comma:{key:",",shiftKey:"<"},Minus:{key:"-",shiftKey:"_"},Period:{key:".",shiftKey:">"},Slash:{key:"/",shiftKey:"?"},Backquote:{key:"`",shiftKey:"~"},BracketLeft:{key:"[",shiftKey:"{"},Backslash:{key:"\\",shiftKey:"|"},BracketRight:{key:"]",shiftKey:"}"},Quote:{key:"'",shiftKey:'"'},IntlBackslash:{key:"\\",shiftKey:"|"}};t(K,"mac",{OSLeft:{key:"Meta"},OSRight:{key:"Meta"}});var C={Esc:"Escape",Nonconvert:"NonConvert",Left:"ArrowLeft",Up:"ArrowUp",Right:"ArrowRight",Down:"ArrowDown",Del:"Delete",Menu:"ContextMenu",MediaNextTrack:"MediaTrackNext",MediaPreviousTrack:"MediaTrackPrevious",SelectMedia:"MediaSelect",HalfWidth:"Hankaku",FullWidth:"Zenkaku",RomanCharacters:"Romaji",Crsel:"CrSel",Exsel:"ExSel",Zoom:"ZoomToggle"},m=i(u,"code");try{var v=n&&"location"in new KeyboardEvent("")}catch(g){}"KeyboardEvent"in e&&"defineProperty"in Object&&!function(){function e(e,o,t){o in e||Object.defineProperty(e,o,t)}if(e(KeyboardEvent.prototype,"code",{get:function(){var e=c(this);return e?e.code:""}}),"key"in KeyboardEvent.prototype){var o=Object.getOwnPropertyDescriptor(KeyboardEvent.prototype,"key");Object.defineProperty(KeyboardEvent.prototype,"key",{get:function(){var e=o.get.call(this);return C.hasOwnProperty(e)?C[e]:e}})}e(KeyboardEvent.prototype,"key",{get:function(){var e=c(this);return e&&"key"in e?e.key:"Unidentified"}}),e(KeyboardEvent.prototype,"location",{get:function(){var e=c(this);return e&&"location"in e?e.location:d}}),e(KeyboardEvent.prototype,"locale",{get:function(){return""}})}(),"queryKeyCap"in e.KeyboardEvent||(e.KeyboardEvent.queryKeyCap=a),e.identifyKey=function(e){if(!("code"in e)){var o=c(e);e.code=o?o.code:"",e.key=o&&"key"in o?o.key:"Unidentified",e.location="location"in e?e.location:"keyLocation"in e?e.keyLocation:o&&"location"in o?o.location:d,e.locale=""}}}(window)}]); | ||
!function(e){function o(i){if(t[i])return t[i].exports;var c=t[i]={exports:{},id:i,loaded:!1};return e[i].call(c.exports,c,c.exports,o),c.loaded=!0,c.exports}var t={};return o.m=e,o.c=t,o.p="",o(0)}([function(e,o,t){!function(e){return e?void(e.aframeCore||e).registerComponent("keyboard-controls",t(1)):void console.error("Component attempted to register before AFRAME was available.")}(window.AFRAME)},function(e,o,t){t(2);var i=200,c="__keyboard-controls-proxy",a=window.KeyboardEvent;e.exports={schema:{easing:{"default":20},acceleration:{"default":65},enabled:{"default":!0},fly:{"default":!1},rollAxis:{"default":"z",oneOf:["x","y","z"]},pitchAxis:{"default":"x",oneOf:["x","y","z"]},rollAxisInverted:{"default":!1},rollAxisEnabled:{"default":!0},pitchAxisInverted:{"default":!1},pitchAxisEnabled:{"default":!0},debug:{"default":!1}},init:function(){this.velocity=new THREE.Vector3,this.localKeys={},this.listeners={keydown:this.onKeyDown.bind(this),keyup:this.onKeyUp.bind(this),blur:this.onBlur.bind(this)},this.attachEventListeners()},tick:function(e,o){var t,c=this.data,a=c.acceleration,n=c.easing,d=this.velocity,r=this.getKeys(),y=c.pitchAxis,l=c.rollAxis,s=c.pitchAxisInverted?-1:1,p=c.rollAxisInverted?-1:1,k=this.el;if(isNaN(o)||o>i)return d[y]=0,void(d[l]=0);d[y]-=d[y]*n*o/1e3,d[l]-=d[l]*n*o/1e3;var u=k.getComputedAttribute("position");c.enabled&&(c.pitchAxisEnabled&&((r.KeyA||r.ArrowLeft)&&(d[y]-=s*a*o/1e3),(r.KeyD||r.ArrowRight)&&(d[y]+=s*a*o/1e3)),c.rollAxisEnabled&&((r.KeyW||r.ArrowUp)&&(d[l]-=p*a*o/1e3),(r.KeyS||r.ArrowDown)&&(d[l]+=p*a*o/1e3))),t=this.getMovementVector(o),k.object3D.translateX(t.x),k.object3D.translateY(t.y),k.object3D.translateZ(t.z),k.setAttribute("position",{x:u.x+t.x,y:u.y+t.y,z:u.z+t.z})},getMovementVector:function(){var e=new THREE.Vector3(0,0,0),o=new THREE.Euler(0,0,0,"YXZ");return function(t){var i=this.velocity,c=this.el.getAttribute("rotation");return e.copy(i),e.multiplyScalar(t/1e3),c?(this.data.fly||(c.x=0),o.set(THREE.Math.degToRad(c.x),THREE.Math.degToRad(c.y),0),e.applyEuler(o),e):e}}(),play:function(){this.attachEventListeners()},pause:function(){this.removeEventListeners()},remove:function(){this.pause()},attachEventListeners:function(){window.addEventListener("keydown",this.listeners.keydown,!1),window.addEventListener("keyup",this.listeners.keyup,!1),window.addEventListener("blur",this.listeners.blur,!1)},removeEventListeners:function(){window.removeEventListener("keydown",this.listeners.keydown),window.removeEventListener("keyup",this.listeners.keyup),window.removeEventListener("blur",this.listeners.blur)},onKeyDown:function(e){this.localKeys[e.code]=!0,this.emit(e)},onKeyUp:function(e){delete this.localKeys[e.code],this.emit(e)},onBlur:function(){for(var e in this.localKeys)this.localKeys.hasOwnProperty(e)&&delete this.localKeys[e]},emit:function(e){c in e&&this.el.emit(e.type,e),this.el.emit(e.type+":"+e.code,new a(e.type,e)),this.data.debug&&console.log(e.type+":"+e.code)},isPressed:function(e){return e in this.getKeys()},getKeys:function(){return this.isProxied()?this.el.sceneEl.components["proxy-controls"].getKeyboard():this.localKeys},isProxied:function(){var e=this.el.sceneEl.components["proxy-controls"];return e&&e.isConnected()}}},function(e,o){!function(e){function o(e,o){return-1!==String(e).indexOf(o)}function t(e,o,t){(k===o||p===o||s===o)&&Object.keys(t).forEach(function(o){e[o]=t[o]})}function i(e,o){var t={};return Object.keys(e).forEach(function(i){var c=e[i];o in c&&(t[c[o]]=c)}),t}function c(e){var o="keyCode"in e?e.keyCode:"which"in e?e.which:0,t=function(){if(v||"keyLocation"in e){var t=v?e.location:e.keyLocation;if(t&&o in h[t])return h[t][o]}return"keyIdentifier"in e&&e.keyIdentifier in f?f[e.keyIdentifier]:o in u?u[o]:null}();if(!t)return null;var i=function(){var o=K[t.code];return o?e.shiftKey&&"shiftKey"in o?o.shiftKey:o.key:t.code}();return{code:t.code,key:i,location:t.location,keyCap:t.keyCap}}function a(e,o){if(e=String(e),!m.hasOwnProperty(e))return"Undefined";if(o&&"en-us"!==String(o).toLowerCase())throw Error("Unsupported locale");var t=m[e];return t.keyCap||t.code||"Undefined"}var n="KeyboardEvent"in e;n||(e.KeyboardEvent=function(){throw TypeError("Illegal constructor")}),e.KeyboardEvent.DOM_KEY_LOCATION_STANDARD=0,e.KeyboardEvent.DOM_KEY_LOCATION_LEFT=1,e.KeyboardEvent.DOM_KEY_LOCATION_RIGHT=2,e.KeyboardEvent.DOM_KEY_LOCATION_NUMPAD=3;var d=window.KeyboardEvent.DOM_KEY_LOCATION_STANDARD,r=window.KeyboardEvent.DOM_KEY_LOCATION_LEFT,y=window.KeyboardEvent.DOM_KEY_LOCATION_RIGHT,l=window.KeyboardEvent.DOM_KEY_LOCATION_NUMPAD,s=function(){return o(navigator.platform,"Win")?"win":o(navigator.platform,"Mac")?"mac":o(navigator.platform,"CrOS")?"cros":o(navigator.platform,"Linux")?"linux":o(navigator.userAgent,"iPad")||o(navigator.platform,"iPod")||o(navigator.platform,"iPhone")?"ios":""}(),p=function(){return o(navigator.userAgent,"Chrome/")?"chrome":o(navigator.vendor,"Apple")?"safari":o(navigator.userAgent,"MSIE")?"ie":o(navigator.userAgent,"Gecko/")?"moz":o(navigator.userAgent,"Opera/")?"opera":""}(),k=p+"-"+s,u={3:{code:"Cancel"},6:{code:"Help"},8:{code:"Backspace"},9:{code:"Tab"},12:{code:"Clear"},13:{code:"Enter"},16:{code:"Shift"},17:{code:"Control"},18:{code:"Alt"},19:{code:"Pause"},20:{code:"CapsLock"},21:{code:"KanaMode"},22:{code:"HangulMode"},23:{code:"JunjaMode"},24:{code:"FinalMode"},25:{code:"KanjiMode"},27:{code:"Escape"},28:{code:"Convert"},29:{code:"NonConvert"},30:{code:"Accept"},31:{code:"ModeChange"},32:{code:"Space"},33:{code:"PageUp"},34:{code:"PageDown"},35:{code:"End"},36:{code:"Home"},37:{code:"ArrowLeft"},38:{code:"ArrowUp"},39:{code:"ArrowRight"},40:{code:"ArrowDown"},41:{code:"Select"},42:{code:"Print"},43:{code:"Execute"},44:{code:"PrintScreen"},45:{code:"Insert"},46:{code:"Delete"},47:{code:"Help"},48:{code:"Digit0",keyCap:"0"},49:{code:"Digit1",keyCap:"1"},50:{code:"Digit2",keyCap:"2"},51:{code:"Digit3",keyCap:"3"},52:{code:"Digit4",keyCap:"4"},53:{code:"Digit5",keyCap:"5"},54:{code:"Digit6",keyCap:"6"},55:{code:"Digit7",keyCap:"7"},56:{code:"Digit8",keyCap:"8"},57:{code:"Digit9",keyCap:"9"},65:{code:"KeyA",keyCap:"a"},66:{code:"KeyB",keyCap:"b"},67:{code:"KeyC",keyCap:"c"},68:{code:"KeyD",keyCap:"d"},69:{code:"KeyE",keyCap:"e"},70:{code:"KeyF",keyCap:"f"},71:{code:"KeyG",keyCap:"g"},72:{code:"KeyH",keyCap:"h"},73:{code:"KeyI",keyCap:"i"},74:{code:"KeyJ",keyCap:"j"},75:{code:"KeyK",keyCap:"k"},76:{code:"KeyL",keyCap:"l"},77:{code:"KeyM",keyCap:"m"},78:{code:"KeyN",keyCap:"n"},79:{code:"KeyO",keyCap:"o"},80:{code:"KeyP",keyCap:"p"},81:{code:"KeyQ",keyCap:"q"},82:{code:"KeyR",keyCap:"r"},83:{code:"KeyS",keyCap:"s"},84:{code:"KeyT",keyCap:"t"},85:{code:"KeyU",keyCap:"u"},86:{code:"KeyV",keyCap:"v"},87:{code:"KeyW",keyCap:"w"},88:{code:"KeyX",keyCap:"x"},89:{code:"KeyY",keyCap:"y"},90:{code:"KeyZ",keyCap:"z"},91:{code:"OSLeft",location:r},92:{code:"OSRight",location:y},93:{code:"ContextMenu"},95:{code:"Standby"},96:{code:"Numpad0",keyCap:"0",location:l},97:{code:"Numpad1",keyCap:"1",location:l},98:{code:"Numpad2",keyCap:"2",location:l},99:{code:"Numpad3",keyCap:"3",location:l},100:{code:"Numpad4",keyCap:"4",location:l},101:{code:"Numpad5",keyCap:"5",location:l},102:{code:"Numpad6",keyCap:"6",location:l},103:{code:"Numpad7",keyCap:"7",location:l},104:{code:"Numpad8",keyCap:"8",location:l},105:{code:"Numpad9",keyCap:"9",location:l},106:{code:"NumpadMultiply",keyCap:"*",location:l},107:{code:"NumpadAdd",keyCap:"+",location:l},108:{code:"NumpadComma",keyCap:",",location:l},109:{code:"NumpadSubtract",keyCap:"-",location:l},110:{code:"NumpadDecimal",keyCap:".",location:l},111:{code:"NumpadDivide",keyCap:"/",location:l},112:{code:"F1"},113:{code:"F2"},114:{code:"F3"},115:{code:"F4"},116:{code:"F5"},117:{code:"F6"},118:{code:"F7"},119:{code:"F8"},120:{code:"F9"},121:{code:"F10"},122:{code:"F11"},123:{code:"F12"},124:{code:"F13"},125:{code:"F14"},126:{code:"F15"},127:{code:"F16"},128:{code:"F17"},129:{code:"F18"},130:{code:"F19"},131:{code:"F20"},132:{code:"F21"},133:{code:"F22"},134:{code:"F23"},135:{code:"F24"},144:{code:"NumLock",location:l},145:{code:"ScrollLock"},160:{code:"ShiftLeft",location:r},161:{code:"ShiftRight",location:y},162:{code:"ControlLeft",location:r},163:{code:"ControlRight",location:y},164:{code:"AltLeft",location:r},165:{code:"AltRight",location:y},166:{code:"BrowserBack"},167:{code:"BrowserForward"},168:{code:"BrowserRefresh"},169:{code:"BrowserStop"},170:{code:"BrowserSearch"},171:{code:"BrowserFavorites"},172:{code:"BrowserHome"},173:{code:"VolumeMute"},174:{code:"VolumeDown"},175:{code:"VolumeUp"},176:{code:"MediaTrackNext"},177:{code:"MediaTrackPrevious"},178:{code:"MediaStop"},179:{code:"MediaPlayPause"},180:{code:"LaunchMail"},181:{code:"MediaSelect"},182:{code:"LaunchApp1"},183:{code:"LaunchApp2"},186:{code:"Semicolon",keyCap:";"},187:{code:"Equal",keyCap:"="},188:{code:"Comma",keyCap:","},189:{code:"Minus",keyCap:"-"},190:{code:"Period",keyCap:"."},191:{code:"Slash",keyCap:"/"},192:{code:"Backquote",keyCap:"`"},219:{code:"BracketLeft",keyCap:"["},220:{code:"Backslash",keyCap:"\\"},221:{code:"BracketRight",keyCap:"]"},222:{code:"Quote",keyCap:"'"},226:{code:"IntlBackslash",keyCap:"\\"},229:{code:"Process"},246:{code:"Attn"},247:{code:"CrSel"},248:{code:"ExSel"},249:{code:"EraseEof"},250:{code:"Play"},251:{code:"ZoomToggle"},254:{code:"Clear"}};t(u,"moz",{59:{code:"Semicolon",keyCap:";"},61:{code:"Equal",keyCap:"="},107:{code:"Equal",keyCap:"="},109:{code:"Minus",keyCap:"-"},187:{code:"NumpadAdd",keyCap:"+",location:l},189:{code:"NumpadSubtract",keyCap:"-",location:l}}),t(u,"moz-mac",{12:{code:"NumLock",location:l},173:{code:"Minus",keyCap:"-"}}),t(u,"moz-win",{173:{code:"Minus",keyCap:"-"}}),t(u,"chrome-mac",{93:{code:"OSRight",location:y}}),t(u,"safari",{3:{code:"Enter"},25:{code:"Tab"}}),t(u,"ios",{10:{code:"Enter",location:d}}),t(u,"safari-mac",{91:{code:"OSLeft",location:r},93:{code:"OSRight",location:y},229:{code:"KeyQ",keyCap:"Q"}});var f={};"cros"===s&&(f["U+00A0"]={code:"ShiftLeft",location:r},f["U+00A1"]={code:"ShiftRight",location:y},f["U+00A2"]={code:"ControlLeft",location:r},f["U+00A3"]={code:"ControlRight",location:y},f["U+00A4"]={code:"AltLeft",location:r},f["U+00A5"]={code:"AltRight",location:y}),"chrome-mac"===k&&(f["U+0010"]={code:"ContextMenu"}),"safari-mac"===k&&(f["U+0010"]={code:"ContextMenu"}),"ios"===s&&(f["U+0010"]={code:"Function"},f["U+001C"]={code:"ArrowLeft"},f["U+001D"]={code:"ArrowRight"},f["U+001E"]={code:"ArrowUp"},f["U+001F"]={code:"ArrowDown"},f["U+0001"]={code:"Home"},f["U+0004"]={code:"End"},f["U+000B"]={code:"PageUp"},f["U+000C"]={code:"PageDown"});var h=[];h[r]={16:{code:"ShiftLeft",location:r},17:{code:"ControlLeft",location:r},18:{code:"AltLeft",location:r}},h[y]={16:{code:"ShiftRight",location:y},17:{code:"ControlRight",location:y},18:{code:"AltRight",location:y}},h[l]={13:{code:"NumpadEnter",location:l}},t(h[l],"moz",{109:{code:"NumpadSubtract",location:l},107:{code:"NumpadAdd",location:l}}),t(h[r],"moz-mac",{224:{code:"OSLeft",location:r}}),t(h[y],"moz-mac",{224:{code:"OSRight",location:y}}),t(h[y],"moz-win",{91:{code:"OSRight",location:y}}),t(h[y],"mac",{93:{code:"OSRight",location:y}}),t(h[l],"chrome-mac",{12:{code:"NumLock",location:l}}),t(h[l],"safari-mac",{12:{code:"NumLock",location:l},187:{code:"NumpadAdd",location:l},189:{code:"NumpadSubtract",location:l},190:{code:"NumpadDecimal",location:l},191:{code:"NumpadDivide",location:l}});var K={ShiftLeft:{key:"Shift"},ShiftRight:{key:"Shift"},ControlLeft:{key:"Control"},ControlRight:{key:"Control"},AltLeft:{key:"Alt"},AltRight:{key:"Alt"},OSLeft:{key:"OS"},OSRight:{key:"OS"},NumpadEnter:{key:"Enter"},Space:{key:" "},Digit0:{key:"0",shiftKey:")"},Digit1:{key:"1",shiftKey:"!"},Digit2:{key:"2",shiftKey:"@"},Digit3:{key:"3",shiftKey:"#"},Digit4:{key:"4",shiftKey:"$"},Digit5:{key:"5",shiftKey:"%"},Digit6:{key:"6",shiftKey:"^"},Digit7:{key:"7",shiftKey:"&"},Digit8:{key:"8",shiftKey:"*"},Digit9:{key:"9",shiftKey:"("},KeyA:{key:"a",shiftKey:"A"},KeyB:{key:"b",shiftKey:"B"},KeyC:{key:"c",shiftKey:"C"},KeyD:{key:"d",shiftKey:"D"},KeyE:{key:"e",shiftKey:"E"},KeyF:{key:"f",shiftKey:"F"},KeyG:{key:"g",shiftKey:"G"},KeyH:{key:"h",shiftKey:"H"},KeyI:{key:"i",shiftKey:"I"},KeyJ:{key:"j",shiftKey:"J"},KeyK:{key:"k",shiftKey:"K"},KeyL:{key:"l",shiftKey:"L"},KeyM:{key:"m",shiftKey:"M"},KeyN:{key:"n",shiftKey:"N"},KeyO:{key:"o",shiftKey:"O"},KeyP:{key:"p",shiftKey:"P"},KeyQ:{key:"q",shiftKey:"Q"},KeyR:{key:"r",shiftKey:"R"},KeyS:{key:"s",shiftKey:"S"},KeyT:{key:"t",shiftKey:"T"},KeyU:{key:"u",shiftKey:"U"},KeyV:{key:"v",shiftKey:"V"},KeyW:{key:"w",shiftKey:"W"},KeyX:{key:"x",shiftKey:"X"},KeyY:{key:"y",shiftKey:"Y"},KeyZ:{key:"z",shiftKey:"Z"},Numpad0:{key:"0"},Numpad1:{key:"1"},Numpad2:{key:"2"},Numpad3:{key:"3"},Numpad4:{key:"4"},Numpad5:{key:"5"},Numpad6:{key:"6"},Numpad7:{key:"7"},Numpad8:{key:"8"},Numpad9:{key:"9"},NumpadMultiply:{key:"*"},NumpadAdd:{key:"+"},NumpadComma:{key:","},NumpadSubtract:{key:"-"},NumpadDecimal:{key:"."},NumpadDivide:{key:"/"},Semicolon:{key:";",shiftKey:":"},Equal:{key:"=",shiftKey:"+"},Comma:{key:",",shiftKey:"<"},Minus:{key:"-",shiftKey:"_"},Period:{key:".",shiftKey:">"},Slash:{key:"/",shiftKey:"?"},Backquote:{key:"`",shiftKey:"~"},BracketLeft:{key:"[",shiftKey:"{"},Backslash:{key:"\\",shiftKey:"|"},BracketRight:{key:"]",shiftKey:"}"},Quote:{key:"'",shiftKey:'"'},IntlBackslash:{key:"\\",shiftKey:"|"}};t(K,"mac",{OSLeft:{key:"Meta"},OSRight:{key:"Meta"}});var C={Esc:"Escape",Nonconvert:"NonConvert",Left:"ArrowLeft",Up:"ArrowUp",Right:"ArrowRight",Down:"ArrowDown",Del:"Delete",Menu:"ContextMenu",MediaNextTrack:"MediaTrackNext",MediaPreviousTrack:"MediaTrackPrevious",SelectMedia:"MediaSelect",HalfWidth:"Hankaku",FullWidth:"Zenkaku",RomanCharacters:"Romaji",Crsel:"CrSel",Exsel:"ExSel",Zoom:"ZoomToggle"},m=i(u,"code");try{var v=n&&"location"in new KeyboardEvent("")}catch(g){}"KeyboardEvent"in e&&"defineProperty"in Object&&!function(){function e(e,o,t){o in e||Object.defineProperty(e,o,t)}if(e(KeyboardEvent.prototype,"code",{get:function(){var e=c(this);return e?e.code:""}}),"key"in KeyboardEvent.prototype){var o=Object.getOwnPropertyDescriptor(KeyboardEvent.prototype,"key");Object.defineProperty(KeyboardEvent.prototype,"key",{get:function(){var e=o.get.call(this);return C.hasOwnProperty(e)?C[e]:e}})}e(KeyboardEvent.prototype,"key",{get:function(){var e=c(this);return e&&"key"in e?e.key:"Unidentified"}}),e(KeyboardEvent.prototype,"location",{get:function(){var e=c(this);return e&&"location"in e?e.location:d}}),e(KeyboardEvent.prototype,"locale",{get:function(){return""}})}(),"queryKeyCap"in e.KeyboardEvent||(e.KeyboardEvent.queryKeyCap=a),e.identifyKey=function(e){if(!("code"in e)){var o=c(e);e.code=o?o.code:"",e.key=o&&"key"in o?o.key:"Unidentified",e.location="location"in e?e.location:"keyLocation"in e?e.keyLocation:o&&"location"in o?o.location:d,e.locale=""}}}(window)}]); |
require('./lib/keyboard.polyfill'); | ||
var MAX_DELTA = 0.2, | ||
var MAX_DELTA = 200, | ||
PROXY_FLAG = '__keyboard-controls-proxy'; | ||
@@ -50,8 +50,3 @@ | ||
}; | ||
var sceneEl = this.el.sceneEl; | ||
if (sceneEl.addBehavior) { | ||
sceneEl.addBehavior(this); | ||
this.attachEventListeners(); | ||
} | ||
this.attachEventListeners(); | ||
}, | ||
@@ -63,5 +58,3 @@ | ||
tick: function () { this.update(); }, | ||
update: function (previousData) { | ||
tick: function (t, dt) { | ||
var data = this.data; | ||
@@ -71,5 +64,2 @@ var acceleration = data.acceleration; | ||
var velocity = this.velocity; | ||
var prevTime = this.prevTime = this.prevTime || Date.now(); | ||
var time = window.performance.now(); | ||
var delta = (time - prevTime) / 1000; | ||
var keys = this.getKeys(); | ||
@@ -82,6 +72,5 @@ var movementVector; | ||
var el = this.el; | ||
this.prevTime = time; | ||
// If data changed or FPS too low, reset velocity. | ||
if (previousData || delta > MAX_DELTA) { | ||
if (isNaN(dt) || dt > MAX_DELTA) { | ||
velocity[pitchAxis] = 0; | ||
@@ -92,4 +81,4 @@ velocity[rollAxis] = 0; | ||
velocity[pitchAxis] -= velocity[pitchAxis] * easing * delta; | ||
velocity[rollAxis] -= velocity[rollAxis] * easing * delta; | ||
velocity[pitchAxis] -= velocity[pitchAxis] * easing * dt / 1000; | ||
velocity[rollAxis] -= velocity[rollAxis] * easing * dt / 1000; | ||
@@ -101,6 +90,6 @@ var position = el.getComputedAttribute('position'); | ||
if (keys.KeyA || keys.ArrowLeft) { | ||
velocity[pitchAxis] -= pitchSign * acceleration * delta; | ||
velocity[pitchAxis] -= pitchSign * acceleration * dt / 1000; | ||
} | ||
if (keys.KeyD || keys.ArrowRight) { | ||
velocity[pitchAxis] += pitchSign * acceleration * delta; | ||
velocity[pitchAxis] += pitchSign * acceleration * dt / 1000; | ||
} | ||
@@ -110,6 +99,6 @@ } | ||
if (keys.KeyW || keys.ArrowUp) { | ||
velocity[rollAxis] -= rollSign * acceleration * delta; | ||
velocity[rollAxis] -= rollSign * acceleration * dt / 1000; | ||
} | ||
if (keys.KeyS || keys.ArrowDown) { | ||
velocity[rollAxis] += rollSign * acceleration * delta; | ||
velocity[rollAxis] += rollSign * acceleration * dt / 1000; | ||
} | ||
@@ -119,3 +108,3 @@ } | ||
movementVector = this.getMovementVector(delta); | ||
movementVector = this.getMovementVector(dt); | ||
el.object3D.translateX(movementVector.x); | ||
@@ -132,10 +121,10 @@ el.object3D.translateY(movementVector.y); | ||
getMovementVector: (function (delta) { | ||
getMovementVector: (function () { | ||
var direction = new THREE.Vector3(0, 0, 0); | ||
var rotation = new THREE.Euler(0, 0, 0, 'YXZ'); | ||
return function (delta) { | ||
return function (dt) { | ||
var velocity = this.velocity; | ||
var elRotation = this.el.getAttribute('rotation'); | ||
direction.copy(velocity); | ||
direction.multiplyScalar(delta); | ||
direction.multiplyScalar(dt / 1000); | ||
if (!elRotation) { return direction; } | ||
@@ -162,6 +151,2 @@ if (!this.data.fly) { elRotation.x = 0; } | ||
tick: function (t) { // jshint ignore:line | ||
this.update(); | ||
}, | ||
remove: function () { | ||
@@ -219,3 +204,3 @@ this.pause(); | ||
*/ | ||
isPressed: function (code) { | ||
@@ -222,0 +207,0 @@ return code in this.getKeys(); |
{ | ||
"name": "aframe-keyboard-controls", | ||
"version": "0.2.4", | ||
"version": "1.0.0", | ||
"description": "Keyboard controls for A-Frame.", | ||
@@ -5,0 +5,0 @@ "main": "keyboard-controls.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
0
210800
1844