Three.js - rotation that does not take into account local orientation

I use a large array of objects built around a central point in the scene, and you need to manipulate them around its local axis. They all come across origin using an empty object and lookAt (), then I used this method to correctly align the other axes . Getting the initial rotation this way worked fine, unfortunately, when I try to rotate these objects on the fly using object.rotation.x = <amount>, it does not respect the local axis of the object.

Confusing the part, it does not even use the global axis, the axis used by it almost seems completely arbitrary. I created a JSFiddle to demonstrate this here . As you can see from line 129, it looker.rotation.zworks correctly, it rotates along the Z axis correctly, but if it changes to X or Y, it does not rotate along the local or global axes. If someone can demystify what is happening to cause this, that would be great.

+3
source share
1 answer

What happens is that you want to add some rotation to the current orientation, and setting a variable looker.rotation.zmeans another thing.

, looker, - (: , ):

this.matrix.multiply( makeXRotationMatrix(this.rotation.x) )
this.matrix.multiply( makeYRotationMatrix(this.rotation.y) )
this.matrix.multiply( makeZRotationMatrix(this.rotation.z) )
DrawGeometry(this.geom, this.matrix)

. , , .

, rotateX (angle), rotateY (angle), rotateZ (angle) rotateOnAxis (axis, angle). axis THREE.Vector3.

looker.rotation.z , (, , , T*R*G is R otating the G eometry, T ).

:

looker.rotation.z += 0.05;

looker.rotateZ (0.05);

looker.rotateX (0.05);

. , :)

+6

All Articles