zoukankan      html  css  js  c++  java
  • threejs 世界坐标与屏幕坐标相互转换

    屏幕坐标转世界坐标:

    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)  
    
    }; 
  • 相关阅读:
    自我介绍
    秋季学期总结
    第七周编程总结
    第六周作业
    第五周编程总结
    第四周编程总结
    第三周作业
    第二周作业
    抓老鼠啊~亏了还是赚了
    币值转换
  • 原文地址:https://www.cnblogs.com/brainworld/p/8309415.html
Copyright © 2011-2022 走看看