gpt4 book ai didi

java - 3D对象在libGDX中相互透视

转载 作者:行者123 更新时间:2023-11-30 07:12:19 26 4
gpt4 key购买 nike

我正在研究一个 3D 模拟,模拟在其中有物体穿越太空。呈现的 3D 对象似乎是“透明的”: image

球体大小相同。大的在前面。模型颜色未设置为透明。我假设渲染顺序可能会导致它(如在 2D 中),并使对象具有可比性并在渲染之前对它们进行排序。那并没有解决问题。

代码如下:

 public void render(float delta) {
Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
//We clear the screen
camera.update();
this._game_.modelBatch.begin(camera);
ModelInstance inst;
Orb closestOrb = null;
float minDistance = Float.MAX_VALUE;
for ( Orb orb : this._game_.orbsList)
{
if (orb.getZ()< _game_.player.getPosition().z)
{
inst = new ModelInstance(this._game_.orbModel);
inst.transform.setToTranslation(orb.getX(),orb.getY(),orb.getZ());
this._game_.modelBatch.render(inst, this._game_.environment);
if (minDistance > Physics.getDistacne(_game_.player.getPosition(),orb.getPosition()))
{
minDistance = Physics.getDistacne(_game_.player.getPosition(), orb.getPosition());
closestOrb = orb;
}
}
}
this._game_.modelBatch.end();

这是模型在游戏中的代码:

        modelBatch = new ModelBatch();//the screen uses this
modelBuilder = new ModelBuilder();
Material orbMaterial = new Material(ColorAttribute.createDiffuse(0.5f, 0.5f, 1f,1f));
//createDiffuse(Color.MAGENTA));
long orbAttributes = Usage.Position | Usage.Normal;
orbModel = modelBuilder.createSphere(Orb.STANDARD_ORB_SIZE,Orb.STANDARD_ORB_SIZE, Orb.STANDARD_ORB_SIZE,30,30, orbMaterial, orbAttributes);
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, -1f, -0.8f, -0.2f));

orbsList = new ArrayList<Orb>();
for (int i = 0; i < SimGame.NUM_OF_ORBS; i++)
{
Orb orb = Orb.generateOrb(-SimGame.WORLD_SIZE,SimGame.WORLD_SIZE, Orb.STANDARD_ORB_SIZE);
orbsList.add(orb);

}
Collections.sort(orbsList);

最佳答案

问题是 zNear 因子设置为 0。这导致深度缓冲功能异常。你可以在这里阅读更多关于他的信息:http://www.opengl.org/archives/resources/faq/technical/depthbuffer.htm我感谢所有为我指出正确方向的人。

关于java - 3D对象在libGDX中相互透视,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20476220/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com