Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Three.js move geometry's center

Tags:

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.

like image 731
Recur Avatar asked Aug 11 '12 01:08

Recur


2 Answers

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.

like image 62
Recur Avatar answered Nov 28 '22 10:11

Recur


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

like image 20
Darius Miliauskas Avatar answered Nov 28 '22 11:11

Darius Miliauskas