From 91ced64374daaf699abe748896516d575d356591 Mon Sep 17 00:00:00 2001 From: -=ybafelo Date: Thu, 17 May 2018 12:42:33 +0200 Subject: [PATCH 01/16] Initial Commit: CC - Entity Loaded - AR Football 2 (ff0fsum4zx.js) --- ff0fsum4zx.js | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 ff0fsum4zx.js diff --git a/ff0fsum4zx.js b/ff0fsum4zx.js new file mode 100644 index 0000000..f1fce3c --- /dev/null +++ b/ff0fsum4zx.js @@ -0,0 +1,121 @@ +if (data.entity === this.parentEntity) { + console.log('AR Football 2 Entity Loaded'); +} else { + return; +} + +/** + * Code Components + */ +this.mouseMove = R3.EntityManager.Instance.findComponentById('dwxvtxzrun'); + +/** + * Meshes + */ +this.footballPlayer = R3.EntityManager.Instance.findComponentById('t537n02x0s'); + +this.playerRotation = { + x : 0, + y : 0 +}; + +R3.CustomCode.prototype.move = function(data) { + + var x = data.x; + var y = data.y; + + if (data.source === 'mouse') { + x *= 0.01; + y *= 0.01; + } + + this.playerRotation.x += x; + this.playerRotation.y += y; + + this.footballPlayer.instance.matrix = new THREE.Matrix4(); + this.footballPlayer.instance.matrix.decompose( + this.footballPlayer.instance.position, + this.footballPlayer.instance.quaternion, + this.footballPlayer.instance.scale + ); + + this.footballPlayer.instance.translateY(0.78); + + this.footballPlayer.instance.rotateY(this.playerRotation.x); + + this.footballPlayer.instance.translateZ(0.2); + + this.footballPlayer.instance.rotateX(this.playerRotation.y); + + // var v = new THREE.Vector3(x, y, 0); + // v.normalize(); + + + /** + * 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'); + + + + //this.footballPlayer.instance.rotateOnAxis(new THREE.Vector3(1, 0, 0), this.playerRotation.y * 0.001); +// this.footballPlayer.instance.rotateX(v.y * 0.1); + + //this.footballPlayer.instance.translateZ(-0.2); + + + + // + + + // + // 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'); + */ + + + + +}.bind(this) + +this.mouseMove.entityLoaded = this; + +//@ sourceURL=entityLoaded.js \ No newline at end of file From c4d5428ef5f1bacec6d7c18368a5fe1fb7e7bb0c Mon Sep 17 00:00:00 2001 From: -=ybafelo Date: Thu, 17 May 2018 12:42:33 +0200 Subject: [PATCH 02/16] Initial Commit: CC - Mouse Move - AR Football 2 (dwxvtxzrun.js) --- dwxvtxzrun.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 dwxvtxzrun.js diff --git a/dwxvtxzrun.js b/dwxvtxzrun.js new file mode 100644 index 0000000..f7756a0 --- /dev/null +++ b/dwxvtxzrun.js @@ -0,0 +1,14 @@ + +if (!this.entityLoaded) { + return; +} + +this.entityLoaded.move( + { + source : 'mouse', + x : data.event.movementX, + y : data.event.movementY + } +); + +//@ sourceURL=mouseMoveARFootball2.js \ No newline at end of file From c40a450f3c0fedb1d8e2ad4ea488e5891b418a8a Mon Sep 17 00:00:00 2001 From: -=ybafelo Date: Thu, 17 May 2018 13:01:28 +0200 Subject: [PATCH 03/16] Initial Commit: CC - Touch Move - AR Football 3 (p49pad0i7l.js) --- p49pad0i7l.js | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 p49pad0i7l.js diff --git a/p49pad0i7l.js b/p49pad0i7l.js new file mode 100644 index 0000000..fb8c2b8 --- /dev/null +++ b/p49pad0i7l.js @@ -0,0 +1,2 @@ +return null; +//@ sourceURL=CustomCode (p49pad0i7l).js \ No newline at end of file From 922d33d61620ff1b0edae86a4d3122317c13c11b Mon Sep 17 00:00:00 2001 From: -=ybafelo Date: Thu, 17 May 2018 15:37:56 +0200 Subject: [PATCH 04/16] stuff --- bmllkpyql3.js | 2 +- ff0fsum4zx.js | 119 ++++++++++++++++++++++++++------------------------ madnahfvrc.js | 2 +- p49pad0i7l.js | 16 ++++++- 4 files changed, 78 insertions(+), 61 deletions(-) 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 From a3c4cbdf3af1cf756e50c5a167884eb42bbcab72 Mon Sep 17 00:00:00 2001 From: -=ybafelo Date: Fri, 18 May 2018 14:42:53 +0200 Subject: [PATCH 05/16] Initial Commit: CC - Before Render - AR Football 3 (7l8ar325qf.js) --- 7l8ar325qf.js | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 7l8ar325qf.js diff --git a/7l8ar325qf.js b/7l8ar325qf.js new file mode 100644 index 0000000..7800937 --- /dev/null +++ b/7l8ar325qf.js @@ -0,0 +1,2 @@ +return null; +//@ sourceURL=CustomCode (7l8ar325qf).js \ No newline at end of file From a2e4bfff3dd80456afe6ad1cd234f6657fd6826e Mon Sep 17 00:00:00 2001 From: -=ybafelo Date: Fri, 18 May 2018 15:31:22 +0200 Subject: [PATCH 06/16] kicking direction --- 7l8ar325qf.js | 10 +++- dwxvtxzrun.js | 2 +- ff0fsum4zx.js | 137 +++++++++++++++++++++++++++++++++++++++----------- p49pad0i7l.js | 4 +- 4 files changed, 120 insertions(+), 33 deletions(-) diff --git a/7l8ar325qf.js b/7l8ar325qf.js index 7800937..1af9d53 100644 --- a/7l8ar325qf.js +++ b/7l8ar325qf.js @@ -1,2 +1,8 @@ -return null; -//@ sourceURL=CustomCode (7l8ar325qf).js \ No newline at end of file + +if (!this.entityLoaded) { + return; +} + +this.entityLoaded.render(data.delta); + +//@ sourceURL=beforeRender.js \ No newline at end of file diff --git a/dwxvtxzrun.js b/dwxvtxzrun.js index f7756a0..bc0bcbb 100644 --- a/dwxvtxzrun.js +++ b/dwxvtxzrun.js @@ -11,4 +11,4 @@ this.entityLoaded.move( } ); -//@ sourceURL=mouseMoveARFootball2.js \ No newline at end of file +//@ sourceURL=mouseMove.js \ No newline at end of file diff --git a/ff0fsum4zx.js b/ff0fsum4zx.js index 7fee068..2a0a32a 100644 --- a/ff0fsum4zx.js +++ b/ff0fsum4zx.js @@ -9,29 +9,58 @@ if (data.entity === this.parentEntity) { */ this.mouseMove = R3.EntityManager.Instance.findComponentById('dwxvtxzrun'); this.touchMove = R3.EntityManager.Instance.findComponentById('p49pad0i7l'); +this.beforeRender = R3.EntityManager.Instance.findComponentById('7l8ar325qf'); /** * Meshes */ this.footballPlayer = R3.EntityManager.Instance.findComponentById('t537n02x0s'); +this.football = R3.EntityManager.Instance.findComponentById('umgbzb0ur2'); -this.movingAverage = R3.Utils.MovingAverage(10); +/** + * Geometry + */ +this.ballGeometry = R3.EntityManager.Instance.findComponentById('dt6jl8kocw'); + +/** + * Materials + */ +this.materialWhite = R3.EntityManager.Instance.findComponentById('iualutcl1y'); +this.materialBlack = R3.EntityManager.Instance.findComponentById('2g36po454g'); this.playerRotation = { x : 0, y : 0 }; +this.kick = { + start : null, + distance : 0, + time : 0, + speed : 0, + direction : 0 +}; -R3.CustomCode.prototype.kick = function(data) { +this.balls = []; +this.activeBall = this.football.instance; + +R3.CustomCode.prototype.render = function(delta) { + + this.balls.map( + function(object) { + var ball = object.ball; + var kick = object.kick; + + ball.translateOnAxis(object.v, 1); + } + ) }; R3.CustomCode.prototype.move = function(data) { var x = data.x; var y = data.y; - var speed = 0; if (data.source === 'mouse' || 'touch') { x *= 0.01; @@ -41,20 +70,16 @@ 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 + * Clamp player rotation to values between 0 and Math.PI * 2 */ if (this.playerRotation.y > Math.PI * 2) { this.playerRotation.y -= Math.PI * 2; @@ -67,6 +92,17 @@ R3.CustomCode.prototype.move = function(data) { canKick = true; } + /** + * Clamp direction angle between 0 and Math.PI * 2 + */ + if (this.playerRotation.x > Math.PI * 2) { + this.playerRotation.x -= Math.PI * 2; + } + + if (this.playerRotation.x < 0) { + this.playerRotation.x += Math.PI * 2; + } + this.footballPlayer.instance.matrix = new THREE.Matrix4(); this.footballPlayer.instance.matrix.decompose( this.footballPlayer.instance.position, @@ -83,44 +119,89 @@ R3.CustomCode.prototype.move = function(data) { this.footballPlayer.instance.rotateX(this.playerRotation.y); if (kick) { - console.log('kick'); - console.log(Number(Date.now()) - Number(this.timestamp)); + + if (this.kick.start === null) { + console.warn('no kick start time'); + return; + } + + this.kick.time = Date.now() - this.kick.start; + + this.kick.speed = this.kick.distance / this.kick.time; + + this.kick.direction = this.playerRotation.x; + + var v = new THREE.Vector3(0, 0, -1); + + v.multiplyScalar(this.kick.speed); + + v.applyAxisAngle( + new THREE.Vector3(0,1,0), + this.kick.direction + ); + + this.balls.push( + { + ball : this.activeBall, + kick : this.kick, + v : v + } + ); + + this.activeBall = null; + + console.log('kick', this.kick); } - if (canKick) { - console.log('can kick'); + if (canKick && this.activeBall === null) { + + console.log('can kick'); + + this.activeBall = new THREE.Mesh( + this.ballGeometry.instance, + [ + this.materialWhite.instance, + this.materialBlack.instance + ] + ); + + this.activeBall.scale.copy(this.football.instance.scale); + //this.activeBall.scale.copy(this.football.instance.scale); + + this.football.parentScene.instance.add(this.activeBall); } if (y > 0 && canKick) { - - - if (this.movingDown) { - /** - * Do nothing - */ - } else { - - this.timestamp = Date.now(); - console.log('time stamped : ' + this.timestamp); - this.movingDown = true + if (this.kick.start === null) { + this.kick.start = Date.now(); } /** - * Moving down, record the average + * Moving down, record the distance travelled */ - // speed = this.movingAverage(y); + this.kick.distance += Math.abs(y); } if (y < 0) { - this.movingDown = false; + + /** + * We are no longer moving down, also reset our Y distance counter + * @type {boolean} + */ + this.kick = { + start : null, + distance : 0, + time : 0, + speed : 0, + direction : 0 + }; } - - }.bind(this) this.mouseMove.entityLoaded = this; this.touchMove.entityLoaded = this; +this.beforeRender.entityLoaded = this; //@ sourceURL=entityLoaded.js \ No newline at end of file diff --git a/p49pad0i7l.js b/p49pad0i7l.js index 599b3f8..a1bfa14 100644 --- a/p49pad0i7l.js +++ b/p49pad0i7l.js @@ -6,8 +6,8 @@ if (!this.entityLoaded) { this.entityLoaded.move( { source : 'touch', - x : data.meta.totalRight - data.meta.totalLeft, - y : data.meta.totalDown - data.meta.totalUp + x : data.meta.movementX, + y : data.meta.movementY } ); From b17e28f8bb880a2023d2f7f0a3647636d2775ae3 Mon Sep 17 00:00:00 2001 From: -=yb4f310 Date: Sun, 20 May 2018 13:36:43 +0200 Subject: [PATCH 07/16] nice kicking --- ff0fsum4zx.js | 74 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 63 insertions(+), 11 deletions(-) diff --git a/ff0fsum4zx.js b/ff0fsum4zx.js index 2a0a32a..c326305 100644 --- a/ff0fsum4zx.js +++ b/ff0fsum4zx.js @@ -45,15 +45,53 @@ this.balls = []; this.activeBall = this.football.instance; +R3.CustomCode.prototype.calcPosition = function(shotAngle, lookAngle, t) { + + + +}; + R3.CustomCode.prototype.render = function(delta) { this.balls.map( - function(object) { - var ball = object.ball; - var kick = object.kick; - ball.translateOnAxis(object.v, 1); - } + function(ball) { + + ball.t += delta; + + var u = new THREE.Vector3( + ball.speed * Math.sin(ball.directionAngle), + ball.speed * Math.sin(ball.upAngle), + ball.speed * Math.cos(ball.directionAngle) + ); + + ball.mesh.position.x = ball.s0.x + u.x * ball.t; + ball.mesh.position.y = ball.s0.y + u.y * ball.t + 0.5 * (-9.8) * ball.t * ball.t; + ball.mesh.position.z = ball.s0.z + u.z * ball.t; + + if (ball.mesh.position.y <= 0) { + ball.s0.x = ball.mesh.position.x; + ball.s0.y = 0; + ball.s0.z = ball.mesh.position.z; + ball.upAngle *= ball.bounciness; + ball.t = 0; + } + + var v = new THREE.Vector3( + -ball.v.z, + 0, + ball.v.x + ); + + + ball.mesh.rotateOnAxis(v.normalize(), -0.1); + + //object.ball.translateOnAxis(object.v, 1); + + //object.ball.position.y = object.ball.position.y + 0.5 * (-9.8) * object.t * object.t; + + + }.bind(this) ) }; @@ -127,10 +165,16 @@ R3.CustomCode.prototype.move = function(data) { this.kick.time = Date.now() - this.kick.start; - this.kick.speed = this.kick.distance / this.kick.time; + this.kick.speed = this.kick.distance / this.kick.time * 40; this.kick.direction = this.playerRotation.x; + if (this.kick.speed > 1) { + this.kick.speed = 1; + } + + console.log(this.kick.speed); + var v = new THREE.Vector3(0, 0, -1); v.multiplyScalar(this.kick.speed); @@ -142,20 +186,26 @@ R3.CustomCode.prototype.move = function(data) { this.balls.push( { - ball : this.activeBall, - kick : this.kick, - v : v + mesh : this.activeBall, + speed : 6, + mouseYTravelDistance : this.kick.distance, + directionAngle : this.kick.direction + Math.PI, + upAngle : Math.PI * this.kick.speed, + v : v, + t : 0, + s0 : new THREE.Vector3(0,0,0), + bounciness : 0.5 } ); this.activeBall = null; - console.log('kick', this.kick); + //console.log('kick', this.kick); } if (canKick && this.activeBall === null) { - console.log('can kick'); + //console.log('can kick'); this.activeBall = new THREE.Mesh( this.ballGeometry.instance, @@ -181,6 +231,8 @@ R3.CustomCode.prototype.move = function(data) { * Moving down, record the distance travelled */ this.kick.distance += Math.abs(y); + + //console.log(this.kick.distance); } if (y < 0) { From 87b4966bc5224783aaf7ffd0d35ccd8d60788151 Mon Sep 17 00:00:00 2001 From: -=yb4f310 Date: Sun, 20 May 2018 16:20:34 +0200 Subject: [PATCH 08/16] nice kicking --- ff0fsum4zx.js | 184 ++++++++++++++++++++++++-------------------------- 1 file changed, 89 insertions(+), 95 deletions(-) diff --git a/ff0fsum4zx.js b/ff0fsum4zx.js index c326305..d1dc070 100644 --- a/ff0fsum4zx.js +++ b/ff0fsum4zx.js @@ -33,18 +33,20 @@ this.playerRotation = { y : 0 }; -this.kick = { - start : null, - distance : 0, - time : 0, - speed : 0, - direction : 0 -}; - this.balls = []; this.activeBall = this.football.instance; +this.canKick = false; + +this.kick = false; + +this.startTime = null; + +this.kickDuration = 0; + +this.kickDistance = 0; + R3.CustomCode.prototype.calcPosition = function(shotAngle, lookAngle, t) { @@ -84,7 +86,7 @@ R3.CustomCode.prototype.render = function(delta) { ); - ball.mesh.rotateOnAxis(v.normalize(), -0.1); + ball.mesh.rotateOnAxis(v.normalize(), -0.2); //object.ball.translateOnAxis(object.v, 1); @@ -101,44 +103,79 @@ R3.CustomCode.prototype.move = function(data) { var y = data.y; if (data.source === 'mouse' || 'touch') { - x *= 0.01; - y *= 0.01; + x *= 0.0025; + y *= 0.0075; } this.playerRotation.x += x; this.playerRotation.y += y; - var kick = false; - - var canKick = false; - - if (this.playerRotation.y > Math.PI) { - canKick = true; - } - /** * Clamp player rotation to values between 0 and Math.PI * 2 */ - if (this.playerRotation.y > Math.PI * 2) { - this.playerRotation.y -= Math.PI * 2; - kick = true; - canKick = false; + if (this.playerRotation.y > Math.PI) { + this.playerRotation.y = Math.PI; } - if (this.playerRotation.y < 0) { - this.playerRotation.y += Math.PI * 2; - canKick = true; + if (this.playerRotation.y < -Math.PI) { + this.playerRotation.y = -Math.PI; } - /** - * Clamp direction angle between 0 and Math.PI * 2 - */ - if (this.playerRotation.x > Math.PI * 2) { - this.playerRotation.x -= Math.PI * 2; + if (this.playerRotation.x > Math.PI / 2) { + this.playerRotation.x = Math.PI / 2; } - if (this.playerRotation.x < 0) { - this.playerRotation.x += Math.PI * 2; + if (this.playerRotation.x < -Math.PI / 2) { + this.playerRotation.x = -Math.PI / 2; + } + + if (this.playerRotation.y <= 0) { + this.canKick = true; + } + + if (this.canKick && this.playerRotation.y > 0) { + this.canKick = false; + this.kick = true; + } + + if (y > 0 && this.canKick) { + + /** + * Moving down, initialize start time and record the distance travelled + */ + if (this.startTime === null) { + this.startTime = Date.now(); + } + + this.kickDistance += Math.abs(y); + + } + + if (y < 0) { + /** + * We are no longer moving down, also reset our Y distance counter + * @type {boolean} + */ + this.kickDistance = 0; + this.startTime = null; + } + + + if (this.canKick && this.activeBall === null) { + + console.log('can kick - creating new ball'); + + this.activeBall = new THREE.Mesh( + this.ballGeometry.instance, + [ + this.materialWhite.instance, + this.materialBlack.instance + ] + ); + + this.activeBall.scale.copy(this.football.instance.scale); + + this.football.parentScene.instance.add(this.activeBall); } this.footballPlayer.instance.matrix = new THREE.Matrix4(); @@ -152,45 +189,48 @@ R3.CustomCode.prototype.move = function(data) { this.footballPlayer.instance.rotateY(this.playerRotation.x); - this.footballPlayer.instance.translateZ(0.2); + this.footballPlayer.instance.translateZ(0.3); this.footballPlayer.instance.rotateX(this.playerRotation.y); - if (kick) { + if (this.kick) { - if (this.kick.start === null) { + this.kick = false; + + if (this.startTime === null) { console.warn('no kick start time'); return; } - this.kick.time = Date.now() - this.kick.start; + var kickDuration = Date.now() - this.startTime; - this.kick.speed = this.kick.distance / this.kick.time * 40; + var speed = this.kickDistance / kickDuration * 20; - this.kick.direction = this.playerRotation.x; +// if (speed > 1.5) { +// speed = 1.5; +// } - if (this.kick.speed > 1) { - this.kick.speed = 1; - } - - console.log(this.kick.speed); + console.log(speed); var v = new THREE.Vector3(0, 0, -1); - v.multiplyScalar(this.kick.speed); + v.multiplyScalar(speed); v.applyAxisAngle( new THREE.Vector3(0,1,0), - this.kick.direction + this.playerRotation.x ); this.balls.push( { mesh : this.activeBall, - speed : 6, + speed : 8, mouseYTravelDistance : this.kick.distance, - directionAngle : this.kick.direction + Math.PI, - upAngle : Math.PI * this.kick.speed, + directionAngle : this.playerRotation.x + Math.PI, + kickDuration : this.kickDuration, + kickDistance : this.kickDistance, + kickSpeed : speed, + upAngle : Math.PI * speed, v : v, t : 0, s0 : new THREE.Vector3(0,0,0), @@ -199,56 +239,10 @@ R3.CustomCode.prototype.move = function(data) { ); this.activeBall = null; - - //console.log('kick', this.kick); } - if (canKick && this.activeBall === null) { - //console.log('can kick'); - this.activeBall = new THREE.Mesh( - this.ballGeometry.instance, - [ - this.materialWhite.instance, - this.materialBlack.instance - ] - ); - - this.activeBall.scale.copy(this.football.instance.scale); - //this.activeBall.scale.copy(this.football.instance.scale); - - this.football.parentScene.instance.add(this.activeBall); - } - - if (y > 0 && canKick) { - - if (this.kick.start === null) { - this.kick.start = Date.now(); - } - - /** - * Moving down, record the distance travelled - */ - this.kick.distance += Math.abs(y); - - //console.log(this.kick.distance); - } - - if (y < 0) { - - /** - * We are no longer moving down, also reset our Y distance counter - * @type {boolean} - */ - this.kick = { - start : null, - distance : 0, - time : 0, - speed : 0, - direction : 0 - }; - } }.bind(this) From 3f265a843629cfbdd9b5cf529d3bef0855e16bcc Mon Sep 17 00:00:00 2001 From: -=yb4f310 Date: Sun, 20 May 2018 16:25:18 +0200 Subject: [PATCH 09/16] Update: CC - Touch Move - AR Football 3 (p49pad0i7l.js) 30 bytes modified --- p49pad0i7l.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/p49pad0i7l.js b/p49pad0i7l.js index a1bfa14..23e5a26 100644 --- a/p49pad0i7l.js +++ b/p49pad0i7l.js @@ -3,6 +3,8 @@ if (!this.entityLoaded) { return; } +data.event.preventDefault(); + this.entityLoaded.move( { source : 'touch', From 838a71f78e53815e2cc5a218ff926e7933cc1ec0 Mon Sep 17 00:00:00 2001 From: -=yb4f310 Date: Sun, 20 May 2018 22:50:22 +0200 Subject: [PATCH 10/16] nice ball motion --- ff0fsum4zx.js | 161 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 145 insertions(+), 16 deletions(-) diff --git a/ff0fsum4zx.js b/ff0fsum4zx.js index d1dc070..b00dd38 100644 --- a/ff0fsum4zx.js +++ b/ff0fsum4zx.js @@ -16,6 +16,9 @@ this.beforeRender = R3.EntityManager.Instance.findComponentById('7l8ar325qf'); */ this.footballPlayer = R3.EntityManager.Instance.findComponentById('t537n02x0s'); this.football = R3.EntityManager.Instance.findComponentById('umgbzb0ur2'); +this.goalL = R3.EntityManager.Instance.findComponentById('ackykfwyd4'); +this.goalR = R3.EntityManager.Instance.findComponentById('040yhx0atm'); +this.goalWithHoles = R3.EntityManager.Instance.findComponentById('p3oxe63wjm'); /** * Geometry @@ -28,6 +31,11 @@ this.ballGeometry = R3.EntityManager.Instance.findComponentById('dt6jl8kocw'); this.materialWhite = R3.EntityManager.Instance.findComponentById('iualutcl1y'); this.materialBlack = R3.EntityManager.Instance.findComponentById('2g36po454g'); +/** + * Scenes + */ +this.arScene = R3.EntityManager.Instance.findComponentById('grb0df22dd'); + this.playerRotation = { x : 0, y : 0 @@ -47,11 +55,20 @@ this.kickDuration = 0; this.kickDistance = 0; -R3.CustomCode.prototype.calcPosition = function(shotAngle, lookAngle, t) { +this.raycaster = new THREE.Raycaster(); +this.debug = true; +this.gravity = -9.8; -}; +if (this.debug) { + this.arrowHelper = new THREE.ArrowHelper( + new THREE.Vector3(0,0,-1), + new THREE.Vector3(0,0,0), + 1 + ); + this.arScene.instance.add(this.arrowHelper); +} R3.CustomCode.prototype.render = function(delta) { @@ -59,6 +76,16 @@ R3.CustomCode.prototype.render = function(delta) { function(ball) { + if (ball.stopped) { + return; + } + + if (ball.speed <= 0) { + ball.stopped = true; + } + + ball.speed -= delta * 2; + ball.t += delta; var u = new THREE.Vector3( @@ -68,29 +95,115 @@ R3.CustomCode.prototype.render = function(delta) { ); ball.mesh.position.x = ball.s0.x + u.x * ball.t; - ball.mesh.position.y = ball.s0.y + u.y * ball.t + 0.5 * (-9.8) * ball.t * ball.t; + ball.mesh.position.y = ball.s0.y + u.y * ball.t + 0.5 * (this.gravity) * ball.t * ball.t; ball.mesh.position.z = ball.s0.z + u.z * ball.t; - if (ball.mesh.position.y <= 0) { + /** + * Bounce + */ + if (ball.mesh.position.y <= 0.18) { ball.s0.x = ball.mesh.position.x; - ball.s0.y = 0; + ball.s0.y = 0.18; ball.s0.z = ball.mesh.position.z; ball.upAngle *= ball.bounciness; ball.t = 0; } - var v = new THREE.Vector3( - -ball.v.z, - 0, - ball.v.x - ); + /** + * Check for goal collision + */ + var goalDistanceL = this.goalL.position.distanceTo(ball.mesh.position); + var goalDistanceR = this.goalR.position.distanceTo(ball.mesh.position); + + if (goalDistanceL < (this.goalL.geometry.boundingSphere.radius - ball.mesh.geometry.boundingSphere.radius)) { + if (ball.scored === false) { + console.log('left goal!'); + ball.scored = true; + ball.scoredThroughGoal = 'left'; + } + } + + if (goalDistanceR < (this.goalR.geometry.boundingSphere.radius - ball.mesh.geometry.boundingSphere.radius)) { + if (ball.scored === false) { + console.log('right goal!'); + ball.scored = true; + ball.scoredThroughGoal = 'right'; + } + } - ball.mesh.rotateOnAxis(v.normalize(), -0.2); - //object.ball.translateOnAxis(object.v, 1); + /** + * Check for goal reflection + */ + var futureTime = ball.t + delta; - //object.ball.position.y = object.ball.position.y + 0.5 * (-9.8) * object.t * object.t; + ball.s1.x = ball.s0.x + u.x * futureTime; + ball.s1.y = ball.s0.y + u.y * futureTime + 0.5 * (this.gravity) * futureTime * futureTime; + ball.s1.z = ball.s0.z + u.z * futureTime; + + //var distance = ball.mesh.position.distanceTo(ball.s1); + + var direction = ball.s1.sub(ball.mesh.position).normalize(); + + if (this.debug) { + this.arrowHelper.position.copy(ball.mesh.position); + this.arrowHelper.setDirection(direction); + this.arrowHelper.setLength(1); + } + + if ( + !ball.scored && + ball.mesh.position.z < -4 && + ball.mesh.position.z > -5 + ) { + + console.warn('check for collision'); + this.raycaster.set(ball.mesh.position, direction); + this.raycaster.intersectObjects([ + this.goalWithHoles.instance + ]).map( + function(intersect) { + + if (intersect.distance < ball.mesh.geometry.boundingSphere.radius) { + + var normal = new THREE.Vector3( + intersect.object.geometry.getAttribute('normal').array[0], + intersect.object.geometry.getAttribute('normal').array[1], + intersect.object.geometry.getAttribute('normal').array[2] + ); + + var reflect = direction.reflect(normal); + + var angle = direction.angleTo(reflect); + + ball.directionAngle = angle; + ball.s0.x = ball.mesh.position.x; + ball.s0.y = ball.mesh.position.y; + ball.s0.z = ball.mesh.position.z; + ball.upAngle *= ball.bounciness; + ball.speed *= ball.bounciness * 1.5; + ball.t = 0; + console.log('collision', reflect); + + ball.v.copy(direction); + + ball.vRotationAxis.x *= -1; + ball.vRotationAxis.z *= -1; + } + } + ) + } + + // if (ball.mesh.position.z <= -5 && !ball.scored && ball.lastIntersect) { + // console.log(ball.lastIntersect); + // } + + + /** + * Rotate the ball + */ + ball.mesh.rotateOnAxis(ball.vRotationAxis, -ball.speed * 0.04); }.bind(this) @@ -174,6 +287,7 @@ R3.CustomCode.prototype.move = function(data) { ); this.activeBall.scale.copy(this.football.instance.scale); + this.activeBall.position.y = 0.18; this.football.parentScene.instance.add(this.activeBall); } @@ -210,7 +324,7 @@ R3.CustomCode.prototype.move = function(data) { // speed = 1.5; // } - console.log(speed); +// console.log(speed); var v = new THREE.Vector3(0, 0, -1); @@ -221,6 +335,12 @@ R3.CustomCode.prototype.move = function(data) { this.playerRotation.x ); + var vRotationAxis = new THREE.Vector3( + -v.z, + 0, + v.x + ).normalize(); + this.balls.push( { mesh : this.activeBall, @@ -232,9 +352,14 @@ R3.CustomCode.prototype.move = function(data) { kickSpeed : speed, upAngle : Math.PI * speed, v : v, + vRotationAxis : vRotationAxis, t : 0, - s0 : new THREE.Vector3(0,0,0), - bounciness : 0.5 + s0 : new THREE.Vector3(0,0.18,0), + s1 : new THREE.Vector3(0,0.18,0), + bounciness : 0.5, + scored : false, + scoredThroughGoal : null, + stopped :false } ); @@ -246,8 +371,12 @@ R3.CustomCode.prototype.move = function(data) { }.bind(this) +this.footballPlayer.instance.translateY(0.78); +this.football.instance.position.y = 0.18; + this.mouseMove.entityLoaded = this; this.touchMove.entityLoaded = this; this.beforeRender.entityLoaded = this; + //@ sourceURL=entityLoaded.js \ No newline at end of file From f333c89486d137c13f7250ac7cb4a00d644ecfc8 Mon Sep 17 00:00:00 2001 From: -=yb4f310 Date: Mon, 21 May 2018 00:06:04 +0200 Subject: [PATCH 11/16] sound --- ff0fsum4zx.js | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/ff0fsum4zx.js b/ff0fsum4zx.js index b00dd38..817fee2 100644 --- a/ff0fsum4zx.js +++ b/ff0fsum4zx.js @@ -120,6 +120,12 @@ R3.CustomCode.prototype.render = function(delta) { console.log('left goal!'); ball.scored = true; ball.scoredThroughGoal = 'left'; + R3.Event.Emit( + R3.Event.PLAY_AUDIO, + { + name : 'Audio - Crowd Cheer' + } + ); } } @@ -128,11 +134,15 @@ R3.CustomCode.prototype.render = function(delta) { console.log('right goal!'); ball.scored = true; ball.scoredThroughGoal = 'right'; + R3.Event.Emit( + R3.Event.PLAY_AUDIO, + { + name : 'Audio - Crowd Cheer' + } + ); } } - - /** * Check for goal reflection */ @@ -316,6 +326,13 @@ R3.CustomCode.prototype.move = function(data) { return; } + R3.Event.Emit( + R3.Event.PLAY_AUDIO, + { + name : 'Audio - Kick' + } + ); + var kickDuration = Date.now() - this.startTime; var speed = this.kickDistance / kickDuration * 20; @@ -378,5 +395,11 @@ this.mouseMove.entityLoaded = this; this.touchMove.entityLoaded = this; this.beforeRender.entityLoaded = this; +R3.Event.Emit( + R3.Event.PLAY_AUDIO, + { + name : 'Audio - Crowd' + } +); //@ sourceURL=entityLoaded.js \ No newline at end of file From 6302f44ddf49426a15a8de528d7c16c33692d823 Mon Sep 17 00:00:00 2001 From: -=yb4f310 Date: Mon, 21 May 2018 14:40:51 +0200 Subject: [PATCH 12/16] remove logs --- ff0fsum4zx.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/ff0fsum4zx.js b/ff0fsum4zx.js index 817fee2..f3053f1 100644 --- a/ff0fsum4zx.js +++ b/ff0fsum4zx.js @@ -61,6 +61,8 @@ this.debug = true; this.gravity = -9.8; +this.initialSpeed = 10; + if (this.debug) { this.arrowHelper = new THREE.ArrowHelper( new THREE.Vector3(0,0,-1), @@ -168,7 +170,6 @@ R3.CustomCode.prototype.render = function(delta) { ball.mesh.position.z > -5 ) { - console.warn('check for collision'); this.raycaster.set(ball.mesh.position, direction); this.raycaster.intersectObjects([ this.goalWithHoles.instance @@ -194,7 +195,6 @@ R3.CustomCode.prototype.render = function(delta) { ball.upAngle *= ball.bounciness; ball.speed *= ball.bounciness * 1.5; ball.t = 0; - console.log('collision', reflect); ball.v.copy(direction); @@ -286,8 +286,6 @@ R3.CustomCode.prototype.move = function(data) { if (this.canKick && this.activeBall === null) { - console.log('can kick - creating new ball'); - this.activeBall = new THREE.Mesh( this.ballGeometry.instance, [ @@ -361,7 +359,7 @@ R3.CustomCode.prototype.move = function(data) { this.balls.push( { mesh : this.activeBall, - speed : 8, + speed : this.initialSpeed, mouseYTravelDistance : this.kick.distance, directionAngle : this.playerRotation.x + Math.PI, kickDuration : this.kickDuration, From 09ead277e5f154be6594316a66fed77d2f6d06fe Mon Sep 17 00:00:00 2001 From: -=yb4f310 Date: Mon, 21 May 2018 14:43:16 +0200 Subject: [PATCH 13/16] Update: CC - Entity Loaded - AR Football 3 (ff0fsum4zx.js) 170 bytes modified --- ff0fsum4zx.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ff0fsum4zx.js b/ff0fsum4zx.js index f3053f1..954c79d 100644 --- a/ff0fsum4zx.js +++ b/ff0fsum4zx.js @@ -170,6 +170,7 @@ R3.CustomCode.prototype.render = function(delta) { ball.mesh.position.z > -5 ) { + console.warn('check for collision'); this.raycaster.set(ball.mesh.position, direction); this.raycaster.intersectObjects([ this.goalWithHoles.instance @@ -195,6 +196,7 @@ R3.CustomCode.prototype.render = function(delta) { ball.upAngle *= ball.bounciness; ball.speed *= ball.bounciness * 1.5; ball.t = 0; + console.log('collision', reflect); ball.v.copy(direction); @@ -286,6 +288,8 @@ R3.CustomCode.prototype.move = function(data) { if (this.canKick && this.activeBall === null) { + console.log('can kick - creating new ball'); + this.activeBall = new THREE.Mesh( this.ballGeometry.instance, [ From 8d4f5b8b2476086ba7f928d5cc4abad46169a9dc Mon Sep 17 00:00:00 2001 From: -=yb4f310 Date: Mon, 21 May 2018 14:52:05 +0200 Subject: [PATCH 14/16] Update: CC - Mouse Move - AR Football 3 (dwxvtxzrun.js) 30 bytes modified --- dwxvtxzrun.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dwxvtxzrun.js b/dwxvtxzrun.js index bc0bcbb..76e4577 100644 --- a/dwxvtxzrun.js +++ b/dwxvtxzrun.js @@ -3,6 +3,8 @@ if (!this.entityLoaded) { return; } +data.event.preventDefault(); + this.entityLoaded.move( { source : 'mouse', From 8f217a08383719a8a30af56962b6cd087393c6cd Mon Sep 17 00:00:00 2001 From: -=yb4f310 Date: Mon, 21 May 2018 14:53:17 +0200 Subject: [PATCH 15/16] fixes --- ff0fsum4zx.js | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/ff0fsum4zx.js b/ff0fsum4zx.js index 954c79d..7b6bd52 100644 --- a/ff0fsum4zx.js +++ b/ff0fsum4zx.js @@ -57,7 +57,7 @@ this.kickDistance = 0; this.raycaster = new THREE.Raycaster(); -this.debug = true; +this.debug = false; this.gravity = -9.8; @@ -170,7 +170,6 @@ R3.CustomCode.prototype.render = function(delta) { ball.mesh.position.z > -5 ) { - console.warn('check for collision'); this.raycaster.set(ball.mesh.position, direction); this.raycaster.intersectObjects([ this.goalWithHoles.instance @@ -196,7 +195,6 @@ R3.CustomCode.prototype.render = function(delta) { ball.upAngle *= ball.bounciness; ball.speed *= ball.bounciness * 1.5; ball.t = 0; - console.log('collision', reflect); ball.v.copy(direction); @@ -227,10 +225,8 @@ R3.CustomCode.prototype.move = function(data) { var x = data.x; var y = data.y; - if (data.source === 'mouse' || 'touch') { - x *= 0.0025; - y *= 0.0075; - } + x *= 0.0025; + y *= 0.0075; this.playerRotation.x += x; this.playerRotation.y += y; @@ -288,8 +284,6 @@ R3.CustomCode.prototype.move = function(data) { if (this.canKick && this.activeBall === null) { - console.log('can kick - creating new ball'); - this.activeBall = new THREE.Mesh( this.ballGeometry.instance, [ From f23218eae997dcb1338e07668bc939b805c530f1 Mon Sep 17 00:00:00 2001 From: -=yb4f310 Date: Mon, 21 May 2018 15:02:20 +0200 Subject: [PATCH 16/16] fixes --- ff0fsum4zx.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ff0fsum4zx.js b/ff0fsum4zx.js index 7b6bd52..f0dd121 100644 --- a/ff0fsum4zx.js +++ b/ff0fsum4zx.js @@ -222,8 +222,8 @@ R3.CustomCode.prototype.render = function(delta) { R3.CustomCode.prototype.move = function(data) { - var x = data.x; - var y = data.y; + var x = data.x || 0; + var y = data.y || 0; x *= 0.0025; y *= 0.0075;