0

I originally wrote a program that generates an area of ​​2D rectangles. SUDDENLY, I wanted to arrange an isometric projection. I thought that the easiest way to do this is using 3D rectangles. I adapted the code and in general everything turned out the way I wanted. However, there was a problem that I do not know how to solve. Each new rectangle is placed as if on top of the rest. Because of what appears the effect of the relief of the area. I would like the platform to be flat. Below on the screen you will understand everything. two muppets I tried to experiment with setTranslateZ(), but it has no effect at all.

protected List fillingArea()
{
    manyPlacedSquares.add(new CustomBox(100,50,100, 0, 0, 0));
    for(int y = 0; y < numberOfSquares; y++)
    {
        for(CustomBox i: manyPlacedSquares)
        {
            CustomBox upBox = new CustomBox(100,50,100,i.getTranslateX()+70,i.getTranslateY()-50, i.getTranslateZ()-1 );
            manyPotentialSquares.add(upBox);
            CustomBox rightBox = new CustomBox(100,50,100,i.getTranslateX()-70,i.getTranslateY()-50,i.getTranslateZ()-1);
            manyPotentialSquares.add(rightBox);
            CustomBox belowBox = new CustomBox(100,50,100,i.getTranslateX()+70,i.getTranslateY()+50,i.getTranslateZ()-1);
            manyPotentialSquares.add(belowBox);
            CustomBox leftBox = new CustomBox(100,50,100,i.getTranslateX()-70,i.getTranslateY()+50,i.getTranslateZ()-1);
            manyPotentialSquares.add(leftBox);
        }
        System.out.println(manyPotentialSquares.size());
        System.out.println(manyPlacedSquares.size());
        System.out.println(manyPotentialSquares.get(1).getTranslateX());
        manyPotentialSquares.removeAll(manyPlacedSquares);
        System.out.println(manyPotentialSquares.size());
        index = randomGenerator.nextInt(manyPotentialSquares.size());
        manyPlacedSquares.add(manyPotentialSquares.get(index));
    }
    return manyPlacedSquares;
}

The custom box has plain content and is unlikely to be needed, but just in case, I'll show its content. equals () method redefined for correct operation removeall ()

public class CustomBox extends Box {
    Double tt;
    Double tt1;
    public CustomBox(double width, double height, double depth, double gtx, double gty, double gtz) 
        {
            super(width, height, depth);
            this.setTranslateX(gtx);
            this.setTranslateY(gty);
            this.setTranslateZ(gtz);
            tt = gtx;
            tt1 = gty;
        }

@Override
public boolean equals(Object obj)
{
    if(this.tt.equals(((CustomBox) obj).getTranslateX()) && this.tt1.equals(((CustomBox) obj).getTranslateY()))
        {
            System.out.println(tt + "  " + ((CustomBox) obj).getTranslateX());
            return true;
        }
    if (obj == null || obj.getClass() != this.getClass())
        {
            return false;
        }
           return false;
}


}
lalalend
  • 41
  • 8
  • 1
    Can you show how you create the scene and the camera? – José Pereda Jan 14 '19 at 09:45
  • @JoséPereda um ... I just put them in a knot, as happens with 2D rectangles. The fact is that I do not need a 3D camera. I just want an isometric effect. I thought that the easiest way is to use 3d shapes. Pane root = new Pane(); for(Box i: storage) { i.getTransforms().addAll(rxBox,ryBox,rzBox); root.getChildren().add(i); } – lalalend Jan 14 '19 at 09:51
  • can I just remove the light source so that all this is in one color? but then the isometric effect will disappear – lalalend Jan 14 '19 at 09:53

1 Answers1

0

You have to configure JavaFX to use 3D correctly. Especially you have to switch depth buffering on. This is explained in the accepted answer of this question here: Overlaping Shapes - wrong overlapping shapes behaviour

mipa
  • 10,369
  • 2
  • 16
  • 35
  • Thanks I got it. I will try to build a rectangle in 3D correctly, and then transfer this principle to my code. – lalalend Jan 14 '19 at 10:21
  • Thanks again for the answer, I did it all. [link](https://ibb.co/k1LZXFj) now everything looks right! – lalalend Jan 14 '19 at 14:29