Here is part of my code :
....
raycaster = new THREE.Raycaster();
mouse = new THREE.Vector2();
var cubeGeo, cubeMaterial;
objects = []; // contain plane (floor)
....
function rollOver() {
// roll-over helpers
var rollOverGeo = new THREE.BoxBufferGeometry( 1, 1, 1 );
rollOverMaterial = new THREE.MeshBasicMaterial( { color: 0xff0000, opacity: 0.5, transparent: true } );
rollOverMesh = new THREE.Mesh( rollOverGeo, rollOverMaterial );
scene.add( rollOverMesh );
}
function onDocumentMouseMove( event ) {
mouse.set( ( event.clientX / window.innerWidth ) * 2 - 1, - ( event.clientY / window.innerHeight ) * 2 + 1 );
raycaster.setFromCamera( mouse, camera );
var intersects = raycaster.intersectObjects( objects );
if ( intersects.length > 0 ) {
var intersect = intersects[ 0 ];
rollOverMesh.position.copy( intersect.point ).add( intersect.face.normal );
rollOverMesh.position.divideScalar( 1 ).floor().multiplyScalar( 1 ).addScalar( 0.5 );
}
}
window.addEventListener('mousemove', onDocumentMouseMove);
the object moves correctly with the onmousemove event, but everything is reversed. when the mouse goes to the left the object goes to the right and vice versa, and when the mouse goes down the object goes up.
Need help