Flickering with boxes

i draw some boxes with:



for (int i = 0; i < sources.size(); i++) {
         int revisions = sources.elementAt(i).getNumberOfRevisions();
         float x = BOX_X + (sources.elementAt(i).getNumberOfDeletedLines() * factorDeletedLines);
         float z = BOX_Z + (sources.elementAt(i).getNumberOfAddedLines() * factorAddedLines);
         float yposition = 0;
         for (int j = 0; j < revisions; j++) {
            float y = calculateBoxStep(i,j);
            yposition = yposition + y;
            Box source1 = new Box((Integer.toString(i).concat("-").concat(Integer.toString(j))), new Vector3f(x,yposition,z), BOX_X, y, BOX_Z);
            source1.setModelBound(new BoundingBox());
            source1.updateModelBound();
            source1.setRenderState(ms);
            
            boxesContainer.add(j, source1);




private float calculateBoxStep(int i, int j) {
      if (j < (sources.elementAt(i).getNumberOfRevisions()-1)) {
         Date date1 = sources.elementAt(i).getDate(j);
         Date date2 = sources.elementAt(i).getDate(j+1);
         float hours1 = date1.getTime();
         float hours2 = date2.getTime();
         float result = ((hours2 - hours1) / 1000 / 60 / 60 / 24 / 31) * BOX_STEP_TIME;
         System.out.println(result);
         return result;
      } else {
         return BOX_STEP;
      }
   }



but unfortunately the boxes are flickering. i think it is because the overlap each other... but why that? i cant find the fault in my algorithm. even if i'm quite sure that it has to be in the yposition argument :(

Often this is the cause of flickering:

http://en.wikipedia.org/wiki/Z-fighting

yes that is exactly the problem. that's why i assume the failure is in the line:


Box source1 = new Box((Integer.toString(i).concat("-").concat(Integer.toString(j))), new Vector3f(x,yposition,z), BOX_X, y, BOX_Z);



when i set the yposition of the box. but the more i try the less i can find any failure there :D

when i construct the boxes in that way:

public Box(java.lang.String name,
           Vector3f center,
           float xExtent,
           float yExtent,
           float zExtent)



the center isn't really the middle of the box???

because you modified the center :slight_smile:



use this to create and move your box:

Box b = new Box("blah", new Vector3f(), BOX_X, y, BOX_Z);

b.getLocalTranslation().set(x,yposition,z);

yes that could be. but in the meantime i could solve the problem with the constructor



box(center, extent, extent, extent)



thx for all the hints.