www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: jiarongkoh on January 21, 2015, 01:20:58 pm

Title: Automating translation of 3D model
Post by: jiarongkoh 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?
Title: Re: Automating translation of 3D model
Post by: EgonOlsen 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().
Title: Re: Automating translation of 3D model
Post by: jiarongkoh on January 23, 2015, 10:33:46 am
ah ha, that works! Thanks!