@Override public void initialize(Context context, ProgramManager programManager) { lineShaderProgram = programManager.getProgram(ProgramManager.PROGRAM.LINE); textureDataHandler = TextureLoader.loadTexture(context, R.drawable.game209, GLES20.GL_LINEAR); GLES20.glGenerateMipmap(GLES20.GL_TEXTURE_2D); int socketTextureDataHandler = TextureLoader.loadTexture(context, R.drawable.node_socket, GLES20.GL_LINEAR); GLES20.glGenerateMipmap(GLES20.GL_TEXTURE_2D); mCorrectNodeTextureHandle = TextureLoader.loadTexture(context, R.drawable.game209, GLES20.GL_LINEAR); GLES20.glGenerateMipmap(GLES20.GL_TEXTURE_2D); mWrongNodeTextureHandle = TextureLoader.loadTexture(context, R.drawable.game210, GLES20.GL_LINEAR); GLES20.glGenerateMipmap(GLES20.GL_TEXTURE_2D); mNodeBatch = new SpriteBatch(SpriteBatch.COLORED_VERTEX_3D, textureDataHandler); mNodeBatch.setFiltered(true); mNodeBatch.initialize(context, programManager); mSocketBatch = new SpriteBatch(SpriteBatch.VERTEX_3D, socketTextureDataHandler); mSocketBatch.setFiltered(true); mSocketBatch.useDepthTest(false); mSocketBatch.initialize(context, programManager); mConnectionsBatch = new Line3DBatch(); mConnectionsBatch.initialize(context, programManager); mDottedBatch = new DottedLine3DBatch(0.7f, 0.8f); mDottedBatch.initialize(context, programManager); mSprite = new Sprite(Vector3f.getZero(), 2.0f, 2.0f); mSprite.setFiltered(true); mSprite.setTexture(textureDataHandler); mSprite.initialize(context, programManager); for (int i = 0; i < nodes.length; i++) { nodes[i].getSprite().setFiltered(true).initialize(context, programManager); } super.initialize(context, programManager); }
private void computeNodeSocketsPositions(Vector3f camPos) { // for each node call updateSocketPosition for each connection // returning vector will be the culling position. update the positions // but DO NOT update the line itself - it have to be updated in buildConnectionDrawOrder // for double calculation reduction (updating line once for both points // instead of updating once for each point) for (int i = 0; i < nodes.length; i++) { NodeConnectionSocket[] sockets = nodes[i].getSockets(); for (int k = 0; k < sockets.length; k++) { Vector3f lineEndPoint; if (connections[sockets[k].connectionId].endNode == i) // inverse point from current node lineEndPoint = connections[sockets[k].connectionId].getLine().getRay().getStartPos(); else lineEndPoint = connections[sockets[k].connectionId].getLine().getRay().getEndPos(); Vector3f intersection = new Ray3v(camPos, lineEndPoint) .findIntersectionWithPlane( nodes[i].getPosV(), nodes[i].getSprite().getLookVector()); intersection = intersection.subtractV(nodes[i].getPosV()); if (intersection.lengthSqr() < Math.pow(nodes[i].getRadius(), 2.0f)) nodes[i].getSocket(k).setPos(Vector3f.getZero()); else nodes[i].getSocket(k).setPos(intersection.normalize().multiplySf(nodes[i].getRadius())); float fraction = nodes[i].getRadius() / intersection.length(); float amount = connections[sockets[k].connectionId].getLine().getRay().getLength() * fraction; // Log.e("Debug", "Fraction: " + fraction); if (connections[sockets[k].connectionId].originNode == i) connections[sockets[k].connectionId].getLine().occludeStartPoint(amount); else connections[sockets[k].connectionId].getLine().occludeEndPoint(amount); } } }