Created
February 3, 2013 07:18
-
-
Save Lewuathe/4700825 to your computer and use it in GitHub Desktop.
Three.jsでカーソルとの衝突判定する方法 ref: http://qiita.com/items/9107051360c2683b2520
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var projector = new THREE.Projector(); | |
| var mouseX = e.clientX -getElementPosition(renderer.domElement).left; | |
| var mouseY = e.clientY - getElementPosition(renderer.domElement).top; | |
| var x = (mouseX / renderer.domElement.width) * 2 - 1; | |
| var y = -(mouseY/renderer.domElement.height) * 2 + 1; | |
| var vector = new THREE.Vector3(x, y, 1); | |
| projector.unprojectVector(vector, camera); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var vector = | |
| var ray = new THREE.Raycaster( | |
| camera.position, | |
| vector.sub(camera.position).normalize()); | |
| // 視点位置から対象オブジェクトへのベクトル |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var intersects = ray.intersectObjects(BB.eventMeshList); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment