我有一个使用正交相机的Screen类,并希望在其上放置一个3D模型。
@Override
public void show() {
....
mCamera = new OrthographicCamera();
mCamera.setToOrtho(false, width * sclWidth, height * sclWidth);
....
//3d instance initialization
modelBatch = new ModelBatch();
ModelBuilder modelBuilder = new ModelBuilder();
model = modelBuilder.createBox(0.5f,0.5f,0.5f, new Material(ColorAttribute.createDiffuse(Color.GREEN)), VertexAttributes.Usage.Position| VertexAttributes.Usage.Normal);
modelInstance = new ModelInstance(model, 128,128,128);
modelInstance.transform.set(mCamera.invProjectionView);
}
@Override
public void render(float delta) {
Gdx.gl.glClearColor(63 / 255f, 128 / 255f, 70 / 255f, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
//mCamera.rotateAround(Vector3.Zero, new Vector3(0,1,0),1f);
mCamera.update();
mBatch.setProjectionMatrix(mCamera.combined);
mBatch.begin();
mBatch.draw(img, 128*10, 0);
mBatch.end();
modelBatch.begin(mCamera);
modelBatch.render(modelInstance);
modelBatch.end();
}
当前是2D视图,可以根据屏幕的宽度和高度放置任何2D精灵到屏幕上的x和y位置。
但是,在进行3D模型时,情况完全不同。
3D模型会根据相机屏幕拉伸并在屏幕中心渲染。我找不到3D模型设置X或Y / SetZ函数的方法。
应该如何定位3D模型以及使用哪些函数?任何建议或指向教程的方向都将不胜感激。
更新: 相机位置:(768.0,192.0,0.0) 相机投影:[0.0012019231 | 0.0 | 0.0 | -0.0] [0.0 | 0.0021378205 | 0.0 | -0.0] [0.0 | 0.0 | -0.02 | -1.0] [0.0 | 0.0 | 0.0 | 1.0]