【发布时间】:2011-09-14 11:25:06
【问题描述】:
我正在尝试使用以下代码(基于Click to zoom in WebGL)在我的数据中找到一个点(屏幕到世界坐标):
var world1 = [0,0,0,0] ;
var world2 = [0,0,0,0] ;
var dir = [0,0,0] ;
var w = event.srcElement.clientWidth ;
var h = event.srcElement.clientHeight ;
// calculate x,y clip space coordinates
var x = (event.offsetX-w/2)/(w/2) ;
var y = -(event.offsetY-h/2)/(h/2) ;
mat4.inverse(pvMatrix, pvMatrixInverse) ;
// convert clip space coordinates into world space
mat4.multiplyVec4(pvMatrixInverse, [x,y,0,1], world1) ;
为简单起见,我设置了一系列 z 坐标始终为 0 的顶点: 我正在绘制的坐标:
0.0 0.0 0.0 1.0 1.0 0.0 1.0 0.0 0.0 0.0 1.0 0.0 0.5 0.5 0.0
然后我将 world1 中的值与我的顶点进行比较。 world1 中的值与我知道我单击的位置不匹配。有人可以帮忙吗?
【问题讨论】:
标签: javascript screen coordinates webgl