Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use matrix for transformation #1593

Closed
lanfeustxiii opened this issue Mar 27, 2012 · 6 comments
Closed

How to use matrix for transformation #1593

lanfeustxiii opened this issue Mar 27, 2012 · 6 comments
Labels

Comments

@lanfeustxiii
Copy link

Hello everybody,

I want display an object in my navigator which come from a stl file. I load it and i display it. It is far away on the display, it is not at the center of the frame. When I open my stl file with "blender", I remark that my object is not localised at the center of the frame. Indeed, he is at (10,22,30) for example. So, the object in my navigator is at the same position that in "blender". So, I translate it with some calculation at the center of the landmark. BUT ^^, I remark that the attribute "position" of the object had values (0,0,0) at the initial position (before I translate it at the center of the frame, so (0,0,0) = (10,22,30) in obsolute frame), consequently after the translation, the object has position (-10,-22,-30). When I try to use setRotation(a), to rotate my object, it rotates around HIS origin that is to say (10,22,30) !!! How can I rotate my object on itself ? I would like that the center of the rotation be the center of the frame. I would like a function where I can specify the center of rotation.

David

@ColasMarko
Copy link
Contributor

The simpliest way to do that is to "center" the pivot of your geometry so that every transformation you'll do to this object will be relative to its center.

Right after loading your geometry center it before creating your THREE.Mesh using this code
THREE.GeometryUtils.center( geometry );

@mrdoob
Copy link
Owner

mrdoob commented Mar 27, 2012

Or...

mesh.geometry.applyMatrix( new THREE.Matrix4().setTranslation( -10,-22,-30 ) );

@lanfeustxiii
Copy link
Author

Thanks kovleouf, it's a good idea to do THREE.GeometryUtils.center( geometry ), I tried and objects are at the center of the frame at the obsolute position (0,0,0). But I have an other constraint :/

Thanks mrdoob mesh.geometry.applyMatrix( new THREE.Matrix4().setTranslation( -10,-22,-30 ) ) was useful to apply transformation on my objet. :)

But I have a particular case, indeed my objects have specifics positions compared to others. I have a bone with anatomical points, when I load bones and anatomical points, they are automatically position on the bone at strategic position for future calculations. If I move everything with THREE.GeometryUtils.center( geometry ) I loose the position of anatomicals points.
If I use mesh.geometry.applyMatrix( new THREE.Matrix4().setTranslation( -10,-22,-30 ) ) I keep the relative position of my objects but the position (0,0,0) of my object corresponds to the initial position of it. So when I use this.object.geometry.applyMatrix(this.object.matrix.setRotationY( Math.PI/2) ); I turn around the relative position of the object (0,0,0) and not the absolute position which must be the center of the frame (0,0,0). I need to be able to specify the center of the rotation or to be in the case where the center of rotation is the center of the frame and that my objects keep the relative position to other object. I need to move all objects like a same unity on the center of the frame.

I hope that my explications are clear ^^

@mrdoob
Copy link
Owner

mrdoob commented Mar 30, 2012

Then use a dummy object.

var dummy = new THREE.Object3D();
dummy.position.set( -10,-22,-30 );
scene.add( dummy );

dummy.add( mesh );

Now you can rotate dummy and it will rotate the contents as expected.

@lanfeustxiii
Copy link
Author

Interesting, Thanks I will try it :)

@mrdoob
Copy link
Owner

mrdoob commented Mar 30, 2012

Actually, that's wrong. It should be like this:

var dummy = new THREE.Object3D();
scene.add( dummy );

mesh.position.set( -10,-22,-30 );
dummy.add( mesh );

Now you can rotate dummy ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants