Author Topic: Automating translation of 3D model  (Read 564 times)

Offline jiarongkoh

  • byte
  • *
  • Posts: 18
    • View Profile
Automating translation of 3D model
« on: January 21, 2015, 01:20:58 pm »
Hey there, me again. I am trying to 'automate' a translation of a 3D model that I input into jPCT. But because the center of this model is not at the world's origin, I do an inverse translation of this 3D model so that I can view it at the origin in world space. However, I realise that float somehow does not go into the negative region (but googling around seems to suggest that float can be negative). This is what I intend to do:

Code: [Select]
cube=Object3D.mergeAll(Loader.loadOBJ(inputmodelFile, null, 1));
float xT=-cube.getCenter().x;
float yT=-cube.getCenter().y;
float zT=-cube.getCenter().z;

Log.w("cube center", String.valueOf(xT)+ " "+ String.valueOf(yT)+ " " + String.valueOf(zT));
cube.translate(xT,yT,zT);

However, this does not perform the translation at all because the Log meesage tells me -0.0 -0.0 -0.0 . In fact, cube.getCenter has some solid numbers, for my models the center is actually (10,50,-100). I tried other methods to get the figures into the negative region, ie multiply -1f, using -=, but none seems to work. Could anyone help explain where have I gone wrong?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11775
    • View Profile
    • http://www.jpct.net
Re: Automating translation of 3D model
« Reply #1 on: January 21, 2015, 04:27:40 pm »
Before calling build(), the center hasn't been calculated, so it's always 0,0,0 at that stage. Try to insert a call to build() before calling getCenter().

Offline jiarongkoh

  • byte
  • *
  • Posts: 18
    • View Profile
Re: Automating translation of 3D model
« Reply #2 on: January 23, 2015, 10:33:46 am »
ah ha, that works! Thanks!