2018-05-17 12:42:33 +02:00
|
|
|
if (data.entity === this.parentEntity) {
|
|
|
|
console.log('AR Football 2 Entity Loaded');
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Code Components
|
|
|
|
*/
|
|
|
|
this.mouseMove = R3.EntityManager.Instance.findComponentById('dwxvtxzrun');
|
2018-05-17 15:37:56 +02:00
|
|
|
this.touchMove = R3.EntityManager.Instance.findComponentById('p49pad0i7l');
|
2018-05-18 15:31:22 +02:00
|
|
|
this.beforeRender = R3.EntityManager.Instance.findComponentById('7l8ar325qf');
|
2018-05-17 12:42:33 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Meshes
|
|
|
|
*/
|
|
|
|
this.footballPlayer = R3.EntityManager.Instance.findComponentById('t537n02x0s');
|
2018-05-18 15:31:22 +02:00
|
|
|
this.football = R3.EntityManager.Instance.findComponentById('umgbzb0ur2');
|
2018-05-17 12:42:33 +02:00
|
|
|
|
2018-05-18 15:31:22 +02:00
|
|
|
/**
|
|
|
|
* Geometry
|
|
|
|
*/
|
|
|
|
this.ballGeometry = R3.EntityManager.Instance.findComponentById('dt6jl8kocw');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Materials
|
|
|
|
*/
|
|
|
|
this.materialWhite = R3.EntityManager.Instance.findComponentById('iualutcl1y');
|
|
|
|
this.materialBlack = R3.EntityManager.Instance.findComponentById('2g36po454g');
|
2018-05-17 15:37:56 +02:00
|
|
|
|
2018-05-17 12:42:33 +02:00
|
|
|
this.playerRotation = {
|
|
|
|
x : 0,
|
|
|
|
y : 0
|
|
|
|
};
|
|
|
|
|
2018-05-18 15:31:22 +02:00
|
|
|
this.kick = {
|
|
|
|
start : null,
|
|
|
|
distance : 0,
|
|
|
|
time : 0,
|
|
|
|
speed : 0,
|
|
|
|
direction : 0
|
|
|
|
};
|
|
|
|
|
|
|
|
this.balls = [];
|
|
|
|
|
|
|
|
this.activeBall = this.football.instance;
|
2018-05-17 15:37:56 +02:00
|
|
|
|
2018-05-18 15:31:22 +02:00
|
|
|
R3.CustomCode.prototype.render = function(delta) {
|
2018-05-17 15:37:56 +02:00
|
|
|
|
2018-05-18 15:31:22 +02:00
|
|
|
this.balls.map(
|
|
|
|
function(object) {
|
|
|
|
var ball = object.ball;
|
|
|
|
var kick = object.kick;
|
|
|
|
|
|
|
|
ball.translateOnAxis(object.v, 1);
|
|
|
|
}
|
|
|
|
)
|
2018-05-17 15:37:56 +02:00
|
|
|
};
|
|
|
|
|
2018-05-17 12:42:33 +02:00
|
|
|
R3.CustomCode.prototype.move = function(data) {
|
|
|
|
|
|
|
|
var x = data.x;
|
|
|
|
var y = data.y;
|
|
|
|
|
2018-05-17 15:37:56 +02:00
|
|
|
if (data.source === 'mouse' || 'touch') {
|
2018-05-17 12:42:33 +02:00
|
|
|
x *= 0.01;
|
|
|
|
y *= 0.01;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.playerRotation.x += x;
|
|
|
|
this.playerRotation.y += y;
|
|
|
|
|
2018-05-17 15:37:56 +02:00
|
|
|
var kick = false;
|
|
|
|
|
|
|
|
var canKick = false;
|
|
|
|
|
|
|
|
if (this.playerRotation.y > Math.PI) {
|
|
|
|
canKick = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-05-18 15:31:22 +02:00
|
|
|
* Clamp player rotation to values between 0 and Math.PI * 2
|
2018-05-17 15:37:56 +02:00
|
|
|
*/
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-05-18 15:31:22 +02:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
|
2018-05-17 12:42:33 +02:00
|
|
|
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);
|
|
|
|
|
2018-05-17 15:37:56 +02:00
|
|
|
if (kick) {
|
2018-05-17 12:42:33 +02:00
|
|
|
|
2018-05-18 15:31:22 +02:00
|
|
|
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);
|
2018-05-17 15:37:56 +02:00
|
|
|
}
|
2018-05-17 12:42:33 +02:00
|
|
|
|
2018-05-18 15:31:22 +02:00
|
|
|
if (canKick && this.activeBall === null) {
|
2018-05-17 12:42:33 +02:00
|
|
|
|
2018-05-18 15:31:22 +02:00
|
|
|
console.log('can kick');
|
2018-05-17 12:42:33 +02:00
|
|
|
|
2018-05-18 15:31:22 +02:00
|
|
|
this.activeBall = new THREE.Mesh(
|
|
|
|
this.ballGeometry.instance,
|
|
|
|
[
|
|
|
|
this.materialWhite.instance,
|
|
|
|
this.materialBlack.instance
|
|
|
|
]
|
|
|
|
);
|
2018-05-17 12:42:33 +02:00
|
|
|
|
2018-05-18 15:31:22 +02:00
|
|
|
this.activeBall.scale.copy(this.football.instance.scale);
|
|
|
|
//this.activeBall.scale.copy(this.football.instance.scale);
|
2018-05-17 12:42:33 +02:00
|
|
|
|
2018-05-18 15:31:22 +02:00
|
|
|
this.football.parentScene.instance.add(this.activeBall);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (y > 0 && canKick) {
|
|
|
|
|
|
|
|
if (this.kick.start === null) {
|
|
|
|
this.kick.start = Date.now();
|
2018-05-17 15:37:56 +02:00
|
|
|
}
|
2018-05-17 12:42:33 +02:00
|
|
|
|
2018-05-17 15:37:56 +02:00
|
|
|
/**
|
2018-05-18 15:31:22 +02:00
|
|
|
* Moving down, record the distance travelled
|
2018-05-17 15:37:56 +02:00
|
|
|
*/
|
2018-05-18 15:31:22 +02:00
|
|
|
this.kick.distance += Math.abs(y);
|
2018-05-17 15:37:56 +02:00
|
|
|
}
|
2018-05-17 12:42:33 +02:00
|
|
|
|
2018-05-17 15:37:56 +02:00
|
|
|
if (y < 0) {
|
2018-05-17 12:42:33 +02:00
|
|
|
|
2018-05-18 15:31:22 +02:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
};
|
|
|
|
}
|
2018-05-17 12:42:33 +02:00
|
|
|
|
|
|
|
}.bind(this)
|
|
|
|
|
|
|
|
this.mouseMove.entityLoaded = this;
|
2018-05-17 15:37:56 +02:00
|
|
|
this.touchMove.entityLoaded = this;
|
2018-05-18 15:31:22 +02:00
|
|
|
this.beforeRender.entityLoaded = this;
|
2018-05-17 12:42:33 +02:00
|
|
|
|
|
|
|
//@ sourceURL=entityLoaded.js
|