Update: CC - Mouse Move - Moorcow (fsilsam72g.js) 174 bytes modified

beta.r3js.org
-=yb4f310 2017-11-07 11:23:13 +01:00
parent d3f0c2de6a
commit 4e528b3a7e
1 changed files with 19 additions and 13 deletions

View File

@ -3,15 +3,15 @@ camera.lookAt.x = (-1 * (window.innerWidth / 2 - data.event.x)) * 0.025;//(windo
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 cursorCamera = GameLib.EntityManager.Instance.findComponentById('b78qx660fo');
var mousePosition = new THREE.Vector3( var mousePosition = new THREE.Vector3(
(-1 * (window.innerWidth / 2 - data.event.x)) , (-1 * (window.innerWidth / 2 - data.event.x)) ,
(window.innerHeight / 2 - data.event.y) , (window.innerHeight / 2 - data.event.y) * 1.66667,
0 0
); );
mousePosition.unproject(cameraCursor.instance); mousePosition.unproject(cursorCamera.instance);
var cursor = GameLib.EntityManager.Instance.findComponentById('oxpg88pgzv'); var cursor = GameLib.EntityManager.Instance.findComponentById('oxpg88pgzv');
cursor.position.x = mousePosition.x; cursor.position.x = mousePosition.x;
@ -21,9 +21,14 @@ cursor.position.y = mousePosition.y;
cursor.updateInstance(); cursor.updateInstance();
var thrower = GameLib.EntityManager.Instance.findComponentById('01viz3rw6l'); var thrower = GameLib.EntityManager.Instance.findComponentById('01viz3rw6l');
thrower.rotation.x = 0.5 + cursor.position.y * 0.12;
thrower.rotation.y = Math.PI + (cursor.position.x * -0.1); //thrower.instance.lookAt.x = cursor.position.x;
thrower.updateInstance(); //thrower.instance.lookAt.y = cursor.position.y;
//thrower.instance.lookAt.z = cursor.position.z;
//thrower.rotation.x = 0.5 + cursor.position.y * 0.12;
//thrower.rotation.y = Math.PI + (cursor.position.x * -0.1);
//thrower.updateInstance();
/** /**
* First we find our crosshair * First we find our crosshair
@ -35,8 +40,8 @@ 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 * Target, is the x / y postion of the crosshair on the z=0 plane in the crosshair scene
*/ */
var target = new THREE.Vector3( var target = new THREE.Vector3(
(-1 * (window.innerWidth / 2 - data.event.clientX)) , (-1 * (window.innerWidth / 2 - data.event.x)) ,
(window.innerHeight / 2 - data.event.clientY) , (window.innerHeight / 2 - data.event.y) ,
0.5 0.5
); );
@ -48,17 +53,18 @@ target.unproject(camera.instance);
/** /**
* We want to shoot in the other direction * We want to shoot in the other direction
*/ */
target.normalize();
target.z *= -1; target.z *= -1;
target.normalize();
//target.sub(thrower.position.instance).normalize(); //target.sub(thrower.position.instance).normalize();
var raycaster = new THREE.Raycaster(); var raycaster = new THREE.Raycaster();
raycaster.ray = new THREE.Ray( raycaster.ray = new THREE.Ray(
thrower.position.instance, cursor.position.instance,
target target.instance
); );
var intersects = raycaster.intersectObjects( var intersects = raycaster.intersectObjects(
@ -89,8 +95,8 @@ if (intersects.length > 0) {
/** /**
* We need the x/y/z position of an imaginary object, at target position, in the game scene * 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 ); //var mInverse = new THREE.Matrix4().getInverse( crosshair.instance.matrixWorld );
sphere.instance.position.copy(target);//.applyMatrix4( mInverse ); sphere.instance.position.copy(target);//instance.applyMatrix4( mInverse );
sphere.position.x = sphere.instance.position.x; sphere.position.x = sphere.instance.position.x;
sphere.position.y = sphere.instance.position.y; sphere.position.y = sphere.instance.position.y;
sphere.position.z = sphere.instance.position.z; sphere.position.z = sphere.instance.position.z;