Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (538)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (600)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Java Game APIs & Engines / Java 2D / Re: How to store vertices positions of a hexgrid in a 2D Array? on: 2011-07-12 12:55:59
mhh here's the solution I found - I wonder if I could cleanup the code a bit and make just 1 loop instead of 2 without the j%2 statement...
The two blocks of code for j%2 change only for Vector c and f respectively the other stayed unchanged - so it it possible to improve it?
xpos = side; and ypos=0.866*side; in this manner I force the grid to be of regular hexagons.

I execute outside the for loops a purgeLines() function to delete lines that share equal start and end points coordinates - so get rid of duplicates.

As Philfrei mentioned the other approach would be to the create a hexagon object itself and then replicate over a grid, and then purge duplicates points at joining hexagons and not at the edge of grid. Never used hashmaps but is something I would really like to harness when Ill get sometime.



1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
float side = w / (numCols);
         particles = new Particle[numCols][numRows][2];
         for (int i=0; i<numCols; ++i){
            for(int j=0; j<numRows; ++j) {
               float xpos,ypos;
               if (j%2!=0  ){
                xpos = side*(i-0.5f);
                ypos = (0.866f*side) * j;
               
               
               } else{
                   xpos = side*(i);
                   ypos = (0.866f*side) *j;
               }
               
               vertices[i][j][0] = new Vector(xpos,
                     ypos, 1.0f);
            }
         }
         for  (int j =0; j<numRows-2; ++j){
            if (j%2 ==0){
               for (int i=j%2*2; i<numCols-2; i+=3){
               
                 
                   Vector a = vertices[i][j][0];              
                   Vector b = vertices[i+1][j][0];
                  Vector c = vertices[i+2][j+1][0];  
                   Vector d = vertices[i+1][j+2][0];
                   Vector e = vertices[i][j+2][0];
                   Vector f = vertices[i][j+1][0];  
                 
               draw.line(a,b);
                 draw.line(b,c);
                 draw.line(c,d);
                 draw.line(d,e);                  
                  draw.line(e,f);
                  draw.line(f,a);
                 
               
               }
            } else{
               for(int i=j%2*2; i<numCols-2; i+=3){

                   Vector a = vertices[i][j][0];              
                   Vector b = vertices[i+1][j][0];
                   Vector c = vertices[i+1][j+1][0];  
                  Vector d = vertices[i+1][j+2][0];
                   Vector e = vertices[i][j+2][0];
                   Vector f = vertices[i-1][j+1][0];  
                 
                draw.line(a,b);
                 draw.line(b,c);
                 draw.line(c,d);
                 draw.line(d,e);                  
                  draw.line(e,f);
                  draw.line(f,a);
                 
               }
            }
           
         }


2  Java Game APIs & Engines / Java 2D / Re: How to store vertices positions of a hexgrid in a 2D Array? on: 2011-07-12 00:07:52
Im not sure about what this lines does

1  
  float y = (i % 2 == 0) ? (i+offsetFraction) * gridSize : i * gridSize;


what are ? and : for? sorry Im new to programming.
3  Java Game APIs & Engines / Java 2D / Re: How to store vertices positions of a hexgrid in a 2D Array? on: 2011-07-11 18:40:39
Ok Ill show you with one pic the problem I have so maybe you can give more inputs Cheesy
Now I have a shifted grid which I used for triangles, the code looks like
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
float side = 10;
for (int i=0; i<numCols; ++i){
            for(int j=0; j<numRows; ++j) {
               float xpos,ypos;
               if (j%2!=0 && i%2!=0 ){
                xpos = side*(i+0.5f);
                ypos = (0.866f*side) * j;
               
               
               } else{
                   xpos = side*(i);
                   ypos = (0.866f*side) * (j+0.5f);
               }
               
               Vector[i][j] = new Vector( xpos, ypos);
            }
         }


Ok I can have unsed points although I was trying to avoid it but it seems I cannot skip with hexagons. So the situation is like in the picture below. Now once I created the grid how do I sort to create the hex tiling as in the picture? I need the indeces of the six verteces to sort all point in my grid...of course at the edge of the grid there will be some unsed (unsorted) points - those within green line in my pic.

Thanks for any help!
4  Java Game APIs & Engines / Java 2D / Re: How to store vertices positions of a hexgrid in a 2D Array? on: 2011-07-11 17:52:03
no worries. what I would like to do is this
-have different basic grid layouts (hex, quad, tria)
-able to extract from the created grid every single basic  shape (so its vertices) and store it in a list

I will have so different classes each one for each basic shape. For example a triangle class to be instatiated needs 3 points. Im doing this because the starting grid will be deformed according to some rules but topology will remain unchanged and so made up od "deformed" shape. Still later I want to retrieve all "pieces" of the deformed grid. Hope this is clear.

Now, for quads, is straightforward, I manaed to do it for triangles...but with hexagons Im really struggling...I read many articles but still stuck. How would you sort the points?
5  Java Game APIs & Engines / Java 2D / How to store vertices positions of a hexgrid in a 2D Array? on: 2011-07-11 15:48:36
Im facing this issue. I want to create an hexgrid and be able to create in this fashion:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
//grid extents
int numCols,numRows;
for (int i=0; i<numCols; ++i){
 for (int j=0; j<numRows; ++j){

 //x and y coordinates of my hexagon's vertices
 float xpos,ypos;


 //2D array storing verteces of my hextopology  
 vertices[i][j] = new VertexClass(xpos, ypos);

 // statements to change xpos/ypos and create hex
 }
}


All methods I found to make hexgrid, first create an hex object and then replicate it over a grid thus creating duplicate verteces position ad joining edges. I want to avoid duplicating verteces position. How can I declare statements to make such a grid?

Thanks
6  Java Game APIs & Engines / Java 2D / Planar tessellation on: 2011-07-03 19:08:10
Hi All,

I need to make some planar tessellation for a small project. I need to make rectangular, rhombic (diagonal), triangular and hexagonal grids. The problem I have is that I want to find a method which doesnt duplicate points/edges. In addition, if I have a point list storing vertices of my grid I have to be able to sort that list and extract collections os sub points comprising basic shape of this tessellation - ie. 4 points identifying a square, or 3 points for triangles and 6 points for hex.

Can anyone suggest a method to build this geometry easily? Eventually I'd like to implement in different shape classes beloging to the same super shape class.
7  Discussions / Business and Project Management Discussions / Java tutorials London on: 2011-06-04 17:16:19
I am an architecture student in London and I'd like to have some private tutorials/lessons about Java programming in Eclipse - would be great to have lessons from another student with a  computer science background. I have basic knowledge of Java programming both for 2d/3d graphics (in Processing) but would like to complete a more advanced project and need help especially for developing GUI.

Please send me a pvt message for further details
Pages: [1]
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (28 views)
2014-12-15 09:26:44

Mr.CodeIt (19 views)
2014-12-14 19:50:38

BurntPizza (39 views)
2014-12-09 22:41:13

BurntPizza (74 views)
2014-12-08 04:46:31

JscottyBieshaar (36 views)
2014-12-05 12:39:02

SHC (49 views)
2014-12-03 16:27:13

CopyableCougar4 (44 views)
2014-11-29 21:32:03

toopeicgaming1999 (112 views)
2014-11-26 15:22:04

toopeicgaming1999 (98 views)
2014-11-26 15:20:36

toopeicgaming1999 (29 views)
2014-11-26 15:20:08
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!