Automating translation of 3D model

Started by jiarongkoh, January 21, 2015, 01:20:58 PM

Previous topic - Next topic

jiarongkoh

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:

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?

EgonOlsen

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().

jiarongkoh