2017-11-15 13:42:29 +01:00
|
|
|
if (!this.entityLoaded) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.initialized) {
|
|
|
|
this.mouse = this.entityLoaded.mouse;
|
|
|
|
this.raycaster = this.entityLoaded.raycaster;
|
|
|
|
this.camera = this.entityLoaded.camera;
|
|
|
|
this.cursor = this.entityLoaded.cursor;
|
|
|
|
this.thrower = this.entityLoaded.thrower;
|
|
|
|
this.throwerParticleEngine = this.entityLoaded.throwerParticleEngine;
|
|
|
|
this.initialized = true;
|
|
|
|
}
|
|
|
|
|
2017-11-15 14:08:20 +01:00
|
|
|
this.mouse.x = (data.event.offsetX / data.event.target.width ) * 2 - 1;
|
|
|
|
this.mouse.y = -(data.event.offsetY / data.event.target.height) * 2 + 1;
|
2017-11-15 13:42:29 +01:00
|
|
|
|
|
|
|
this.camera.lookAt.x = this.mouse.x * 20;
|
|
|
|
this.camera.lookAt.y = this.mouse.y * 20;
|
|
|
|
this.camera.lookAt.z = Math.cos(this.mouse.x) + Math.sin(this.mouse.y);
|
|
|
|
this.camera.updateInstance();
|
|
|
|
|
|
|
|
this.raycaster.setFromCamera(
|
|
|
|
this.mouse,
|
|
|
|
this.camera
|
|
|
|
);
|
|
|
|
|
|
|
|
var distance = - this.camera.position.z / this.raycaster.direction.z;
|
|
|
|
var cursorPosition = this.camera.position.clone().add(
|
|
|
|
this.raycaster.direction.clone().multiply(
|
|
|
|
distance,
|
|
|
|
true
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
this.cursor.position.x = cursorPosition.x;
|
|
|
|
this.cursor.position.y = cursorPosition.y;
|
|
|
|
this.cursor.position.z = cursorPosition.z;
|
|
|
|
this.cursor.updateInstancePosition();
|
|
|
|
|
|
|
|
this.cursor.instance.quaternion.copy(this.camera.instance.quaternion);
|
|
|
|
|
|
|
|
this.thrower.lookAt(this.cursor.position);
|
|
|
|
|
|
|
|
this.throwerParticleEngine.direction.x = this.raycaster.direction.x;
|
|
|
|
this.throwerParticleEngine.direction.y = this.raycaster.direction.y;
|
|
|
|
this.throwerParticleEngine.direction.z = this.raycaster.direction.z;
|
|
|
|
this.throwerParticleEngine.updateInstance('direction');
|
|
|
|
|
|
|
|
this.throwerParticleEngine.position.x = this.thrower.position.x + this.raycaster.direction.x * 6;
|
|
|
|
this.throwerParticleEngine.position.y = this.thrower.position.y + this.raycaster.direction.y * 6 + 0.3;
|
|
|
|
this.throwerParticleEngine.position.z = this.thrower.position.z + this.raycaster.direction.z * 6;
|
|
|
|
this.throwerParticleEngine.updateInstance('position');
|
|
|
|
|
|
|
|
/*
|
|
|
|
this.scene.meshes.map(
|
|
|
|
function(mesh) {
|
|
|
|
if (mesh.instance.material instanceof Array) {
|
|
|
|
mesh.instance.material.map(
|
|
|
|
function(material) {
|
|
|
|
material.color.setHex(0xffffff);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
mesh.instance.material.color.setHex(0xffffff);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//@ sourceURL=mouseMove.js
|