1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
| public class Level extends ExampleBase {
Node _level=new Node("Level Root"); private final float farPlane = 8000.0f; private Terrain terrain; final int SIZE = 2048; PointLight pl=new PointLight(); private double counter = 0; private int frames = 0;
public void updateExample(ReadOnlyTimer t){ counter += t.getTimePerFrame(); frames++; if (counter > 1) { final double fps = frames / counter; counter = 0; frames = 0; System.out.printf("%7.1f FPS\n", fps); } pl.setLocation(_canvas.getCanvasRenderer().getCamera().getLocation()); } @Override protected void initExample() { _canvas.setTitle("Terrain Example"); _canvas.getCanvasRenderer().getCamera().setLocation(new Vector3(0, 10, 0)); _canvas.getCanvasRenderer().getCamera().lookAt(new Vector3(1, -300, 1), Vector3.UNIT_Y); _canvas.getCanvasRenderer().getCamera().setFrustumPerspective( 70.0, (float) _canvas.getCanvasRenderer().getCamera().getWidth() / _canvas.getCanvasRenderer().getCamera().getHeight(), 1.0f, farPlane); _canvas.getCanvasRenderer().getRenderer().setBackgroundColor(ColorRGBA.CYAN); _controlHandle.setMoveSpeed(300); setupDefaultStates(); AwtTextureSource awt = new AwtTextureSource(8, TextureStoreFormat.RGBA8); try { final int SIZE = 2048;
float[] heightMap=new float[SIZE*SIZE]; for(int i=0;i<heightMap.length;i++)heightMap[i]=0f;
final TerrainDataProvider terrainDataProvider = new ArrayTerrainDataProvider(heightMap, SIZE, new Vector3(1, 300, 1));
TerrainBuilder b=new TerrainBuilder(terrainDataProvider, _canvas.getCanvasRenderer().getCamera()); b.addTextureConnection(awt); terrain = b.setShowDebugPanels(true).build();
terrain.getTextureClipmap().setShowDebug(false); terrain.reloadShader(); _level.attachChild(terrain); } catch (final Exception ex1) { System.out.println("Problem setting up terrain..."); ex1.printStackTrace(); }
AwtShapeElement rectangle = new AwtShapeElement(new Rectangle(2048, 2048)); Transform t = new Transform(); rectangle.setTransform(t); awt.getProvider().addElement(rectangle); _root.attachChild(_level); } private void setupDefaultStates() { _lightState.detachAll(); final DirectionalLight dLight = new DirectionalLight(); dLight.setEnabled(true); dLight.setAmbient(new ColorRGBA(0.4f, 0.4f, 0.5f, 1)); dLight.setDiffuse(new ColorRGBA(0.6f, 0.6f, 0.5f, 1)); dLight.setSpecular(new ColorRGBA(0.3f, 0.3f, 0.2f, 1)); dLight.setDirection(new Vector3(-1, -1, -1).normalizeLocal()); pl.setAmbient(new ColorRGBA(0.4f, 0.4f, 0.5f, 1)); pl.setDiffuse(new ColorRGBA(0.6f, 0.6f, 0.5f, 1)); pl.setSpecular(new ColorRGBA(0.3f, 0.3f, 0.2f, 1)); pl.setAttenuate(false); _lightState.attach(pl); _lightState.attach(dLight);
_lightState.setEnabled(true);
final CullState cs = new CullState(); cs.setEnabled(true); cs.setCullFace(CullState.Face.Back); _root.setRenderState(cs);
final FogState fs = new FogState(); fs.setStart(farPlane / 2.0f); fs.setEnd(farPlane); fs.setColor(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f)); fs.setDensityFunction(DensityFunction.Linear); _root.setRenderState(fs); }
public static void main(String[] args) { start(Level.class);
}
} |