使用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();
}
答案 0 :(得分:0)
通过将文件转换为LibGDX的本机文件格式来解决