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

Using noise to generate a terrain


While noise is unwanted in many occasions, it is a great tool for procedural generation and has many uses. In this recipe, we'll explore jMonkeyEngine's FractalSum class and generate an image based on the output. This can be used as a heightmap for a terrain, but we are not limited by that. With some tweaking, we could get a basis to cover a forest or city.

Getting ready

This recipe relies on a way to output an image. Either use your own method to do this or refer to the The ImageGenerator class section in Appendix, Information Fragments, which provides an example of how to do it.

How to do it...

To generate a heightmap, perform the following steps:

  1. We will start by creating a class called NoiseMapGenerator.

  2. In its constructor, define a new FractalSum instance and store it in a field called fractalSum.

  3. Next, create a public method called generateNoiseMap that takes an integer parameter called size, a float parameter called frequency, and an integer parameter called...