diff --git a/bmllkpyql3.js b/bmllkpyql3.js index f7756a0..5f33db7 100644 --- a/bmllkpyql3.js +++ b/bmllkpyql3.js @@ -11,4 +11,4 @@ this.entityLoaded.move( } ); -//@ sourceURL=mouseMoveARFootball2.js \ No newline at end of file +//@ sourceURL=mouseMoveARFootball3.js \ No newline at end of file diff --git a/ff0fsum4zx.js b/ff0fsum4zx.js index f1fce3c..7fee068 100644 --- a/ff0fsum4zx.js +++ b/ff0fsum4zx.js @@ -8,23 +8,32 @@ if (data.entity === this.parentEntity) { * Code Components */ this.mouseMove = R3.EntityManager.Instance.findComponentById('dwxvtxzrun'); +this.touchMove = R3.EntityManager.Instance.findComponentById('p49pad0i7l'); /** * Meshes */ this.footballPlayer = R3.EntityManager.Instance.findComponentById('t537n02x0s'); +this.movingAverage = R3.Utils.MovingAverage(10); + this.playerRotation = { x : 0, y : 0 }; + +R3.CustomCode.prototype.kick = function(data) { + +}; + R3.CustomCode.prototype.move = function(data) { var x = data.x; var y = data.y; + var speed = 0; - if (data.source === 'mouse') { + if (data.source === 'mouse' || 'touch') { x *= 0.01; y *= 0.01; } @@ -32,6 +41,32 @@ R3.CustomCode.prototype.move = function(data) { this.playerRotation.x += x; this.playerRotation.y += y; + this.timestamp = null; + + var kick = false; + + var canKick = false; + + var movingDown = false; + + if (this.playerRotation.y > Math.PI) { + canKick = true; + } + + /** + * Clamp player rotation to values between Math.PI * 2 + */ + if (this.playerRotation.y > Math.PI * 2) { + this.playerRotation.y -= Math.PI * 2; + kick = true; + canKick = false; + } + + if (this.playerRotation.y < 0) { + this.playerRotation.y += Math.PI * 2; + canKick = true; + } + this.footballPlayer.instance.matrix = new THREE.Matrix4(); this.footballPlayer.instance.matrix.decompose( this.footballPlayer.instance.position, @@ -47,75 +82,45 @@ R3.CustomCode.prototype.move = function(data) { this.footballPlayer.instance.rotateX(this.playerRotation.y); - // var v = new THREE.Vector3(x, y, 0); - // v.normalize(); + if (kick) { + console.log('kick'); + console.log(Number(Date.now()) - Number(this.timestamp)); + } + if (canKick) { + console.log('can kick'); + } - /** - * This is where i have to do the right order of transformations - */ - - //this.footballPlayer.instance.rotateOnAxis(new THREE.Vector3(0, 1, 0), this.playerRotation.x * 0.001); - - // this.footballPlayer.quaternion.axis.x = 1; - // this.footballPlayer.quaternion.axis.y = 0; - // this.footballPlayer.quaternion.axis.z = 0; - // - // this.footballPlayer.quaternion.angle = this.playerRotation.y; - // - // this.footballPlayer.updateInstance('quaternion'); + if (y > 0 && canKick) { - //this.footballPlayer.instance.rotateOnAxis(new THREE.Vector3(1, 0, 0), this.playerRotation.y * 0.001); -// this.footballPlayer.instance.rotateX(v.y * 0.1); + if (this.movingDown) { + /** + * Do nothing + */ + } else { - //this.footballPlayer.instance.translateZ(-0.2); + this.timestamp = Date.now(); + console.log('time stamped : ' + this.timestamp); + this.movingDown = true + } + /** + * Moving down, record the average + */ + // speed = this.movingAverage(y); + } - - // - - - // - // this.footballPlayer.position.x = Math.sin(this.playerRotation.x); - // this.footballPlayer.position.z = Math.cos(this.playerRotation.x); - // this.footballPlayer.updateInstance('position'); - // - // this.footballPlayer.lookAt.x = 0; - // this.footballPlayer.lookAt.y = 0; - // this.footballPlayer.lookAt.z = 0; - // this.footballPlayer.updateInstance('lookAt'); - - - /** - var v = new THREE.Vector3(this.playerRotation.y, this.playerRotation.x, 0); - v.normalize(); - - this.footballPlayer.quaternion.axis.x = v.x; - this.footballPlayer.quaternion.axis.y = v.y; - this.footballPlayer.quaternion.axis.z = 0; - - this.footballPlayer.quaternion.angle = 1; - //this.footballPlayer.quaternion.angle = Math.abs(x) + Math.abs(y); - - this.footballPlayer.updateInstance('quaternion'); - console.log('todo: player rotation'); - - this.footballPlayer.quaternion.axis.x = 0; - this.footballPlayer.quaternion.axis.y = 1; - this.footballPlayer.quaternion.axis.z = 0; - - this.footballPlayer.quaternion.angle = this.playerRotation.x; - - this.footballPlayer.updateInstance('quaternion'); - */ - + if (y < 0) { + this.movingDown = false; + } }.bind(this) this.mouseMove.entityLoaded = this; +this.touchMove.entityLoaded = this; //@ sourceURL=entityLoaded.js \ No newline at end of file diff --git a/madnahfvrc.js b/madnahfvrc.js index 6653ff4..dff7d0e 100644 --- a/madnahfvrc.js +++ b/madnahfvrc.js @@ -1,5 +1,5 @@ if (data.entity === this.parentEntity) { - console.log('AR Football 2 Entity Loaded'); + console.log('AR Football 3 Entity Loaded'); } else { return; } diff --git a/p49pad0i7l.js b/p49pad0i7l.js index fb8c2b8..599b3f8 100644 --- a/p49pad0i7l.js +++ b/p49pad0i7l.js @@ -1,2 +1,14 @@ -return null; -//@ sourceURL=CustomCode (p49pad0i7l).js \ No newline at end of file + +if (!this.entityLoaded) { + return; +} + +this.entityLoaded.move( + { + source : 'touch', + x : data.meta.totalRight - data.meta.totalLeft, + y : data.meta.totalDown - data.meta.totalUp + } +); + +//@ sourceURL=touchMove.js \ No newline at end of file