Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visualizing Raycaster

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

like image 264
Michael Perlbach Avatar asked Feb 12 '13 23:02

Michael Perlbach


People also ask

What is raycasting in SketchUp?

Raycasting 1 Table of Contents 2 Introduction. Raycasting is a rendering technique to create a 3D perspective in a 2D map. ... 3 The Basic Idea. The basic idea of raycasting is as follows: the map is a 2D square grid, and each square can either be 0 (= no wall), or a ... 4 Untextured Raycaster. ... 5 Textured Raycaster. ...

What is the position of ray in raycast?

If you mean RaycastResult.Position then it is a property of raycastresult which is basically is a vector value which shows where the ray got intersected.

Does raycasting work with vertical or horizontal stripes?

Raycasting works with vertical stripes, but the screen buffer in memory is laid out with horizontal scanlines. So drawing vertical stripes is bad for memory locality for caching (it is in fact a worst case scenario), and the loss of good caching may hurt the speed more than some of the 3D computations on modern machines.

Where can I download the source code for the raycaster textured version?

Download the source code here: raycaster_textured.cpp The core of the textured version of the raycaster is almost the same, only at the end some extra calculations need to be done for the textures, and a loop in the y-direction is required to go through every pixel to determinate which texel (texture pixel) of the texture should be used for it.


2 Answers

Here is another method to show your raycsters:

scene.add(new THREE.ArrowHelper(raycaster.ray.direction, raycaster.ray.origin, 300, 0xff0000) );
like image 57
EnginO Avatar answered Oct 28 '22 11:10

EnginO


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

like image 3
gaitat Avatar answered Oct 28 '22 12:10

gaitat