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

Deforming a terrain in real time


A deformable terrain is something that can have a serious effect on the gameplay, or it can simply be a cosmetic bonus. It can be used for impact craters or games that require excavation.

We'll base the deformation around the Control class pattern as this allows us to offset the code in a manageable and reusable way. The recipe will trigger the deformation based on a mouse click, and it will use a ray to detect the collision point.

Getting ready

To get up and running quickly, unless there already is an application to apply this to, TestTerrain.java from the jMonkeyEngine's test cases will provide a good start for what we need. This example will expand on the code provided in that application, but it should work perfectly well with any terrain-based application.

How to do it...

With a base application already set up, we can get straight to the creation of the Control pattern:

  1. Create a new class called DeformableControl that extends AbstractControl. It needs one...