Good afternoon. I am making a label for shooting an object in 3D space and I am faced with the problem that when the camera is looking in the opposite direction relative to the object, the projection vector does not give the resolution that I expect. I want to get the results as it was done in the spatial-bora-boring example.
my code looks like this:
const positionGoal = this.navigationGoal.getWorldPosition(new Vector3());
positionGoal.project(camera);
positionGoal.x = ((positionGoal.x + 1) * canvas.width) / 2;
positionGoal.y = (-(positionGoal.y - 1) * canvas.height) / 2;
const halfSizeCanvas = new Vector2(canvas.width, canvas.height).multiplyScalar(0.5);
const centrVec = new Vector2(positionGoal.x, positionGoal.y).sub(halfSizeCanvas);
if (centrVec.length() > NAV_PARAM.MAX_DISTANCE_MARK) {
const direct = centrVec.clone().normalize();
centrVec.copy(direct.clone().multiplyScalar(NAV_PARAM.MAX_DISTANCE_MARK));
angle = (direct.angle() / Math.PI) * 180 - 90;
positionGoal.x = centrVec.x + halfSizeCanvas.x;
positionGoal.y = centrVec.y + halfSizeCanvas.y;
}
What does it look like for me: