Time for action – plant a tree

Placing a tree on flat ground is easy: you know the y coordinate of the ground plane.

Let's try placing a tree on a hilly terrain.

  1. Make a copy of TerrainSimple.java and name the class Trees.java. Remember to also refactor the first line of the main() method to the following:
    Trees app = new Trees();
  2. Keep the code that creates HillHeightMap(1025, 1000, 50, 100, (byte) 3).
  3. Load a tree model from the assets folder included with this book.
    public void simpleInitApp() {
      Spatial treeGeo = assetManager.loadModel("Models/Tree/Tree.j3o");
      treeGeo.scale(5); // make tree bigger
      treeGeo.setQueueBucket(Bucket.Transparent); 
      // transparent leaves
      rootNode.attachChild(treeGeo);
  4. Place the tree at (-30,y,-30) on the terrain.
     Vector3f treeLoc ...

Get jMonkeyEngine 3.0 Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.