Is it possible to visualize ray?

is it possible to visualize ray?

not sure if there is build-in function, but create a line (its always visible, even on low-res view)

Line line = new Line(start, end);

1 Like

and what values for start and end?

something like code below.

you know where Ray start so its rayStart, because you start from some point, but rayEnd idk, i would give it rayStart + direction.multiple(1000). Also you can set RayEnd as “last contact point vector” if there is contant point

i would also use unshaded, but i was too lazy to change

Material lineMat = new Material(, "Common/MatDefs/Light/Lighting.j3md");
Line line = new Line(rayStart, rayEnd);
Geometry lineGeom = new Geometry("rayVisualize", line);
1 Like

com.jme3.scene.debug.Arrow has the advantage that it makes the direction obvious, unlike Line.


I know what are the origin and the direction of Ray. but how can I pass it as extent parameter to Arrow construction method?

the arrow is created starting at origin, and points out to extent.
you could set the arrow’s translation to the begin point, but that would skew your endpoint over by the begin point as well (but still in same direction).
if you care about exactly where the arrow terminates and not just it’s direction, you could remedy this skewing by subtracting that begin point from the arrow’s extent, then the translated arrow (origin now at the desired begin point) will have the endpoint where you wanted it.

  o=======>     translated    o=======>
0,0,0   5,0,0    by 5,5,5   5,5,5  10,5,5
1 Like

Pass the direction as the extent for the Mesh. Apply move() and scale() to the Spatial to set the origin and length.

For an example, see

1 Like