Thanks for quickly answering. I put some code below. It is very long and quite unoptimized for the triangles generation. But even if the generation is badly coded, does it impact the performance (since the data are created just once) ???
And as i said, the XithTerrainDemo is hanging my PC (and another too which is a Athlon550,GeForce256,512Mo RAM)
public class TerrainRenderer2
{
Transform3D testRotateY = new Transform3D();
TransformGroup testRotateYGroup = new TransformGroup();
Material material = new Material();
boolean play = true;
boolean pause = false;
TerrainData terrainMap = null;
View view = new View();
public static void main(String[] args)
{
<load image in map>
final TerrainRenderer2 test = new TerrainRenderer2(map, panel);
...
test.start();
}
public TerrainRenderer2(TerrainData terrainMap, Component ccc)
throws Exception
{
this.terrainMap = terrainMap;
// Prepare full-screen canvas adapted for current resolution
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
VirtualUniverse universe = new VirtualUniverse();
view.setBackClipDistance(100f);
view.setProjectionPolicy(View.PERSPECTIVE_PROJECTION);
new Vector3f(0, 1, 0));
view.getTransform().lookAt(
new Vector3f(0, 3.5f, 3),
new Vector3f(0, 0, 0),
Locale locale = new Locale();
universe.addLocale(locale);
universe.addView(view);
RenderPeer renderPeer = new RenderPeerImpl();
CanvasPeer canvasPeer =
renderPeer.makeCanvas(
ccc,
screenSize.width - 200,
screenSize.height - 200,
16,
true);
//canvasPeer.getWindow().setLocation(100, 100);
Canvas3D canvas = new Canvas3D();
canvas.set3DPeer(canvasPeer);
view.addCanvas3D(canvas);
BranchGroup scene = this.createSceneGraph();
locale.addBranchGraph(scene);
class KeyboardEventListener implements AWTEventListener{...}
Toolkit.getDefaultToolkit().addAWTEventListener(
new KeyboardEventListener(),
AWTEvent.KEY_EVENT_MASK);
}
public void start()
{
<classical loop with view.renderOnce()>
}
public void stop()
{
play = false;
}
protected BranchGroup createSceneGraph() throws Exception
{
BranchGroup objRoot = new BranchGroup();
AmbientLight light =
new AmbientLight(true, new Color3f(0.25f, 0.25f, 0.25f));
DirectionalLight dlight =
new DirectionalLight(
true,
new Color3f(0.75f, 0.75f, 0.75f),
new Vector3f(-1, -1, -1));
objRoot.addChild(light);
objRoot.addChild(dlight);
// Add animation TransformGroup
testRotateYGroup.setTransform(testRotateY);
objRoot.addChild(testRotateYGroup);
// Make extra transfrom we may want to play with (scale etc.)
TransformGroup sceneRootTransform = new TransformGroup();
Transform3D t = new Transform3D();
t.setIdentity();
t.setTranslation(new Vector3f(-2, 0, -2));
sceneRootTransform.setTransform(t);
testRotateYGroup.addChild(sceneRootTransform);
material.setEmissiveColor(0.0f, 0f, 0f);
material.setSpecularColor(0.5f, 0.5f, 0.5f);
material.setAmbientColor(10.0f, 0.0f, 0.0f);
material.setDiffuseColor(0.75f, 0.0f, 0.0f);
material.setLightingEnable(true);
int width = terrainMap.getSize().width;
int height = terrainMap.getSize().height;
int cellHeight = 0;
//interpolatedHeightfield
float[][] ihf = new float[width - 1][height - 1];
for (int i = 0; i < ihf.length; i++)
{
for (int j = 0; j < ihf[0].length; j++)
{
<much much (too much ?) lines to generate the triangles >
<looks like xith examples>
}
}
int flags = GeometryArray.COORDINATES;
flags |= GeometryArray.NORMALS;
TriangleArray qa = new TriangleArray(coords.length, flags);
qa.setCoordinates(0, coords);
qa.setNormals(0, normals);
Appearance a = new Appearance();
a.setPolygonAttributes(
new PolygonAttributes(
PolygonAttributes.POLYGON_FILL,
PolygonAttributes.CULL_NONE,
0));
a.setColoringAttributes(
new ColoringAttributes(
new Color3f(1, 0, 0),
ColoringAttributes.SHADE_GOURAUD));
a.setMaterial(material);
Shape3D shape = new Shape3D();
shape.setAppearance(a);
shape.setGeometry(qa);
sceneRootTransform.addChild(shape);
}
}
return objRoot;
}
}