Hi,
Can anyone give me some clue as to what is happening with the vertex coordinates here?
I'm trying to create an irregular sized plane in order to create a terrain (this is currently shown in Wireframe mode).
Firstly, for a given bounding box I calculate the number of cells required in X and Y, along with the size of each 'cell'.
Then I loop through generating the vertex positions for each corner of each cell/ quad as so;
Coordinate[] quads = new Coordinate[(xNum * yNum * 4) ];
Coordinate ll, ur;
int cnt = 0;
for (int yd=0; yd < yNum; yd++) {
for (int xd=0; xd < xNum; xd++) {
ll = new Coordinate(bbox.getMinX() + (xSize*xd), bbox.getMinY() + (ySize*yd) );//lowerLeft
//ur = new Coordinate(bbox.getMinX() + (xSize*(xd+1)), bbox.getMinY() + (ySize*(yd+1)) );//upperRight
ur = new Coordinate(ll.x + xSize, ll.y+ySize);//upperRight
quads[cnt++] = new Coordinate(ll); //lowerLeft
quads[cnt++] = new Coordinate(ur);//upperRight
quads[cnt++] = new Coordinate(ll.x, ur.y); //upperLeft
quads[cnt++] = new Coordinate(ur.x, ll.y); //lowerRight
}
}
Lastly I create triangles for the coordinates and add to an Object3D;
Coordinate[] quadCS = quadGeom.getCoordinates();
SimpleVector lowerLeft=new SimpleVector();
SimpleVector upperRight=new SimpleVector();
SimpleVector upperLeft=new SimpleVector();
SimpleVector lowerRight=new SimpleVector();
plane = new Object3D(xNum * yNum * 2);
for (int c=0; c < quadCS.length-1; c+=4) {
lowerLeft.set((float)quadCS[c].x, (float)quadCS[c].y, (float)quadCS[c].z);
upperRight.set((float)quadCS[c+1].x, (float)quadCS[c+1].y, (float)quadCS[c+1].z);
upperLeft.set((float)quadCS[c+2].x, (float)quadCS[c+2].y, (float)quadCS[c+2].z);
lowerRight.set((float)quadCS[c+3].x, (float)quadCS[c+3].y, (float)quadCS[c+3].z);
plane.addTriangle(
upperLeft,0,0,
lowerLeft,0,1,
upperRight,1,0);
plane.addTriangle(
upperRight,1,0,
lowerLeft,0,1,
lowerRight,1,1);
}
I've tried this a couple different ways but don't seem to get the edge of the plane correct - Is this something happening internally with the vertex indexing, or am I not completing the 'square' correctly...?
Incidentally I would love to use the in-built getPlane(int, int) function, but this doesn't allow me to create for odd sizes, hence doing this manually.
Many thanks for any assistance...