屏幕坐标转世界坐标:

let pX = (screenPoint.x / this.scene.renderer.domElement.clientWidth) * 2 - 1;
let pY = - (screenPoint.y / this.scene.renderer.domElement.clientHeight) * 2 + 1;
 
//通过调用Vector3的unproject()方法(只有vector3能使用)
//注:pX, pY介于 -1 到1之间
let p = new THREE.Vector3(pX, pY, -1).unproject(this.scene.camera)
return  new THREE.Vector2(p.x,p.y);
 
 
世界坐标转屏幕坐标
let projector = new THREE.Projector();  

let world_vector = new THREE.Vector3(0,0,1);  

let vector = world_vector.project(this.camera);
let halfWidth = window.innerWidth / 2,

  halfHeight = window.innerHeight / 2;  

return {  

  x: Math.round(vector.x * halfWidth + halfWidth),  

  y: Math.round(-vector.y * halfHeight + halfHeight)  

}; 

 

相关文章:

  • 2021-07-21
  • 2022-12-23
  • 2021-08-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-08
  • 2022-12-23
  • 2022-12-23
  • 2021-04-23
  • 2022-12-23
  • 2022-01-09
  • 2022-12-23
相关资源
相似解决方案