Hi, I have set up my projects in such a way that I can run my game on both PC and on android for easy testing and debugging. I did this by separating out the game code from the Activity code. Say I created a class called Game. I then created a desktop project and linked it to the android project. It then uses the Game class (and all related..) from the android project.
For things that differ that differ between android and desktop and jpct-ae and jpct, like file loading, I created an interface called GLoader, with an implementation in each project (DLoader and MLoader), and pass the instance in, and this instance is then used to load files in the generic game code. (I did the same for control input, mouse<>touchscreen, gsens<>keyboard arrows). This is working great.
The problem I have is that my player model does not rotate around it's .3ds center in the android jpct-ae version, but it works in the desktop jpct version. All the code is identical, except the InputStream creation. Here in my MLoader code. The function that loads the model, private Object3D loadModel(InputStream is, float scale) is identical in both desktop and and AE versions. (Adding o3d.setRotationPivot(SimpleVector.ORIGIN); is what made the desktop version work, but adding it does not work in the AE version.)
package com.example.mrunner;
import java.io.IOException;
import java.io.InputStream;
import android.content.res.AssetManager;
import com.threed.jpct.Loader;
import com.threed.jpct.Matrix;
import com.threed.jpct.Object3D;
import com.threed.jpct.SimpleVector;
import com.threed.jpct.Texture;
import com.threed.jpct.TextureManager;
public class MLoader implements GLoader {
AssetManager assets;
public MLoader(AssetManager assets) {
this.assets = assets;
}
@Override
public Object3D loadModel(String file, float scale) {
InputStream is = null;
try {
is = assets.open(file);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(file.endsWith(".3ds")) {
return loadModel(is, scale);
}
else if(file.endsWith(".ser")) {
return loadSerializedModel(is, scale);
}
return null;
}
@Override
public Texture loadTexture(String file) {
InputStream is = null;
try {
is = assets.open(file);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Texture tex = new Texture(is);
TextureManager.getInstance().addTexture(file, tex);
return tex;
}
private Object3D loadModel(InputStream is, float scale) {
Object3D[] model = Loader.load3DS(is, scale);
Object3D o3d = new Object3D(1);
Object3D temp = null;
for (int i = 0; i < model.length; i++) {
temp = model[i];
temp.setCenter(SimpleVector.ORIGIN);
temp.rotateX((float)( -.5*Math.PI));
temp.rotateMesh();
temp.setRotationMatrix(new Matrix());
o3d = Object3D.mergeObjects(o3d, temp);
o3d.build();
}
o3d.setRotationPivot(SimpleVector.ORIGIN);
return o3d;
}
private Object3D loadSerializedModel(InputStream is, float scale) {
Object3D o3d = Loader.loadSerializedObject(is);
o3d.scale(scale);
Object3D temp = o3d;
temp.setCenter(SimpleVector.ORIGIN);
temp.rotateX((float)( -.5*Math.PI));
temp.rotateMesh();
temp.setRotationMatrix(new Matrix());
o3d = Object3D.mergeObjects(o3d, temp);
o3d.build();
o3d.setRotationPivot(SimpleVector.ORIGIN);
return o3d;
}
}
In the ae version the model does not rotate around the correct pivot, in the desktop version it does. I also tried setting Config.useRotationPivotFrom3DS which did not fix it. I do not call build again. The funny thing is that getRotationPivot() returns 0.0,0.0,0.0 on ae but it still does not rotate right.