Note that there are some explanatory texts on larger screens.

plurals
  1. PO3D objects are seen through each other in libGDX
    primarykey
    data
    text
    <p>I am working on a 3D simulation of traveling through space with objects in it. The 3D objects that are rendered seem to be "transparent": <img src="https://i.stack.imgur.com/pCDzx.png" alt="image"></p> <p>The orbs are the same size. the large one is in front. The model color is NOT set to transparent. I assumed the order of rendering might cause it (as in 2D), and made the objects comparable and sorted them prior to rendering. That did not solve the problem.</p> <p>Here is the code:</p> <pre><code> 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()&lt; _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 &gt; Physics.getDistacne(_game_.player.getPosition(),orb.getPosition())) { minDistance = Physics.getDistacne(_game_.player.getPosition(), orb.getPosition()); closestOrb = orb; } } } this._game_.modelBatch.end(); </code></pre> <p>here is the model's code in <em>game</em>:</p> <pre><code> 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&lt;Orb&gt;(); for (int i = 0; i &lt; 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); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload