Translation on rotation

Started by ErDetEnAnd?, November 27, 2008, 04:57:52 PM

Previous topic - Next topic

ErDetEnAnd?

Put sense into this.

// I read a 3DS file that contains 2 object3ds.
Object3D[] obj = Loader.read(...)

// I have translation and rotation offsets for both object3ds.
obj[0].translate(translation_offset1);
obj[1].translate(translation_offset2);
obj[0].translateMesh();
obj[1].translateMesh();

obj[0].rotateX(rotation_offset1);
obj[1].rotateX(rotation_offset2);
obj[0].rotateMesh();
obj[1].rotateMesh();

Object3D o3d = o3ds[0];
           for (Object3D o: o3ds)
               if (o!=o3d)
                   o3d = Object3D.mergeObjects(o3d, o);

o3d is added to the world etc.

Why is mesh translation/rotation necessary when merging objects?
Without rotation the translation part works, but then I rotate and the obj moves!? Why does it move on rotation?

paulscode

Are the objects' pivot points in the correct place?  If the pivot is not in the center of an object, it might appear to be moving as it rotates.

ErDetEnAnd?

You mean obj.getCenter()!=obj.getRotationPivot()

Both object center: 0,0,0 from obj.getCenter()
respective rotation pivot: 0,0,0 from obj.getRotationPivot()

paulscode

Oh, sorry, what I actually meant is that since you are rotating the sub-objects individually before merging them, are their individual pivot points in the correct place (i.e., do you want them to rotate around the model's center, or around their own individual centers, or around somewhere else?).  Also, you must take into account where (0,0,0) is in relation to the model (i.e. is it in the center of the model, at the corner, etc), as this will determine what point the objects will rotate around.  It looks to me like all the objects are rotating around (0,0,0) from what you've posted, so I would suggest making sure that is the correct point to rotate around.  If it is, then that probably isn't what's causing your problem.

EgonOlsen

(0,0,0) is the default pivot. Without setting it correctly, or at least calling build() on the sub-object, the rotation of single objects from a 3ds will most likely create bogus results. There is no need to rotate or translate a 3ds file's objects before merging, unless this is a very special case. Rotate and transform the merged object instead.

ErDetEnAnd?

#5
Do the operations on the merged object is prefered, however, several 3ds test have shown that their subobjects were dislocated. I cant imagine that you haven't experienced this, or did I miss something?

EgonOlsen

Quote from: ErDetEnAnd? on November 27, 2008, 10:05:25 PM
Do the operations on the merged object is prefered, however, several 3ds test have shown that their subobjects were dislocated. I cant imagine that you haven't experienced this, or did I miss something?
No, never. It always worked fine for me. Maybe it's a matter of how they have been saved/converted.

ErDetEnAnd?

Almost all the complex models i've downloaded from web repositories were dislocated. I'll take a closer look and paste the result if I still find the problem.

Thank you for the hint about the pivot. It solved the problem.