示例#1
0
  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);
      }
    }
  }