无法理解JavaScript中的以下代码行

时间:2016-09-26 12:15:47

标签: javascript math three.js

我无法理解代码中这些行的执行情况。

  

this.screenVector = new THREE.Vector3(0,0,0); this.screenVector.copy(this.position);
  this.screenVector.project(照相机);   什么是项目(相机)意味着它做什么,以及screenVector意味着什么。

    function labelBox(Ncardinal, radius, domElement)
    {
    this.screenVector = new THREE.Vector3(0, 0, 0);
    this.position = convertlatlonToVec3(Ncardinal.lat,Ncardinal.lon).multiplyScalar(radius);
    this.box = document.createElement('div');
    a = document.createElement('a');
    a.innerHTML = Ncardinal.name;
    a.href ='http://www.google.de';
    this.box.className = "spritelabel";
    this.box.appendChild(a);

    this.domElement = domElement;
    this.domElement.appendChild(this.box);
    }

labelBox.prototype.update = function()
{
this.screenVector.copy(this.position);  
this.screenVector.project(camera);

var posx = Math.round((this.screenVector.x + 1)* this.domElement.offsetWidth/2);
var posy = Math.round((1 - this.screenVector.y)* this.domElement.offsetHeight/2);

var boundingRect = this.box.getBoundingClientRect();

//update the box overlays position
this.box.style.left = (posx - boundingRect.width) + 'px';
this.box.style.top = posy + 'px';

this.occludeLabel(this.box, this.marker);

};

1 个答案:

答案 0 :(得分:1)

Vector3.project( camera )将3D点从世界空间映射到标准化设备坐标(NDC)空间。请参阅http://www.songho.ca/opengl/gl_projectionmatrix.html

该方法是将3D点从世界坐标转换为屏幕坐标(像素)的一个步骤。请参阅https://stackoverflow.com/a/27412386/1461008

three.js r.81