From 2e03ecb25dfbe8fe01cb32326b5b6525f6b5c2c9 Mon Sep 17 00:00:00 2001 From: -=yb4f310 Date: Thu, 9 Nov 2017 10:13:49 +0100 Subject: [PATCH] Initial Commit: CC - Mouse Move - Moorcow (0krv8dcow2.js) --- 0krv8dcow2.js | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 0krv8dcow2.js diff --git a/0krv8dcow2.js b/0krv8dcow2.js new file mode 100644 index 0000000..39d74cd --- /dev/null +++ b/0krv8dcow2.js @@ -0,0 +1,115 @@ +if (!this.entityLoaded) { + return; +} + +var camera = GameLib.EntityManager.Instance.findComponentById('zc2pq229fq'); +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); +camera.updateInstance(); + +var cursorCamera = GameLib.EntityManager.Instance.findComponentById('6tr9gzu4oh'); + +var mousePosition = new THREE.Vector3( + (-1 * (window.innerWidth / 2 - data.event.x)) , + (window.innerHeight / 2 - data.event.y) * 1.66667, + 0 +); + +mousePosition.unproject(cursorCamera.instance); + +var cursor = GameLib.EntityManager.Instance.findComponentById('jl8hpa2pel'); +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); +cursor.updateInstance(); + +var thrower = GameLib.EntityManager.Instance.findComponentById('y548ddx1ff'); + +thrower.instance.lookAt( + new THREE.Vector3( + cursor.position.x, + cursor.position.y, + 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 + */ +//var crosshair = GameLib.EntityManager.Instance.findComponentById('oxpg88pgzv'); +var sphere = GameLib.EntityManager.Instance.findComponentById('uhfavijs0s'); + +/** + * 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){ + //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 ); + + + +//@ sourceURL=mouseMove.js \ No newline at end of file