我有从3ds Max导出的3d模型并转换为g3db格式。 渲染的模型在两个不同的手机上看起来不同。 当我在 Micromax Unite 2 上运行应用程序时,渲染的视图非常精确 但对于 Nexus 5或模拟器,它会被扭曲..
Nexus 5和Micromax Unite 2的快照:http://i.stack.imgur.com/Fyy7j.jpg
我已遵循并实施了以下代码:http://xoppa.github.io/blog/interacting-with-3d-objects/
mycode的
AndroidLauncher.java
int
Viewer3d.java
public class AndroidLauncher extends AndroidApplication {
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
config.useGLSurfaceView20API18 = true;
config.numSamples = 4;
initialize(new Viewer3D);
} }
我试过了:
1. @Override
public void create () {
stage = new Stage();
font = new BitmapFont();
label = new Label(" ", new Label.LabelStyle(font, Color.WHITE));
stage.addActor(label);
stringBuilder = new StringBuilder();
modelBatch = new ModelBatch();
environment = new Environment();
environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1f));
environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, 100,1000,300));
cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
cam.position.set((float) (maxX/2f+radius * Math.sin(finalAngle)), finalY, (float) (maxZ/2f+radius * Math.cos(finalAngle)));
cam.lookAt(centerX, 1500, centerY);
cam.up.set(Vector3.Y);
cam.near = 1;
cam.far = 7000;
cam.update();
camController = new CameraInputController(cam);
Gdx.input.setInputProcessor(new InputMultiplexer(this, camController));
Arrays.fill(usedIndexes, false);
assets = new AssetManager();
assets.load("models" + "/final.g3db", Model.class);//
loading = true;
}
@Override
public void render () {
if (loading && assets.update())
doneLoading();
camController.update();
Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
modelBatch.begin(cam);
visibleCount = 0;
for (final GameObject instance : instances) {
if (isVisible(cam, instance)) {
modelBatch.render(instance, environment);
visibleCount++;
}
}
if (Sky != null)
modelBatch.render(Sky);
modelBatch.end();
stage.draw();
}
/* updaing my camera position such that it moves in a circle in XZ-plane */
private void updateCamera() {
float x = (float) (centerX + radius * Math.sin(finalAngle));
float z = (float) (centerY + radius * Math.cos(finalAngle));
// Constrained camera posX > 0 posZ > 0
cam.position.set(x < 0 ? 0 : x , 3000, z < 0 ? 0 : z);
cam.lookAt(centerX, 1500, centerY);
cam.up.set(Vector3.Y);
cam.update();
camController = new CameraInputController(cam);
Gdx.input.setInputProcessor(new InputMultiplexer(this, camController));
}
2. config.numSamples = 8;
但没有任何效果! :(
请帮助。