var fNearZ = -100.0;
var farZ = 100.0;
var fZoom = 10.0;
var iR = this.iWidth/fZoom;
var iL = (this.iWidth/fZoom)*(-1);
var iT = this.iHeight/fZoom;
var iB = (this.iHeight/fZoom)*(-1);
var pMatrix = new mat4.ortho(iL, iR, iB, iT, fNearZ, farZ);
var mvMatrix = new mat4.create();
mat4.identity(mvMatrix);
zI.debug(mat4.str(mvMatrix),{'grp':'mv_before','style':'color:#060;'});
mat4.translate(mvMatrix, [0.0, 0.0, -50.0]);
mat4.scale(mvMatrix, [3, 3, 3]);
zI.debug(vec3.unproject([
parseFloat(this.pLastMouse.x-this.iLeft),
parseFloat(this.pLastMouse.y-this.iTop),
0
],
mvMatrix,
pMatrix,
[
0,
0,
this.iWidth,
this.iHeight
]),{'grp':'dest____','style':'color:#00F;'});
this.setMatrices(pMatrix, mvMatrix);
//After this line, buffers will be set
SCREEN网址:http://i.stack.imgur.com/au2ac.pngvec3.unproject()鼠标冲突问题
今天我试着去实现我的鼠标碰撞GL-矩阵的新版本,提供vec3.unproject。我想要的是获得鼠标位置的z世界坐标。正如你在屏幕截图上看到的那样,x和y坐标是可以的,但无论光标位于何处,z坐标始终为50。
每个平面都是1.0x1.0,其间有0.1个间隔。
当我在Y轴上添加旋转或平移时,我收到来自未投影的错误(?)x和y坐标。我认为我处理mvMatrix和pMatrix的方式是错误的。谁能帮帮我吗?
编辑 不使用.translate()和.scale()函数我越来越zNear和zFar的正确的价值观,现在,仍然不知道如果坐标是正确的,当我将这些功能到模型视图矩阵。还缺少的是交点计算。
链接到我的源:
我应该提到,glMatrix中的unproject函数是非常新的,并且在多个场景中还没有经过很多严格的测试。我把事情搞砸是完全可能的。是否有可能将你的源文件发布到某个地方,以便我可以进行交叉检查? – Toji
http://jsfiddle.net/matthoz/vucAq/ < - 请不要嘲笑我;) - 纹理不适用于jsfiddle。但我可以告诉你,你的代码工作正常。 – mat