Game Development Reference
In-Depth Information
x][(int)coords.y y][(int)coords.z + z] !=
null){terrainBlock[x][y][z].setNeighbor(i, true);
} else
{terrainBlock[x][y][z].setNeighbor(i, false);
}
}
}
}
}
6. The next step is to create geometries for the CubeCell instances. Do this by
again parsing through the terrainBlock field, and where the corresponding
CubeCell is not null, create a new Geometry class by calling the
CubeCell'sgetMesh' method. Then, move it to the right position using x , y ,
and z that we're iterating over, and apply a material and attach it to the batch node
as follows:
Geometry g = new Geometry("Cube",
terrainBlock[x][y][z].getMesh() );
g.setLocalTranslation(x, y, z);
g.setMaterial(materials[0]);
node.attachChild(g);
7. Finally, in the generateGeometry method, call
node.updateModelBound() and node.batch() to optimize it before at-
taching it to worldNode .
8. The basic of the generation process is now in place, and you can create a new
class called CubeWorldAppState that extends AbstractAppState . In
this case, add a CubeWorld field called cubeWorld .
9. Override the initialize method and declare a new cubeWorld instance.
10. Then, load a new material based on the Lighting material's definition and supply
it to cubeWorld . After this, call cubeWorld and generate and attach
worldNode through its getter method.
11. Also, add a light to see anything since we're using the Lighting material.
12. Now, create an application where we attach this Appstate instance and we
should see our block of CubeCell in the world. It's static, however, and it's very
common to want to change the world.
Search WWH ::




Custom Search