Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to rotate a 3D object on axis three.js?
    primarykey
    data
    text
    <p>I have a great problem about the rotation in three.js I want to rotate my 3D cube in one of my game.</p> <pre><code>//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 </code></pre> <p>and (x, y, z) may be (1, 0, 0)</p> <p>then the cube can rotate, but the problem is the cube rotate on its own axis,so after it has rotated, it can't rotate as expected.</p> <p>I find the page <a href="https://stackoverflow.com/questions/10747510/how-to-rotate-a-three-js-vector3-around-an-axis">How to rotate a Three.js Vector3 around an axis?</a>, but it just let a Vector3 point rotate around the world axis?</p> <p>and I have tried to use <strong>matrixRotationWorld</strong> as</p> <pre><code>@mesh.matrixRotationWorld.x += x * Math.PI / 180 @mesh.matrixRotationWorld.y += y * Math.PI / 180 @mesh.matrixRotationWorld.z += z * Math.PI / 180 </code></pre> <p>but it doesn't work, I don't whether I used it in a wrong way or there are other ways..</p> <p><strong>so, how to let the 3D cube rotate around the world's axis???</strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload