Reputation: 2085
I try to create hexagons and place them on the opengl window. I want to use them as a tiled-map. My current code looks like this:
private Polygon generateTile(){
Polygon poly = new Polygon();
for(int i = 0; i < 6; ++i) {
poly.addPoint((float)Math.sin(i/6.0*2*Math.PI),
(float)Math.cos(i/6.0*2*Math.PI));
}
return poly;
}
private void generateTiles (){
Shape s;
Polygon p = generateTile();
for (int i = 0; i <= 2; i++) {
for (int j = 0; j <=10; j++) {
s=p.transform(Transform.createScaleTransform(Constants.TILE_SIZE, Constants.TILE_SIZE));
if (i%2==0) {
s.setLocation(s.getMaxX()*j*2, s.getMaxY()*i*2);
} else {
s.setLocation(s.getMaxX()*j*2+Constants.TILE_SIZE, s.getMaxY()*i*2);
}
tiles.add(s);
}
}
Window:
The problem is that the row 2 should integrate under row 1.
Upvotes: 1
Views: 296