0
使用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();
}
解決它似乎我喜歡深度測試被禁用。 – Veljko 2014-10-04 07:27:29
奇怪的是,depthtest似乎完全隱藏了它。 LibGDX令我困惑。 – Braindrool 2014-10-04 21:18:04
你爲什麼試圖使用3D攝像機的正射相機?通常使用透視相機。 – Veljko 2014-10-04 21:29:21