Problem rendering big box [Solved]

I am trying to build some sidewalks. For this I am using many Box objects. After I construct an object I set a model bound (a BoundingBox) and I update the model bound. This boxes are quite large and they don’t render as I expected.

Take a look here.







After I build all the boxes I attach them to a node.

What is the problem?

Show us your code for building and attaching the sidewalk.

I use the skeleton from FlagRush tutorial. I changed buildEnvironment() method


private void buildEnvironment() {
        number = 1;
   Node sidewalk = new Node("Sidewalk");
   detectEmptyRectangleAndDrawBox(sidewalk);
        scene.attachChild(sidewalk);
}

private void detectEmptyRectangleAndDrawBox(Node sidewalk) {
      // TODO Auto-generated method stub
      int width = board.getMapWidth(), height = board.getMapHeight();
      int[][] tempMap = new int[width][height];
      //copy the map for detecting sidewalks
      board.copyMap(tempMap);
      
      for (int i = 0; i < width; i++) {
         for (int j = 0; j < height; j++) {
            if (tempMap[i][j] == 0) { //if it's an empty space detect the rectangle
               detectAndAddNewBox(sidewalk, tempMap, i,j, width, height);
            }
         }
      }
}

private void detectAndAddNewBox(Node sidewalk, int[][] tempMap, int x, int y, int width, int height) {
      // TODO Auto-generated method stub
      int i,j, yMax;
      
      i = x;
      for (j = y + 1; j < height && tempMap[i][j] == 0;j++)
         ;
      yMax = j;      
      
      for (i = x + 1; i < width && j == yMax; i++) {
         for (j = y; j < yMax && tempMap[i][j] == 0; j++)
            ;
               
      }
      if (j < yMax)
         i--;
      addNewBox(sidewalk, tempMap, x, y, i, yMax);
//      System.out.println("x " + x + " y " + y + " xmax " + i + " ymax " + yMax);
   }

private void addNewBox(Node sidewalk, int[][] tempMap, int x, int y, int xMax,
         int yMax) {
      // TODO Auto-generated method stub
      number++;
      
      
      drawBox(sidewalk, x, y, xMax, yMax);
      
      fillMap(tempMap, x, y, xMax, yMax);
   }

private void drawBox(Node sidewalk, int x, int y, int xMax, int yMax) {
      // TODO Auto-generated method stub
      Box box = new Box("Box" + (number - 1) , new Vector3f(x , 0, y),
            new Vector3f(xMax - 1, 0.1f, yMax - 1));
      box.setModelBound(new BoundingBox());
      box.updateModelBound();
      box.setLocalScale(scale);
      sidewalk.attachChild(box);
   }



The algorithm for detecting where a box should be put is working correct. But the problem is the rendering of boxes during runtime. I don't know for if it is important but for generating terrain I use a class which extends AbstractHeightMap which creates a flat terrain.

in your drawBox method try adding



box.updateRenderState();



see if that helps…

ncomp said:

in your drawBox method try adding

box.updateRenderState();

see if that helps...


It's not working  :(

I solved the problem. I had to set a render queue mode  :slight_smile:



private void buildEnvironment() {
        number = 1;
   Node sidewalk = new Node("Sidewalk");
   detectEmptyRectangleAndDrawBox(sidewalk);
   scene.attachChild(sidewalk);
   sidewalk.setRenderQueueMode(Renderer.QUEUE_OPAQUE);
}