鍍金池/ 問答/網(wǎng)絡(luò)安全  HTML/ three.js中的Matrix4對坐標(biāo)為何不起作用?

three.js中的Matrix4對坐標(biāo)為何不起作用?

var mirrorMatrix = new THREE.Matrix4();
        mirrorMatrix.set(
            3, 0, 0, 0, 0, 3, 0, 0, 0, 0, 3, 0, 20, 4, 2, 1
        );
        sphere.applyMatrix(mirrorMatrix);
        scene.add(sphere);
        console.log(sphere);
        camera.position.x = -30;
        camera.position.y = 40;
        camera.position.z = 30;
        camera.lookAt(scene.position);
        document.getElementById("WebGL-output").appendChild(renderer.domElement);
        renderer.render(scene, camera);

發(fā)現(xiàn)scale沒有問題,但是坐標(biāo)20,4,2不起作用,仍然在原點(diǎn)位置,這是為什么呢?謝謝

回答
編輯回答
久礙你

clipboard.png

所以修改矩陣如下:
mirrorMatrix.set(
    3, 0, 0, 20, 0, 3, 0, 4, 0, 0, 3, 2, 0, 0, 0, 1
);

Update1:

clipboard.png
因為使用數(shù)組來存儲矩陣,矩陣是二維的,如果用一維數(shù)組存儲的話,肯定會涉及一個順序問題,即一行行的存儲還是一列列的存儲;
官網(wǎng)的說明是set方法使用的是行主序,元素中的矩陣是列主序,舉例如下:
矩陣

3 0 0 20
0 3 0 4
0 0 3 2
0 0 0 1

clipboard.png

如果使用行主序存儲在數(shù)組中,那么這個數(shù)組是[3, 0, 0, 20, 0, 3, 0, 4, 0, 0, 3, 2, 0, 0, 0, 1]

clipboard.png

如果使用列主序存儲在數(shù)組中,那么這個數(shù)組是[3, 0, 0, 0, 0, 3, 0, 0, 0, 0, 3, 0, 20, 4, 2, 1]

2018年8月7日 20:24