1
我現在開始學習Three.js,並且首先嚐試做一些真正基本的事情,比如創建一個盒子,然後在其上應用轉換矩陣,在Z上旋轉15deg軸:轉換矩陣不能與Three.js一起工作
<html>
<head>
<title>My first Three.js app</title>
<style>
body {
margin: 0;
}
canvas {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<script src="scripts/three.js"></script>
<script>
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(75, window.innerWidth/window.innerHeight, 0.1, 100000);
var renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
var geometry = new THREE.BoxGeometry(1, 0.5, 0.1);
var material = new THREE.MeshBasicMaterial({ color: 0x00ff00 });
material.wireframe = true;
var cube = new THREE.Mesh(geometry, material);
cube.matrixAutoUpdate = false;
var matrix = new THREE.Matrix4(0.9659, 0.2588, 0.000, 0,
-0.2588, 0.9659, 0.000, 0,
0.0000, 0.0000, 1.000, 0,
0.0000, 0.0000, 0.000, 1);
cube.applyMatrix(matrix);
scene.add(cube);
camera.position.z = 5;
//camera.position.x = 5;
//camera.position.y = 5;
var n1 = cube.matrix.elements;
camera.lookAt(new THREE.Vector3(0, 0, 0));
var render = function() {
requestAnimationFrame(render);
//cube.rotation.x += 0.01;
//cube.rotation.y += 0.01;
renderer.render(scene, camera);
};
render();
</script>
</body>
</html>
問題是,箱子根本沒有改變,它仍然在相同的位置/方向。
如果我檢查了applied_matrix變量,它將返回一個單位矩陣,就好像我從未應用過矩陣。
我錯過了什麼?
我使用Visual Studio開發,我不知道這種消息只出現在瀏覽器控制檯。非常感謝,解決了問題。 – RBasniak 2014-12-08 20:31:31