Hexagon

I’m going to add a hexagon to the com.jme.scene.shape package if that’s ok.



   1____ 2
  /    /
 6/___7/___3
    /    /
   /___ /
    5    4



I'm going to set up the vertexes numbered like this. Now, I want to make sure that I'm setting up the indicies correctly.

Should I set this up to be double or single sided? My understanding is that I need to go in a clockwise direction where the first triangle would be 1,2,7 and the scond 2,3,7 and so on. Just wanted to make sure this is right. I've looked at your Box and this seems to be what you are doing.

Why are you using a contructor that takes a size? Why not just make all TriMesh derived shapes be some basic size and allow people to scale them? I figure you have a good reason and I'm just missing the point.

Thanks!

Take a look at Octahedron for a similar shape, that might help.



There’s no real good reason that shapes are given a size… convienence I suppose.

Ok, here it is until I can get it home and then into CVS. I guess I need to gain access to be able to put stuff in CVS? Is that right?



public class Hexagon extends TriMesh {
   private static final int NUM_POINTS = 7;
   private static final int NUM_TRIS = 6;
   private float sideLength;
   public Hexagon(String name, float sideLength) {
      super(name);
      this.sideLength = sideLength;

      // allocate vertices
      vertex = new Vector3f[NUM_POINTS];
      normal = new Vector3f[NUM_POINTS];
      color = new ColorRGBA[NUM_POINTS];
      texture[0] = new Vector2f[NUM_POINTS];
      indices = new int[3 * NUM_TRIS];

      setVertexData();
      setIndexData();
      setTextureData();
      setNormalData();
      setColorData();

   }
   
   private void setVertexData() {
      vertex[0] = new Vector3f( -(sideLength / 2), sideLength, 0.0f);
      vertex[1] = new Vector3f( sideLength / 2, sideLength, 0.0f);
      vertex[2] = new Vector3f( sideLength, 0.0f, 0.0f);
      vertex[3] = new Vector3f( sideLength / 2, -sideLength, 0.0f);
      vertex[4] = new Vector3f( -(sideLength / 2), -sideLength, 0.0f);
      vertex[5] = new Vector3f( -sideLength, 0.0f, 0.0f);
      vertex[6] = new Vector3f( 0.0f, 0.0f, 0.0f);
      
      setVertices(vertex);
   }

   private void setIndexData() {
      // tri 1
      indices[0] = 0;
      indices[1] = 1;
      indices[2] = 6;
      // tri 2
      indices[3] = 1;
      indices[4] = 2;
      indices[5] = 6;
      // tri 3
      indices[6] = 2;
      indices[7] = 3;
      indices[8] = 6;
      // tri 4
      indices[9] = 3;
      indices[10] = 4;
      indices[11] = 6;
      // tri 5
      indices[12] = 4;
      indices[13] = 5;
      indices[14] = 6;
      // tri 6
      indices[15] = 5;
      indices[16] = 0;
      indices[17] = 6;

      setIndices(indices);
   }
   
   private void setTextureData() {
      
      texture[0][0] = new Vector2f();
      texture[0][0].x = 0.25f;
      texture[0][0].y = 0.0f;
      
      texture[0][1] = new Vector2f();
      texture[0][1].x = 0.75f;
      texture[0][1].y = 0.0f;
      
      texture[0][2] = new Vector2f();
      texture[0][2].x = 1.0f;
      texture[0][2].y = 0.5f;
      
      texture[0][3] = new Vector2f();
      texture[0][3].x = 0.75f;
      texture[0][3].y = 1.0f;
      
      texture[0][4] = new Vector2f();
      texture[0][4].x = 0.25f;
      texture[0][4].y = 1.0f;
      
      texture[0][5] = new Vector2f();
      texture[0][5].x = 0.0f;
      texture[0][5].y = 0.5f;
      
      texture[0][6] = new Vector2f();
      texture[0][6].x = 0.5f;
      texture[0][6].y = 0.5f;
      
      setTextures(texture[0]);
   }
   
   private void setColorData() {
      for (int x = 0; x < NUM_POINTS; x++)
         color[x] = new ColorRGBA();
      setColors(color);
   }
   
   private void setNormalData() {
      for (int i = 0; i < NUM_POINTS; i++)
         normal[i] = new Vector3f(0,0,1);

      setNormals(normal);
   }
   
}

It’s now checked in with a slight fix on height… The code above shows height as 2*sideLength making for a slightly incorrect hex. The code in cvs is correct.