Author Topic: Translation on rotation  (Read 5075 times)

Offline ErDetEnAnd?

  • int
  • **
  • Posts: 87
    • View Profile
Translation on rotation
« on: November 27, 2008, 04:57:52 pm »
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?

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: Translation on rotation
« Reply #1 on: November 27, 2008, 06:15:17 pm »
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.

Offline ErDetEnAnd?

  • int
  • **
  • Posts: 87
    • View Profile
Re: Translation on rotation
« Reply #2 on: November 27, 2008, 06:23:26 pm »
You mean obj.getCenter()!=obj.getRotationPivot()

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

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: Translation on rotation
« Reply #3 on: November 27, 2008, 06:33:07 pm »
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Translation on rotation
« Reply #4 on: November 27, 2008, 06:40:23 pm »
(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.

Offline ErDetEnAnd?

  • int
  • **
  • Posts: 87
    • View Profile
Re: Translation on rotation
« Reply #5 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?
« Last Edit: November 27, 2008, 10:09:57 pm by ErDetEnAnd? »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Translation on rotation
« Reply #6 on: November 27, 2008, 10:12:52 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.

Offline ErDetEnAnd?

  • int
  • **
  • Posts: 87
    • View Profile
Re: Translation on rotation
« Reply #7 on: November 28, 2008, 07:24:51 pm »
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.