Update: CC - Mouse Move - Moorcow (fsilsam72g.js) 2039 bytes modified
parent
fa991b2c89
commit
d3f0c2de6a
|
@ -1,15 +1,23 @@
|
||||||
//console.log(data);
|
|
||||||
|
|
||||||
var camera = GameLib.EntityManager.Instance.findComponentById('knwkksjc7n');
|
var camera = GameLib.EntityManager.Instance.findComponentById('knwkksjc7n');
|
||||||
|
|
||||||
camera.lookAt.x = (-1 * (window.innerWidth / 2 - data.event.x)) * 0.025;//(window.clientWidth/ 2) + data.event.x;
|
camera.lookAt.x = (-1 * (window.innerWidth / 2 - data.event.x)) * 0.025;//(window.clientWidth/ 2) + data.event.x;
|
||||||
camera.lookAt.y = (((window.innerHeight / 2 - data.event.y)) * 0.05) - 8;
|
camera.lookAt.y = (((window.innerHeight / 2 - data.event.y)) * 0.05) - 8;
|
||||||
|
|
||||||
camera.updateInstance();
|
camera.updateInstance();
|
||||||
|
|
||||||
|
var cameraCursor = GameLib.EntityManager.Instance.findComponentById('b78qx660fo');
|
||||||
|
|
||||||
|
var mousePosition = new THREE.Vector3(
|
||||||
|
(-1 * (window.innerWidth / 2 - data.event.x)) ,
|
||||||
|
(window.innerHeight / 2 - data.event.y) ,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
|
||||||
|
mousePosition.unproject(cameraCursor.instance);
|
||||||
|
|
||||||
var cursor = GameLib.EntityManager.Instance.findComponentById('oxpg88pgzv');
|
var cursor = GameLib.EntityManager.Instance.findComponentById('oxpg88pgzv');
|
||||||
cursor.position.x = (-1 * (window.innerWidth / 2 - data.event.x)) * 0.025;
|
cursor.position.x = mousePosition.x;
|
||||||
cursor.position.y = (((window.innerHeight / 2 - data.event.y)) * 0.05);
|
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);
|
||||||
cursor.updateInstance();
|
cursor.updateInstance();
|
||||||
|
|
||||||
var thrower = GameLib.EntityManager.Instance.findComponentById('01viz3rw6l');
|
var thrower = GameLib.EntityManager.Instance.findComponentById('01viz3rw6l');
|
||||||
|
@ -17,4 +25,75 @@ thrower.rotation.x = 0.5 + cursor.position.y * 0.12;
|
||||||
thrower.rotation.y = Math.PI + (cursor.position.x * -0.1);
|
thrower.rotation.y = Math.PI + (cursor.position.x * -0.1);
|
||||||
thrower.updateInstance();
|
thrower.updateInstance();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* First we find our crosshair
|
||||||
|
*/
|
||||||
|
var crosshair = GameLib.EntityManager.Instance.findComponentById('oxpg88pgzv');
|
||||||
|
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(
|
||||||
|
(-1 * (window.innerWidth / 2 - data.event.clientX)) ,
|
||||||
|
(window.innerHeight / 2 - data.event.clientY) ,
|
||||||
|
0.5
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.z *= -1;
|
||||||
|
|
||||||
|
target.normalize();
|
||||||
|
|
||||||
|
//target.sub(thrower.position.instance).normalize();
|
||||||
|
|
||||||
|
var raycaster = new THREE.Raycaster();
|
||||||
|
|
||||||
|
raycaster.ray = new THREE.Ray(
|
||||||
|
thrower.position.instance,
|
||||||
|
target
|
||||||
|
);
|
||||||
|
|
||||||
|
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
|
||||||
|
*/
|
||||||
|
var mInverse = new THREE.Matrix4().getInverse( crosshair.instance.matrixWorld );
|
||||||
|
sphere.instance.position.copy(target);//.applyMatrix4( mInverse );
|
||||||
|
sphere.position.x = sphere.instance.position.x;
|
||||||
|
sphere.position.y = sphere.instance.position.y;
|
||||||
|
sphere.position.z = sphere.instance.position.z;
|
||||||
|
|
||||||
|
|
||||||
//@ sourceURL=mouseMove.js
|
//@ sourceURL=mouseMove.js
|
Loading…
Reference in New Issue