Hi trying to sub divide the terrain shape from the terrain demo into a 2 dim array of shape3d’s each of size 256 * 256.
wrote a piece of code (see below) but the texturing is not mapping properly and there is large gaps between each shape3d geometry.
the init method is the only major thing i changed can anyone suggest a reason why there could be gaps between the shape3d’s???
public void rebuild(View view) {
view.getTransform().get(pTemp); // get the location of the view
terrain.update(pTemp,117); // update terrain according to the views location
for(int row=0; row<geo.length; ++row){
for(int col=0; col<geo[0].length; ++col){
geo[row][col].drawStart(); // resets the terrain vertices
totalIndex = totalVerts = 0;
terrain.render(this);
geo[row][col].drawEnd(); // commits the changes to the video card
geo[row][col].setIndex(index);
geo[row][col].setValidIndexCount(totalIndex);
geo[row][col].setValidVertexCount(totalVerts);
}
}
}// end rebuild()
/** called at the beginning of rendering the triangles for one adaptive quad square
*/
public void start() {
}
/** */
public void initVert(int i, float x, float y, float z) {
//System.out.println("initVert: x:"+x+" y:"+y+" z:"+z);
//System.out.println("texture scale: "+textureScale);
if (totalVerts>=MAX_VERTICES) return;
int row = (int)((x) / 256);
int col = (int)((z) / 256);
if(row == 4)row = 3;
if(col == 4)col = 3;
//System.out.println("row: "+row);
//System.out.println("col: "+col);
//for(int row=0; row<geo.length; ++row){
//for(int col=0; col<geo[0].length; ++col){
geo[row][col].newVertex();
geo[row][col].setCoordinate(x,y,z);
/**
* Next we have to divide out the texture coordinates. 2D textures have coordinates
* from 0 to 1 in what is called "S,T" space. Each coordinate in our X,Z world
* has to be mapped to its appropriate S,T texture coordinate. If we are stretching
* the texture all the way across the terrain, then 0,0 in X,Z would be 0,0 in S,T and
* the farthest point in X,Z from the origin would be 1,1 in S,T. Thus, mathematically,
* we should divide X and Z by the width and depth (should be equal) of the terrain. To
* wrap the texture, you would divide this depth and width by some number (set by textureScale)
* to make the textured patches smaller.
*/
float texCoordx = x / (terrain.getWidth() / textureScale);
float texCoordz = z / (terrain.getWidth() / textureScale);
// Now we need to use these figures to set up a TexCoord2f
TexCoord2f texCoords = new TexCoord2f(texCoordx, texCoordz);
geo[row][col].setTextureCoordinate(0,totalVerts,texCoords);
// We want prettier colors :-)
float c = y/1500;
geo[row][col].setColor(0.48f+c, 0.48f+c, 0.39f+c);
vertexMap[i] = totalVerts++;
//}
//}// end for loop
}// initVert()
/** */
public void tri(int a, int b, int c) {
if (totalIndex+3>=MAX_INDICES) return;
index[totalIndex++] = vertexMap[a];
index[totalIndex++] = vertexMap[b];
index[totalIndex++] = vertexMap[c];
}// end tri()