117 lines
2.5 KiB
JavaScript
117 lines
2.5 KiB
JavaScript
if (!this.entityLoaded) {
|
|
return;
|
|
}
|
|
|
|
if (!this.initialized) {
|
|
this.initialized = true;
|
|
}
|
|
|
|
this.mouse.x = (event.offsetX / event.target.width ) * 2 - 1;
|
|
this.mouse.y = -(event.offsetY / event.target.height) * 2 + 1;
|
|
|
|
this.camera.lookAt.x = this.mouse.x;
|
|
this.camera.lookAt.y = this.mouse.y;
|
|
this.camera.updateInstance();
|
|
|
|
this.raycaster.instance.setFromCamera(
|
|
this.mouse,
|
|
this.camera.instance
|
|
);
|
|
|
|
var intersects = this.raycaster.getIntersectedObjects(this.scene.meshes);
|
|
|
|
this.cursor.position.x = mouse.x;
|
|
this.cursor.position.y = mouse.y;
|
|
this.cursor.updateInstance();
|
|
|
|
this.thrower.instance.lookAt(
|
|
new THREE.Vector3(
|
|
this.cursor.position.x,
|
|
this.cursor.position.y,
|
|
this.cursor.position.z
|
|
)
|
|
);
|
|
|
|
/**
|
|
* First we find our crosshair
|
|
*/
|
|
//var crosshair = GameLib.EntityManager.Instance.findComponentById('oxpg88pgzv');
|
|
/var sphere = GameLib.EntityManager.Instance.findComponentById('ijir4gkqya');
|
|
|
|
/**
|
|
* Target, is the x / y postion of the crosshair on the z=0 plane in the crosshair scene
|
|
*/
|
|
//var target = new THREE.Vector3(
|
|
// (-1 * (window.innerWidth / 2 - data.event.x)) ,
|
|
// (window.innerHeight / 2 - data.event.y) ,
|
|
// 0
|
|
//);
|
|
/*
|
|
sphere.instance.position.copy(target);//instance.applyMatrix4( mInverse );
|
|
sphere.position.x = sphere.instance.position.x;
|
|
sphere.position.y = sphere.instance.position.y;
|
|
sphere.position.z = sphere.instance.position.z;
|
|
*/
|
|
/**
|
|
* Now we get the position of the crosshair, in our world scene space
|
|
*/
|
|
/*
|
|
target.unproject(camera.instance);
|
|
*/
|
|
/**
|
|
* We want to shoot in the other direction
|
|
*/
|
|
/*
|
|
target.normalize();
|
|
|
|
target.z *= -1;
|
|
*/
|
|
|
|
//target.sub(thrower.position.instance).normalize();
|
|
/*
|
|
var raycaster = new THREE.Raycaster();
|
|
|
|
raycaster.ray = new THREE.Ray(
|
|
cursor.position.instance,
|
|
target.instance
|
|
);
|
|
|
|
var intersects = raycaster.intersectObjects(
|
|
GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Mesh).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);
|
|
}
|
|
|
|
return mesh.instance;
|
|
}
|
|
)
|
|
);
|
|
|
|
if (intersects.length > 0) {
|
|
console.log('intersected');
|
|
intersects.map(
|
|
function(intersect){
|
|
if (mesh.instance.material instanceof Array) {
|
|
mesh.instance.material.map(
|
|
function(material) {
|
|
material.color.setHex(0xff0000);
|
|
}
|
|
);
|
|
} else {
|
|
mesh.instance.material.color.setHex(0xff0000);
|
|
}
|
|
}
|
|
)
|
|
}
|
|
*/
|
|
|
|
|
|
//@ sourceURL=mouseMove.js
|