我在three.js中遇到了一个关于旋转的问题。我想在我的游戏中旋转我的3D立方体。
//init
geometry = new THREE.CubeGeometry grid, grid, grid
material = new THREE.MeshLambertMaterial {color:0xFFFFFF * Math.random(), shading:THREE.FlatShading, overdraw:true, transparent: true, opacity:0.8}
for i in [1...@shape.length]
othergeo = new THREE.Mesh new THREE.CubeGeometry(grid, grid, grid)
othergeo.position.x = grid * @shape[i][0]
othergeo.position.y = grid * @shape[i][1]
THREE.GeometryUtils.merge geometry, othergeo
@mesh = new THREE.Mesh geometry, material
//rotate
@mesh.rotation.y += y * Math.PI / 180
@mesh.rotation.x += x * Math.PI / 180
@mesh.rotation.z += z * Math.PI / 180
如果 (x, y, z) 可以是 (1, 0, 0),那么该立方体可以旋转,但问题在于它会绕自己的轴旋转,因此旋转后无法按预期旋转。
我找到了网页如何绕一个轴旋转 Three.js 中的 Vector3?,但它只能让一个 Vector3 点绕世界轴旋转?
我尝试使用 matrixRotationWorld:
@mesh.matrixRotationWorld.x += x * Math.PI / 180
@mesh.matrixRotationWorld.y += y * Math.PI / 180
@mesh.matrixRotationWorld.z += z * Math.PI / 180
但它没有起作用,我不知道是我使用方法有误还是还有其他方法…
那么,如何让这个三维立方体围绕世界坐标轴旋转?
@
符号是什么意思? - Daniel Node.js