Book Image

JMonkeyEngine 3.0 Cookbook

By : Rickard Eden
Book Image

JMonkeyEngine 3.0 Cookbook

By: Rickard Eden

Overview of this book

Table of Contents (17 chapters)
jMonkeyEngine 3.0 Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Automating trees' distribution


Placing trees and bushes in an editor is fine for many types of games. There are many cases where you need objects to be in a very specific spot. When it comes to large-scale outdoor games, you might want to have a way of placing common objects in an automatic way, at least as a base. An artist or designer might then move items around to suit the needs of the game.

In this recipe, we'll create one such way that places trees using noise. Once the base is in, we'll take a look at how the pattern can be varied with different settings.

How to do it...

To produce automatic trees' distribution, perform the following steps:

  1. We get right to the center of the things. Create a new class called TreeControl that extends AbstractControl.

  2. Add a TerrainQuad field called terrain, a FractalSum field called fractalSum, a Spatial field called treeModel, and a BatchNode field called treeNode.

  3. Override the setSpatial method. Here, we declare treeNode.

  4. Then, assuming that the supplied...