提交 638e86fc 编写于 作者: M Mr.doob

Merge pull request #5452 from alexan0308/webgl_geometry_terrain_raycast

shouldSphereFollowMouse and controls_handleResize enabled
......@@ -62,7 +62,6 @@
var clock = new THREE.Clock();
var shouldSphereFollowMouse = true;
var helper;
init();
......@@ -77,7 +76,7 @@
scene = new THREE.Scene();
controls = new THREE.OrbitControls(camera);
controls.center.set(0.0, 100.0, 0.0);
controls.center.set( 0.0, 100.0, 0.0 );
controls.userPanSpeed = 100;
data = generateHeight( worldWidth, worldDepth );
......@@ -138,8 +137,6 @@
renderer.setSize( window.innerWidth, window.innerHeight );
controls.handleResize();
}
function generateHeight( width, height ) {
......@@ -250,31 +247,28 @@
function onMouseMove( event ) {
if ( shouldSphereFollowMouse ) {
var mouseX = ( event.clientX / window.innerWidth ) * 2 - 1;
var mouseY = -( event.clientY / window.innerHeight ) * 2 + 1;
var mouseX = ( event.clientX / window.innerWidth ) * 2 - 1;
var mouseY = -( event.clientY / window.innerHeight ) * 2 + 1;
var vector = new THREE.Vector3( mouseX, mouseY, camera.near );
// Convert the [-1, 1] screen coordinate into a world coordinate on the near plane
vector.unproject( camera );
var vector = new THREE.Vector3( mouseX, mouseY, camera.near );
// Convert the [-1, 1] screen coordinate into a world coordinate on the near plane
vector.unproject( camera );
var raycaster = new THREE.Raycaster( camera.position, vector.sub( camera.position ).normalize() );
var raycaster = new THREE.Raycaster( camera.position, vector.sub( camera.position ).normalize() );
// See if the ray from the camera into the world hits one of our meshes
var intersects = raycaster.intersectObject( mesh );
lastIntersects = intersects;
// See if the ray from the camera into the world hits one of our meshes
var intersects = raycaster.intersectObject( mesh );
// Toggle rotation bool for meshes that we clicked
if ( intersects.length > 0 ) {
// Toggle rotation bool for meshes that we clicked
if ( intersects.length > 0 ) {
helper.position.set( 0, 0, 0 );
helper.lookAt( intersects[ 0 ].face.normal );
helper.position.set( 0, 0, 0 );
helper.lookAt( intersects[ 0 ].face.normal );
helper.position.copy( intersects[ 0 ].point );
helper.position.copy( intersects[ 0 ].point );
}
}
}
</script>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册