The last two chapters have been about creating landscapes: the fractal terrain in Chapter 26 was empty, but the Terragen-generated landscape in Chapter 27 was decorated with 3D models and ground cover (2D images that always face the user). This mix of models and images is enough in most situations but still lacking in one area: the scenery doesn't change. For example, the trees don't sway in the wind, and the sagebrush doesn't tumble.
As the title of this chapter suggests, this chapter focuses on making trees grow. Each tree starts from a tiny sampling, then young green shoots turn brown, grow, branch, and sprout leaves. However, the underlying aim is to describe a rule-based approach to animation, which can be applied to many kinds of 3D shapes. This approach has the following characteristics:
Each rule is a Java
then statement. If all the conditions of a rule evaluate to
true, then the rule's actions are carried out.
I'm not using a rule-based language such as Prolog, or a Java rules engine such as JESS. There's no need to step beyond standard Java.
The rules are evaluated at regular intervals during the program's execution. They're executed in a fixed, sequential order, defined by their textual order in the
applyRules() method in the
When it's time for a rule to be evaluated, it's applied to every tree limb (tree branch) in the scene. ...