繁体   English   中英

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

[英]Unable to understand the following line of code in JavaScript

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

this.screenVector =新的THREE.Vector3(0,0,0); this.screenVector.copy(this.position);
this.screenVector.project(camera); project(camera)的含义与它的作用以及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);

};

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

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

three.js r.81

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM