使用LibGDX来简化我的项目制作,我遇到了一个我似乎找不到根源的问题。每当我渲染一个模型时,它在投影视图中看起来很好,但一旦我切换到正交视图,我就会遇到一些奇怪的裁剪问题。


如上所述,我使用的是LibGDX,如果你需要OpenGL的等价物,尽管问。以下是代码的一些部分,可根据需要获得更多内容:
public Camera(String type) {
if (type.contains("perspective")) {
position = new Vector3(1, 2, 1);
lookAt = new Vector3(0, 1, 0);
perspectiveCamera = new PerspectiveCamera(67,
Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
perspectiveCamera.position.set(position);
perspectiveCamera.lookAt(lookAt);
perspectiveCamera.near = 1f;
perspectiveCamera.far = 300f;
perspectiveCamera.update();
}
if (type.contains("orthographic")) {
position = new Vector3(1, 1, 1);
lookAt = new Vector3(0, 0, 0);
orthographicCamera = new OrthographicCamera(
Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
orthographicCamera.position.set(position);
orthographicCamera.lookAt(lookAt);
orthographicCamera.near = 1f;
orthographicCamera.far = 300f;
orthographicCamera.zoom = 0.005f;
orthographicCamera.update();
}
}-更改类
@Override
public void render() {
Vector3 translate = new Vector3(isTrue(input.D)
+ (isTrue(input.A) * -1), 0, isTrue(input.W)
+ (isTrue(input.S) * -1)).nor().crs(
new Vector3(0.05f, 0.05f, 0.05f));
camera.perspectiveCamera.translate(translate);//Change to orthographic accordingly
camera.perspectiveCamera.update();//Change to orthographic accordingly
// Temporary (testing)
Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(),
Gdx.graphics.getHeight());
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
batch.begin(camera.getPerspectiveCamera());//Change to orthographic accordingly
for (int n = 0; n < world.entities.size; n++) {
instance = world.entities.get(n).modelInstance;
instance.transform.setToTranslation(world.entities.get(n).position);
world.entities.get(n).modelInstance = instance;
batch.render(world.entities.get(n).modelInstance, environment);
}
batch.end();
}发布于 2014-10-06 01:49:23
通过将文件转换为LibGDX的本机文件格式来解决
https://stackoverflow.com/questions/26188208
复制相似问题