可视化Raycaster

时间:2013-02-12 23:30:40

标签: three.js

我正在尝试使用光线投射来检测交叉路口。我目前的问题是我不确定我的光线投射是否朝着理想的方向发展。所以我的一般问题是:有没有办法让光线投射可见?如果是这样:它是如何完成的?这对我有很大帮助。

迈克尔

2 个答案:

答案 0 :(得分:3)

为什么不从原点到光线方向画一条线。

更具体(使用r83):

    // Draw a line from pointA in the given direction at distance 100
    var pointA = new THREE.Vector3( 0, 0, 0 );
    var direction = new THREE.Vector3( 10, 0, 0 );
    direction.normalize();

    var distance = 100; // at what distance to determine pointB

    var pointB = new THREE.Vector3();
    pointB.addVectors ( pointA, direction.multiplyScalar( distance ) );

    var geometry = new THREE.Geometry();
    geometry.vertices.push( pointA );
    geometry.vertices.push( pointB );
    var material = new THREE.LineBasicMaterial( { color : 0xff0000 } );
    var line = new THREE.Line( geometry, material );
    scene.add( line );

Codepen at:https://codepen.io/anon/pen/evNqGy

答案 1 :(得分:2)

这是展示你的raycsters的另一种方法:

scene.add(new THREE.ArrowHelper(raycaster.ray.direction, raycaster.ray.origin, 300, 0xff0000) );