Chapter 8 : Scene graph
Jzy3d has a minimal scene graph, mainly intended to:
- provide global scaling of drawable objects
- deal with polygon ordering for translucent objects (see chapter Transparency)
You will most probably never have to deal with such details, unless you wish to apply custom transforms or polygon ordering methods.
Transforms
Transformations for Drawables
Every drawable object in jzy3d is globally transformed by calling setTransform(Transform)
,that is commonly used by the View
to apply a scale and rotate a complete Scene
.
Another transformation can be applied specifically to a drawable via setTransformBefore(Transform)
. Each call to the draw()
method of a Drawable
begins by executing the held transforms.
Executing transformations:
- always start by reloading the identity matrix (thus ensuring any object can be freely transformed however you transform the other objects of the scene graph).
- then execute the sequence of
Transformer
, either aScale
, aTranslate
, or aRotate
.
Animating a drawable transformation
The code below shows how to define a rotation axis to a specific shape, and how to start a rotation applying only to the object and not to the complete scene.
// Define rotation around Z axis
Rotate r = new Rotate(25, new Coord3d(0, 0, 1)); Transform t = new Transform();
t.add(r);
shape.setTransformBefore(t);
// Let the wheel rotate
Rotator rotator = new Rotator(10, r);
rotator.start();