2017-11-08 12:26:07 +01:00
|
|
|
if (!this.entityLoaded) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-06 20:44:12 +01:00
|
|
|
var camera = GameLib.EntityManager.Instance.findComponentById('knwkksjc7n');
|
2017-11-06 21:01:43 +01:00
|
|
|
camera.lookAt.x = (-1 * (window.innerWidth / 2 - data.event.x)) * 0.025;//(window.clientWidth/ 2) + data.event.x;
|
2017-11-08 17:49:25 +01:00
|
|
|
camera.lookAt.y = (((window.innerHeight / 2 - data.event.y)) * 0.05);
|
2017-11-06 20:44:12 +01:00
|
|
|
camera.updateInstance();
|
2017-11-06 20:38:13 +01:00
|
|
|
|
2017-11-07 11:23:13 +01:00
|
|
|
var cursorCamera = GameLib.EntityManager.Instance.findComponentById('b78qx660fo');
|
2017-11-07 10:41:52 +01:00
|
|
|
|
|
|
|
var mousePosition = new THREE.Vector3(
|
|
|
|
(-1 * (window.innerWidth / 2 - data.event.x)) ,
|
2017-11-07 11:23:13 +01:00
|
|
|
(window.innerHeight / 2 - data.event.y) * 1.66667,
|
2017-11-07 10:41:52 +01:00
|
|
|
0
|
|
|
|
);
|
|
|
|
|
2017-11-07 11:23:13 +01:00
|
|
|
mousePosition.unproject(cursorCamera.instance);
|
2017-11-07 10:41:52 +01:00
|
|
|
|
2017-11-07 00:51:59 +01:00
|
|
|
var cursor = GameLib.EntityManager.Instance.findComponentById('oxpg88pgzv');
|
2017-11-07 10:41:52 +01:00
|
|
|
cursor.position.x = mousePosition.x;
|
|
|
|
cursor.position.y = mousePosition.y;
|
|
|
|
//cursor.position.x = (-1 * (window.innerWidth / 2 - data.event.x)) * 0.025;
|
|
|
|
//cursor.position.y = (((window.innerHeight / 2 - data.event.y)) * 0.05);
|
2017-11-07 00:51:59 +01:00
|
|
|
cursor.updateInstance();
|
|
|
|
|
2017-11-07 01:05:06 +01:00
|
|
|
var thrower = GameLib.EntityManager.Instance.findComponentById('01viz3rw6l');
|
2017-11-07 11:23:13 +01:00
|
|
|
|
2017-11-07 11:27:17 +01:00
|
|
|
thrower.instance.lookAt(
|
|
|
|
new THREE.Vector3(
|
|
|
|
cursor.position.x,
|
|
|
|
cursor.position.y,
|
|
|
|
cursor.position.z
|
|
|
|
)
|
|
|
|
);
|
2017-11-07 11:23:13 +01:00
|
|
|
|
|
|
|
//thrower.rotation.x = 0.5 + cursor.position.y * 0.12;
|
|
|
|
//thrower.rotation.y = Math.PI + (cursor.position.x * -0.1);
|
|
|
|
//thrower.updateInstance();
|
2017-11-07 01:05:06 +01:00
|
|
|
|
2017-11-07 10:41:52 +01:00
|
|
|
/**
|
|
|
|
* First we find our crosshair
|
|
|
|
*/
|
2017-11-07 20:53:09 +01:00
|
|
|
//var crosshair = GameLib.EntityManager.Instance.findComponentById('oxpg88pgzv');
|
2017-11-07 10:41:52 +01:00
|
|
|
var sphere = GameLib.EntityManager.Instance.findComponentById('dpol2u3xbm');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Target, is the x / y postion of the crosshair on the z=0 plane in the crosshair scene
|
|
|
|
*/
|
|
|
|
var target = new THREE.Vector3(
|
2017-11-07 11:23:13 +01:00
|
|
|
(-1 * (window.innerWidth / 2 - data.event.x)) ,
|
|
|
|
(window.innerHeight / 2 - data.event.y) ,
|
2017-11-07 20:53:09 +01:00
|
|
|
0
|
2017-11-07 10:41:52 +01:00
|
|
|
);
|
|
|
|
|
2017-11-07 20:53:09 +01:00
|
|
|
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;
|
|
|
|
|
2017-11-07 10:41:52 +01:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2017-11-07 11:23:13 +01:00
|
|
|
target.normalize();
|
|
|
|
|
2017-11-07 10:41:52 +01:00
|
|
|
target.z *= -1;
|
|
|
|
|
|
|
|
|
|
|
|
//target.sub(thrower.position.instance).normalize();
|
|
|
|
|
|
|
|
var raycaster = new THREE.Raycaster();
|
|
|
|
|
|
|
|
raycaster.ray = new THREE.Ray(
|
2017-11-07 11:23:13 +01:00
|
|
|
cursor.position.instance,
|
|
|
|
target.instance
|
2017-11-07 10:41:52 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
var intersects = raycaster.intersectObjects(
|
|
|
|
GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Mesh).map(
|
|
|
|
function(mesh){
|
|
|
|
//mesh.instance.visible = true;
|
|
|
|
mesh.instance.material.color.setHex(0xffffff);
|
|
|
|
return mesh.instance;
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
if (intersects.length > 0) {
|
|
|
|
console.log('intersected');
|
|
|
|
intersects.map(
|
|
|
|
function(intersect){
|
|
|
|
intersect.object.material.color.setHex(0xff0000);
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* But we also, want the direction from the thrower to the crosshair
|
|
|
|
*/
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* We need the x/y/z position of an imaginary object, at target position, in the game scene
|
|
|
|
*/
|
2017-11-07 11:23:13 +01:00
|
|
|
//var mInverse = new THREE.Matrix4().getInverse( crosshair.instance.matrixWorld );
|
2017-11-07 20:53:09 +01:00
|
|
|
|
2017-11-07 10:41:52 +01:00
|
|
|
|
|
|
|
|
2017-11-06 20:38:13 +01:00
|
|
|
//@ sourceURL=mouseMove.js
|