【发布时间】:2012-06-19 02:49:11
【问题描述】:
我对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)
那么立方体可以旋转,但问题是立方体在自己的轴上旋转,所以旋转后,它不能像预期的那样旋转。
我找到了页面How to rotate a Three.js Vector3 around an axis?,但它只是让一个Vector3点围绕世界轴旋转?
我已经尝试使用 matrixRotationWorld 作为
@mesh.matrixRotationWorld.x += x * Math.PI / 180
@mesh.matrixRotationWorld.y += y * Math.PI / 180
@mesh.matrixRotationWorld.z += z * Math.PI / 180
但它不起作用,我不知道是我用错了还是有其他方法..
那么,如何让 3D 立方体绕世界轴旋转???
【问题讨论】:
-
@表示法是什么? -
'@' 在 CoffeeScript 中的意思是 'this'。在 JavaScript 中。这是一个简写。
标签: javascript coffeescript three.js