From 9f656ce066958dfd11d3b523c320740a510b8eb0 Mon Sep 17 00:00:00 2001 From: Theunis Johannes Botha Date: Thu, 17 May 2018 14:46:46 +0200 Subject: [PATCH 01/11] Initial Commit: CC - Touch Move - AR Football 3 (p49pad0i7l.js) --- p49pad0i7l.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 p49pad0i7l.js diff --git a/p49pad0i7l.js b/p49pad0i7l.js new file mode 100644 index 0000000..599b3f8 --- /dev/null +++ b/p49pad0i7l.js @@ -0,0 +1,14 @@ + +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 0e9c66e63c9c0eb324fcca31f0b237a755cbf851 Mon Sep 17 00:00:00 2001 From: Theunis Johannes Botha Date: Fri, 18 May 2018 14:43:07 +0200 Subject: [PATCH 02/11] Update: CC - Entity Loaded - AR Football 3 (ff0fsum4zx.js) 1246 bytes modified --- ff0fsum4zx.js | 173 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 173 insertions(+) create mode 100644 ff0fsum4zx.js diff --git a/ff0fsum4zx.js b/ff0fsum4zx.js new file mode 100644 index 0000000..74b830c --- /dev/null +++ b/ff0fsum4zx.js @@ -0,0 +1,173 @@ +if (data.entity === this.parentEntity) { + console.log('AR Football 2 Entity Loaded'); +} else { + return; +} + +/** + * 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.football = R3.EntityManager.Instance.findComponentById('umgbzb0ur2'); + +/** + * 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 +}; + +this.balls = []; + +this.activeBall = this.football.instance; + +R3.CustomCode.prototype.move = function(data) { + + var x = data.x; + var y = data.y; + + if (data.source === 'mouse' || 'touch') { + x *= 0.01; + y *= 0.01; + } + + 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 < 0) { + this.playerRotation.y += Math.PI * 2; + 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, + 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); + + if (kick) { + + 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; + + this.balls.push(this.activeBall); + + 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 + ] + ); + } + + 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); + } + + 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) + +this.mouseMove.entityLoaded = this; +this.touchMove.entityLoaded = this; + +//@ sourceURL=entityLoaded.js \ No newline at end of file From faa71712da4132c210a583858db370858d079794 Mon Sep 17 00:00:00 2001 From: Theunis Johannes Botha Date: Fri, 18 May 2018 14:43:07 +0200 Subject: [PATCH 03/11] Update: CC - Mouse Move - AR Football 3 (dwxvtxzrun.js) 11 bytes modified --- 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..bc0bcbb --- /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=mouseMove.js \ No newline at end of file From 8e263c3f11b65571893bfad506c09dd72d890f81 Mon Sep 17 00:00:00 2001 From: Theunis Johannes Botha Date: Sun, 20 May 2018 13:37:10 +0200 Subject: [PATCH 04/11] Update: CC - Entity Loaded - AR Football 3 (ff0fsum4zx.js) 1503 bytes modified --- ff0fsum4zx.js | 96 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 91 insertions(+), 5 deletions(-) diff --git a/ff0fsum4zx.js b/ff0fsum4zx.js index 74b830c..c326305 100644 --- a/ff0fsum4zx.js +++ b/ff0fsum4zx.js @@ -9,6 +9,7 @@ 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 @@ -44,6 +45,56 @@ 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(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) + ) +}; + R3.CustomCode.prototype.move = function(data) { var x = data.x; @@ -114,20 +165,47 @@ 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; + this.kick.direction = this.playerRotation.x; - this.balls.push(this.activeBall); + 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); + + v.applyAxisAngle( + new THREE.Vector3(0,1,0), + this.kick.direction + ); + + this.balls.push( + { + 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, @@ -136,6 +214,11 @@ R3.CustomCode.prototype.move = function(data) { 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) { @@ -148,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) { @@ -169,5 +254,6 @@ R3.CustomCode.prototype.move = function(data) { this.mouseMove.entityLoaded = this; this.touchMove.entityLoaded = this; +this.beforeRender.entityLoaded = this; //@ sourceURL=entityLoaded.js \ No newline at end of file From 3b7710a5a35e30c88e11450099f5373f0595f9fe Mon Sep 17 00:00:00 2001 From: Theunis Johannes Botha Date: Sun, 20 May 2018 16:21:03 +0200 Subject: [PATCH 05/11] Update: CC - Entity Loaded - AR Football 3 (ff0fsum4zx.js) 153 bytes modified --- 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 5973d8c0d8a4c2e1eb8c4013e3999749597efa3d Mon Sep 17 00:00:00 2001 From: Theunis Johannes Botha Date: Sun, 20 May 2018 16:25:29 +0200 Subject: [PATCH 06/11] Update: CC - Touch Move - AR Football 3 (p49pad0i7l.js) 30 bytes modified --- p49pad0i7l.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/p49pad0i7l.js b/p49pad0i7l.js index 599b3f8..23e5a26 100644 --- a/p49pad0i7l.js +++ b/p49pad0i7l.js @@ -3,11 +3,13 @@ if (!this.entityLoaded) { return; } +data.event.preventDefault(); + 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 b9d3aa497e02c5e0c3dbbf153cb51fb8bf154f24 Mon Sep 17 00:00:00 2001 From: Theunis Johannes Botha Date: Sun, 20 May 2018 22:51:07 +0200 Subject: [PATCH 07/11] Update: CC - Entity Loaded - AR Football 3 (ff0fsum4zx.js) 4573 bytes modified --- 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 bfcbfd04ab2d04a3058efc21812b2c19d97962d4 Mon Sep 17 00:00:00 2001 From: Theunis Johannes Botha Date: Sun, 20 May 2018 23:56:17 +0200 Subject: [PATCH 08/11] Update: CC - Entity Loaded - AR Football 3 (ff0fsum4zx.js) 642 bytes modified --- 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 d202e28005e56d8d34996f0542dbda8177c774c9 Mon Sep 17 00:00:00 2001 From: Theunis Johannes Botha Date: Mon, 21 May 2018 14:44:03 +0200 Subject: [PATCH 09/11] Update: CC - Entity Loaded - AR Football 3 (ff0fsum4zx.js) 129 bytes modified --- 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 2cf1410589e193790331bb516243bf7e4e1efe27 Mon Sep 17 00:00:00 2001 From: Theunis Johannes Botha Date: Mon, 21 May 2018 14:52:15 +0200 Subject: [PATCH 10/11] 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 d5509d9d7f86918aaa95f8543a8b5491309cb432 Mon Sep 17 00:00:00 2001 From: Theunis Johannes Botha Date: Mon, 21 May 2018 14:54:56 +0200 Subject: [PATCH 11/11] Update: CC - Entity Loaded - AR Football 3 (ff0fsum4zx.js) 59 bytes modified --- ff0fsum4zx.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/ff0fsum4zx.js b/ff0fsum4zx.js index f3053f1..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; @@ -225,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;