Here’s the code that I wrote/stole from other programs, to randomly generate 3d terrain. When I run it however, the screen appears to have nothing. Any ideas what’s going wrong? (Basic summary @ bottom)
import javax.vecmath.*;
import com.xith3d.scenegraph.*;
import com.xith3d.render.*;
import com.xith3d.render.jogl.*;
public class LandTest {
private Square[][] tiles;
private Point3f[][] vertices;
private final int NUM = 32;
public static int counter = 0;
public static void main(String[] args){
new LandTest();
}
public LandTest(){
initVerts();
initSquares();
VirtualUniverse universe = new VirtualUniverse();
Locale l = new Locale(NUM/2f, 0, NUM/2f);
View v = new View();
universe.addLocale(l);
universe.addView(v);
BranchGroup scene = new BranchGroup();
l.addBranchGraph(scene);
Transform3D rotate = new Transform3D();
rotate.rotXYZ(0,0,0);
TransformGroup objRotate = new TransformGroup(rotate);
scene.addChild(objRotate);
for(int x = 0; x < NUM; x++){
for(int y = 0; y < NUM; y++){
objRotate.addChild(new Shape3D(tiles[x][y].getGeometry(), new Appearance()));
}
}
scene.compile();
RenderPeer rp = new RenderPeerImpl();
CanvasPeer cp = rp.makeCanvas(null, 640, 480, 32, false);
Canvas3D canvas = new Canvas3D();
canvas.set3DPeer(cp);
v.addCanvas3D(canvas);
v.setFrontClipDistance(.5f);
v.setBackClipDistance(20f);
Transform3D t = new Transform3D();
t.lookAt(new Vector3f(0, 5f, 10f),
new Vector3f(NUM/2f, 0, NUM/2f),
new Vector3f(0, 1f, 0));
v.setTransform(t);
for(int i = 0; i > -1; i++){
v.renderOnce();
}
}
private void initVerts(){
vertices = new Point3f[NUM+1][NUM+1];
for(int x = 0; x <= NUM; x++){
for(int y = 0; y <= NUM; y++){
vertices[x][y] = new Point3f(x, (float)(20*Math.random()-10), y);
}
}
}
private void initSquares(){
tiles = new Square[NUM][NUM];
for(int x = 0; x < NUM; x++){
for(int y = 0; y < NUM; y++){
tiles[x][y] = new Square( vertices[x][y],
vertices[x+1][y],
vertices[x][y+1],
vertices[x+1][y+1]);
}
}
}
}
class Square {
private Geometry shape;
Square(Point3f v1, Point3f v2, Point3f v3, Point3f v4){
Point3f[] coords = new Point3f[] {
v1, v2, v3,
v1, v4, v3
};
Color3f[] colors = new Color3f[] {
new Color3f(0, 1f, 0),
new Color3f(0, 1f, 0),
new Color3f(0, 1f, 0),
new Color3f(0, 1f, 0),
new Color3f(0, 1f, 0),
new Color3f(0, 1f, 0)
};
TriangleArray array = new TriangleArray(coords.length, GeometryArray.COORDINATES|GeometryArray.COLOR_3);
array.setCoordinates(0, coords);
array.setColors(0, colors);
}
public Geometry getGeometry(){
return shape;
}
}
Ok, so first thing it does: creates a 2^5 +1 x 2^5 + 1 array of Point3fs with definite x and z values. The height of that point is determined randomly at runtime. Then, Square objects are created from those points, constructing a 2^5 x 2^5 array of tiles. Each Square has its own Geometry which is used to create Shape3Ds and they are stored in an unrotated TransformGroup. If anything is rendered, however, I can’t see it at runtime. (The window with its trademark Xith Brown/Black bg appears, but nothing is in it).