1

I tried to rotate an object arount the Worlds-Y-Axis, with

myObject.rotateOnWorldAxis(new THREE.Vector3(0,1,0),THREE.Math.degToRad(1));

but the result was, that the object is only rotated in object space.

To be sure that I used the correct method I looked into the documentation and found that there are three methods to rotate an object:

.RotateY(rad) // rotate in Local Space

.rotateOnAxis(axis,rad) // rotation in Object Space

.rotateOnWorldAxis(axis,rad) // rotation in World Space

It seems that I used the correct method.
Is this a bug or an understanding problem on my side?

Here is a JSFiddle which illustrates my problem (the blue cube should rotate around the world axis).
Here is a second Fiddle where thy cyan cube is a child of another object.

Karlheinz Reinhardt
  • 1,025
  • 1
  • 11
  • 22
  • You're adding them all to `scene`, which is your world. All rotation methods will do the same – davidpox Jun 03 '19 at 11:13
  • @davidpox sorry I don't understand it yet. They are rotating around the objects axis not around the worlds axis? I created a second fiddle where the cyan cube is the child of an other object. https://jsfiddle.net/4wpxyLg0/2/ – Karlheinz Reinhardt Jun 03 '19 at 11:25
  • @davidpox maybe can you give me an example where rotateOnAxis() behaves differently from rotateOnWorldAxis()? – Karlheinz Reinhardt Jun 03 '19 at 11:29
  • 1
    @KarlheinzReinhardt If your axis are aligned in Object Space and World Space, the rotation will look the same. But they are not, as you can see in this example: [JSFiddle](https://jsfiddle.net/agj80zLo/) uncomment to see the difference. – ScieCode Jun 03 '19 at 12:22
  • @KarlheinzReinhardt Possible duplicate: https://stackoverflow.com/questions/31953608/rotate-object-on-specific-axis-anywhere-in-three-js-including-outside-of-mesh – WestLangley Jun 03 '19 at 14:35
  • 1
    @ScieCode Thank you now I understand it. I thought that the position of the pivot point changes depending on the function -> e.g. in `rotateOnWorldAxis()`pivot point would be in Worlds center. **But** in reality **the pivot point is always in/at the objects origin**; only the direction of the given axis is relative on the Space. – Karlheinz Reinhardt Jun 03 '19 at 15:11

1 Answers1

2

It looks to me like your real question isn't regarding world space or object space rotations, cause those are working as expected in your examples.

You probably meant, how to change the point of rotation of an object. If that is the case, you have two options, you can either translate all your geometry vertices in respect to a pivot point of rotation. That way, your pivot will be centered at (0,0,0) and your vertices will rotate in respect to that.

mesh.geometry.translate( x, y, z );

Or you can make your object a child of a different Object3D (pivot), position your original mesh similarly to what was described above and rotate your pivot mesh.

var cube = new THREE.Mesh( geometry, material );
var pivot = new THREE.Object3D();

cube.position.set( 0, 12, 30 ); // offset from center

pivot.add( cube );
scene.add( pivot );

//...

pivot.rotation.y += Math.PI/2;

JSFiddle

ScieCode
  • 1,706
  • 14
  • 23