【问题标题】:Setting three.js projection matrix direction设置three.js投影矩阵方向
【发布时间】:2015-11-21 19:17:54
【问题描述】:

我阅读了以下为 webgl 编写的代码,我想使用 three.js 重写它。但是我找不到任何方法,请帮助我。

pMatrix = mat4.create();
mat4.perspective(pMatrix,1.01,gl.drawingBufferWidth/gl.drawingBufferHeight, 10.0, 300000.0);
var eciMat = [1,  0,  0,  0,
           0,  0, -1,  0,
           0,  1,  0,  0,
           0,  0,  0,  1
           ];
mat4.mul(pMatrix, pMatrix, eciMat );

【问题讨论】:

    标签: javascript three.js webgl


    【解决方案1】:

    Three.js 中的矩阵类非常复杂,请查看此处的文档:http://threejs.org/docs/#Reference/Math/Matrix4

    这就是我在 Three.js 中的写法

    // Arguments are fov, aspect, near, far
    var perspectiveMatrix = new THREE.Matrix4().makePerspective(30, 1, 0.01, 20);
    
    var eciMatrix = new THREE.Matrix4();
    eciMatrix.set(1,  0,  0,  0,
                  0,  0, -1,  0,
                  0,  1,  0,  0,
                  0,  0,  0,  1);
    
    var resultMatrix = new THREE.Matrix4();
    resultMatrix.multiply(eciMatrix);
    resultMatrix.multiply(perspectiveMatrix);
    resultMatrix.multiply(perspectiveMatrix);
    
    console.log(resultMatrix);
    

    【讨论】:

    • eciMatrix 似乎使轴旋转到以地球为中心的惯性。在three.js中我找到了一个相机属性projectionMatrix,我应该如何将resultMatrix与projectionMatrix关联起来? projectMatrix 的元素副本似乎不正确。
    • 相机的 projectionMatrix 应该是 makePerspective 调用的结果。是的,eciMatrix 是 90 度旋转,这不是本意吗?你的意图是什么?我只是试图用 Three.JS 类重写你的代码。
    猜你喜欢
    • 1970-01-01
    • 2012-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-27
    • 2020-03-28
    • 1970-01-01
    • 2015-04-11
    相关资源
    最近更新 更多