23

I've created a cylinder and I want to move its center of rotation to one of its ends by changing it's bounding box but its not working.

http://jsfiddle.net/736a7/1/

There's an example of what I've been working on.

Basically I want to rotate the cylinder around as if it was a sword being swung by it's handle.

Recur
  • 1,418
  • 2
  • 17
  • 30

2 Answers2

32

Found out thanks to some help.

geometry.applyMatrix( new THREE.Matrix4().makeTranslation(x, y, z) );

using that I translated the cylinder's y by 100 points so it basically rotates on it's lower end.

Recur
  • 1,418
  • 2
  • 17
  • 30
  • For the life of me I can't get this to work. It translates the point of origin as well, and the rotation doesn't change at all. – Tyguy7 Sep 14 '15 at 04:20
  • 2
    @Tyguy7 - You need to set geometry.verticesNeedUpdate = true – Agniva De Sarker Oct 06 '15 at 19:48
  • 7
    You can now use this shortcut `geometry.translate(x, y, z);`, see http://stackoverflow.com/questions/12835361/three-js-move-custom-geometry-to-origin – kraftwer1 Mar 11 '16 at 08:45
4

I took an approach using pivots in my case. Basically, you create a pivot point:

var pointToRotateAround;
var objectToRotate;
...
var pivot = new THREE.Object3D();
pivot.position=pointToRotateAround.position;
pivot.add(objectToRotate);
scene.add(pivot);
...
function render (){
pivot.rotation.z +=0.05;
}
...

It gives the possible ways to make one body rotate around another or any point. Here is more about that approach: https://github.com/mrdoob/three.js/issues/1830

Darius Miliauskas
  • 3,391
  • 4
  • 35
  • 53