I want to draw a line with two points. To draw it I have to do two clicks, and I want that the direction of the arrow is the second click
Could you share a codepen / example of what you already tried? Is there a specific issue that’s stopping you?
1 Like
if (counterMove == 0) {
pointsMove.push(intersect.point.x, 1, intersect.point.z);
counterMove++;
} else {
let referencia = intersect.point;
pointsMove.push(referencia.x, 1, referencia.z);
const geometr = new THREE.LineGeometry();
geometr.setPositions(pointsMove);
matLine = new THREE.LineMaterial({
linewidth: 0.003, // in pixels
//resolution: // to be set by renderer, eventually
});
move = new THREE.Line2(geometr, matLine);
move.position.y = 1;
move.name = "movimiento";
move.computeLineDistances();
scene.add(move);
objects.push(move);
const dir = new THREE.Vector3(referencia.x, 0, referencia.z);
dir.normalize();
var a = pointsMove[0] - pointsMove[3];
var b = pointsMove[2] - pointsMove[5];
var leng = Math.sqrt(a * a + b * b);
//normalize the direction vector (convert to vector of length 1)
const origin = new THREE.Vector3(pointsMove[0], 0, pointsMove[2]);
const length = 100;
const hex = 0xffff00;
console.log(dir);
const arrowHelper = new THREE.ArrowHelper(dir, origin, leng, hex);
scene.add(arrowHelper);
console.log(pointsMove);
console.log(arrowHelper);
pointsMove = []; counterMove = 0;
I’m trying to do this to draw the arrow, but isn´t show in the correct direction