Problem with Line (Connecting and Loop)

i use this method to draw a line through some points:


public void connectBoxes(ColorRGBA colorUsed, String author) {
      MaterialState ms = DisplaySystem.getDisplaySystem().getRenderer().createMaterialState();
      ms.setColorMaterial(MaterialState.CM_AMBIENT_AND_DIFFUSE);
      
      int length = boxes.size();
      Vector3f[] vertex = new Vector3f[length];
      ColorRGBA[] color = new ColorRGBA[length];
      Vector3f center = new Vector3f();
      
      /**
       * only use boxes which are of a specific author
       */
      
      System.out.println("Checking for: " + author);
      for (int i = 0; i < boxes.size(); i++) {
         if (authors.elementAt(i).equals(author) == true) {
            boxes2draw.add(boxes.elementAt(i));
         }
      }
      
      for (int j = 0; j < boxes2draw.size(); j++) {
         center = boxes2draw.elementAt(j).getCenter();
         vertex[j] = new Vector3f(center.x, center.y + boxes2draw.elementAt(j).yExtent, center.z);
         System.out.println(vertex[j]);
         color[j] = ColorRGBA.white;
      }
      
      Line connectingLine = new Line("Connecting Line", vertex, null, color, null);
      connectingLine.setMode(Line.LOOP);
      connectingLine.setLineWidth(LINE_WIDTH);
      
      connectingLine.setDefaultColor(ColorRGBA.white);
      
      lineNode.attachChild(connectingLine);
      lineNode.setRenderState(ms);
      lineNode.updateRenderState();
      nodes.add(lineNode);
   }



event if the point (0,0,0) is not in the vertex list ( i checked it throug the system.out.println), the line always goes trhough the origin (0,0,0). does anybody know, how i can prevent that?

i tried to set the connecting mode to connected or loop but it doesn't matter.

thx 4 u help!

looks like it is possible for the vertex array to be longer than the boxes2draw array, which would likely leave some 0's at the end of the resulting FloatBuffer created in Line.  Try using an ArrayList for vertex and color instead.

thank you very mutch!! a big problem is solved!



i just moved the declaration further down and set the length of the arrays to boxes2draw.size()

that solves it.