0

What I have:

var pointA = new THREE.Vector3(camera_RC_Holder.position.x, camera_RC_Holder.position.y, camera_RC_Holder.position.z);

var direction = camera_RC.position.clone();
direction.applyMatrix4( camera_RC.matrixWorld );
direction.normalize();

var distance = 700;

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_Main.add( line );

enter image description here

What I want:

What I'm trying to do is to show that a ray has began from the camera and explores through the view volume. So, instead of instantly create a line (point_A, point_B) I want to grow the line from point_A pixel by pixel until it meets it's destination (point_B).

Question:

How to draw the lines pixel by pixel as shown in the code snippet below??

var w = 200;
var h = 150;
var x;

function setup(){

  createCanvas(w,h);
  x=0;
  y=0;
}

function draw(){
  
  
  if(x>w){
    x = 0;
  }
  background(250);
  line(0,50,x,50); //x1,y1,x2,y2
  x++;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.7.3/p5.js"></script>
Loizos Vasileiou
  • 674
  • 10
  • 37
  • 1
    See https://stackoverflow.com/questions/42229799/how-to-smoothly-animate-drawing-of-a-line/42236893#42236893 and https://stackoverflow.com/questions/31399856/drawing-a-line-with-three-js-dynamically/31411794#31411794 – WestLangley Feb 20 '19 at 19:22

1 Answers1

0

Title question and explanation does not fit to me very well, maybe I did not understand your question perfectly. I will try to answer just the title question and edit this answer as soon as some clarifications are done from your side.

( Also I would always try to avoid multi-questions as much as possible. )

About the title question:

Adding something to the scene is basically drawing it... or do you mean something else?

Bind this code snippet to your click mouse event. This will create your raycast, in order to see it you need to add it to your scene. Afterwards you can move your camera and check how it looks like:

var material = new THREE.LineBasicMaterial({
    color: 0x0000ff
});
var geometry = new THREE.Geometry();

geometry.vertices.push(new THREE.Vector3(raycaster.ray.origin.x, raycaster.ray.origin.y, raycaster.ray.origin.z));
geometry.vertices.push(new THREE.Vector3(raycaster.ray.origin.x + (raycaster.ray.direction.x * 100000), raycaster.ray.origin.y + (raycaster.ray.direction.y * 100000), raycaster.ray.origin.z + (raycaster.ray.direction.z * 100000)));
var line = new THREE.Line(geometry, material);
juagicre
  • 1,065
  • 30
  • 42
  • Hi @juagicre, thanks for your reply. I have updated my question. Hope this explains what i want now. Notice the code snippet at the end. This is basically what i wanna do. – Loizos Vasileiou Feb 20 '19 at 16:35