8

I am trying to detect an intersection by using a raycast. My current problem is that I am not sure about my raycast aiming into the desired direction. So my general question is: Is there a way to make a raycast visible? And if so: How is it done? This would help me a lot.

Michael

Damjan Pavlica
  • 31,277
  • 10
  • 71
  • 76

2 Answers2

10

Here is another method to show your raycsters:

scene.add(new THREE.ArrowHelper(raycaster.ray.direction, raycaster.ray.origin, 300, 0xff0000) );
Kos
  • 4,890
  • 9
  • 38
  • 42
EnginO
  • 174
  • 3
  • 12
4

Why dont you draw a line from your origin to the direction of the ray.

To be more specific (using 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

gaitat
  • 12,449
  • 4
  • 52
  • 76
  • That's what I did in the end. I just hoped there was a convenient way of setting some visibility flag without additional programming. Thank you! – Michael Perlbach Feb 13 '13 at 09:21
  • 1
    Any tips on how you did that? I'm new to threejs so "drawing a line from your origin to the direction of the ray" isn't a piece of cake for me :) – binoculars Jul 03 '16 at 18:08
  • Please explain further on how to draw a line or something...thanks – TOPKAT Feb 27 '17 at 23:11
  • Big thankx brother :) For me the codePen demo only works when I change library to r84 but thats ok I understand the basics. – TOPKAT Feb 28 '17 at 12:30