Changing Raycaster position dynamically

梦想与她 提交于 2019-12-19 11:39:11

问题


I have a canvas, inside that I have several cubes. I use Raycaster to select them and change their colors. But the canvas is inside of a draggable object and when I move around I cannot change the colors, the color changing works in the original position. I think I also have to change the dimensions of the Raycaster. How can I do that?

Here is the example.


回答1:


try to change a code as follows:

function onDocumentMouseDown( event ) {

    event.preventDefault();

    var x = event.offsetX == undefined ? event.layerX : event.offsetX;
    var y = event.offsetY == undefined ? event.layerY : event.offsetY;

    var vector = new THREE.Vector3();
    vector.set( ( x / renderer.domElement.width ) * 2 - 1, - ( y / renderer.domElement.height ) * 2 + 1, 0.5 );
    vector.unproject( camera );

    raycaster.ray.set( camera.position, vector.sub( camera.position ).normalize() );
...


来源:https://stackoverflow.com/questions/27862229/changing-raycaster-position-dynamically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!