public void drawAll(Camera cam) { float[] rotationMatrix = new float[16]; boolean typeSwitchDirty = false; OrderUnit[] renderOrder = buildCompleteDrawOrder(cam.getPos()); Matrix.setIdentityM(rotationMatrix, 0); Matrix.rotateM(rotationMatrix, 0, -angle, 0.0f, 1.0f, 0.0f); for (int i = 0; i < renderOrder.length; i++) { if (renderOrder[i].getType() == OrderUnit.ORDERUNITTYPE.Node) { if (!typeSwitchDirty) { mConnectionsBatch.endBatch(); mDottedBatch.endBatch(); } drawOneNode(renderOrder[i].getId(), rotationMatrix, cam); typeSwitchDirty = true; } else { if (typeSwitchDirty) { mConnectionsBatch.beginBatch(cam, modelMatrix); mDottedBatch.beginBatch(cam, modelMatrix); typeSwitchDirty = false; } Line3D currentLine = connections[renderOrder[i].getId()].getLine(); if (currentLine.isDotted()) mDottedBatch.batchElement(currentLine); else mConnectionsBatch.batchElement(currentLine); } } }
public void drawNodesBatched(Camera cam) { int cur; TextureRegion texRgn = new TextureRegion(); float[] color; float[] spriteMatrix = new float[16]; float[] rotationMatrix = new float[16]; float[] convMatrix = new float[16]; Matrix.multiplyMM( convMatrix, 0, cam.getViewM(), 0, modelMatrix, 0); // multiply view matrix by model to calc distances from cam NodeOrderUnit[] renderOrder = this.buildDrawOrder(convMatrix); Matrix.setIdentityM(rotationMatrix, 0); Matrix.rotateM(rotationMatrix, 0, -angle, 0.0f, 1.0f, 0.0f); mNodeBatch.beginBatch(cam, rotationMatrix); // batch.beginBatch(cam); for (int i = 0; i < renderOrder.length; i++) { cur = renderOrder[i].getId(); /*if (nodes[cur].isSelected()) color = new float[] {0.1f, 0.1f, 0.7f, 1.0f}; else color = new float[] {1.0f, 1.0f, 1.0f, 1.0f};*/ switch (nodes[cur].getState()) { case CORRECT: color = new float[] {0.0f, 0.8f, 0.0f, 1.0f}; break; case WRONG: color = new float[] {0.8f, 0.0f, 0.0f, 1.0f}; break; case OPEN: color = new float[] {1.0f, 1.0f, 1.0f, 1.0f}; break; default: // when IDLE color = new float[] {0.7f, 0.7f, 0.7f, 1.0f}; break; } Matrix.setIdentityM(spriteMatrix, 0); Matrix.translateM( spriteMatrix, 0, modelMatrix, 0, nodes[cur].posX, nodes[cur].posY, nodes[cur].posZ); float diam = nodes[cur].getRadius() * 2; mNodeBatch.batchElement(diam, diam, color, texRgn, spriteMatrix); } mNodeBatch.endBatch(); }
@Override public void draw(Camera cam) { Matrix.setIdentityM(modelMatrix, 0); Matrix.rotateM(modelMatrix, 0, angle, 0.0f, 1.0f, 0.0f); Camera updCam = new Camera(cam); updCam.setPos( cam.getPos() .rotate( -angle, 0.0f, 1.0f, 0.0f)); // camera position is changed WITHOUT updating matrices computeNodeSocketsPositions(updCam.getPos()); // TODO: redo enable/disable switch when performance optimizations are done // GLES20.glDisable(GLES20.GL_DEPTH_TEST); // GLES20.glEnable(GLES20.GL_DEPTH_TEST); drawConnections(updCam); // GLES20.glDisable(GLES20.GL_DEPTH_TEST); // GLES20.glEnable(GLES20.GL_DEPTH_TEST); drawNodes(updCam); // GLES20.glEnable(GLES20.GL_DEPTH_TEST); }
private void drawConnections(Camera cam) { NodeConnectionOrderUnit[] renderOrder = buildConnectionDrawOrder(cam.getPos()); mConnectionsBatch.beginBatch(cam, modelMatrix); mDottedBatch.beginBatch(cam, modelMatrix); for (int i = 0; i < renderOrder.length; i++) { Line3D currentLine = connections[renderOrder[i].getId()].getLine(); if (currentLine.isDotted()) mDottedBatch.batchElement(currentLine); else mConnectionsBatch.batchElement(currentLine); } mConnectionsBatch.endBatch(); mDottedBatch.endBatch(); }
public void drawNodes(Camera cam) { int cur; float[] color; float[] spriteMatrix = new float[16]; float[] rotationMatrix = new float[16]; float[] convMatrix = new float[16]; Matrix.multiplyMM( convMatrix, 0, cam.getViewM(), 0, modelMatrix, 0); // multiply view matrix by model to calc distances from cam NodeOrderUnit[] renderOrder = this.buildDrawOrder(convMatrix); Matrix.setIdentityM(rotationMatrix, 0); Matrix.rotateM(rotationMatrix, 0, -angle, 0.0f, 1.0f, 0.0f); for (int i = 0; i < renderOrder.length; i++) { cur = renderOrder[i].getId(); /*if (nodes[cur].isSelected()) color = new float[] {0.1f, 0.1f, 0.7f, 1.0f}; else color = new float[] {1.0f, 1.0f, 1.0f, 1.0f};*/ switch (nodes[cur].getState()) { case CORRECT: color = new float[] {0.0f, 0.8f, 0.0f, 1.0f}; nodes[cur].getSprite().setColor(color).setTexture(mCorrectNodeTextureHandle); break; case WRONG: color = new float[] {1.0f, 1.0f, 1.0f, 1.0f}; nodes[cur].getSprite().setColor(color).setTexture(mWrongNodeTextureHandle); break; case OPEN: color = new float[] {1.0f, 1.0f, 1.0f, 1.0f}; nodes[cur].getSprite().setColor(color).setTexture(mCorrectNodeTextureHandle); break; default: // when IDLE color = new float[] {0.7f, 0.7f, 0.7f, 1.0f}; nodes[cur].getSprite().setColor(color).setTexture(mCorrectNodeTextureHandle); break; } Matrix.setIdentityM(spriteMatrix, 0); Matrix.translateM( spriteMatrix, 0, modelMatrix, 0, nodes[cur].posX, nodes[cur].posY, nodes[cur].posZ); nodes[cur] .getSprite() .setModelMatrix(spriteMatrix) .setOrientationMatrix(rotationMatrix) .draw(cam); NodeConnectionSocket[] sockets = nodes[cur].getSockets(); mSocketBatch.beginBatch(cam, rotationMatrix); for (int k = 0; k < sockets.length; k++) { Matrix.setIdentityM(spriteMatrix, 0); Matrix.translateM( spriteMatrix, 0, modelMatrix, 0, nodes[cur].posX + sockets[k].posX, nodes[cur].posY + sockets[k].posY, nodes[cur].posZ + sockets[k].posZ); // sockets[k].getPosV().print("Debug", "Node " + i + " socket " + k); float diam = sockets[k].getRadius() * 2; mSocketBatch.batchElement(diam, diam, sockets[k].getSprite().getTexRgn(), spriteMatrix); } mSocketBatch.endBatch(); } }