Grouping Shapes and Transforming Group

Grouping Shapes

We want to be able to "clump" elements of the scene in certain
ways

There are several different types of groups, depending on what properties
you want the clumped elements to have

Each group can have any number of children

With one exception, Java 3D reserves the right to render the children
in any order

Exemple : ExSwitch

Slide 3 : 3 / 28 : Types of Groups

Types of Groups

Java 3D provides several types of groups:

Group

BranchGroup

OrderedGroup

DecalGroup

SharedGroup

Switch

TransformGroup

All groups manage a list of children nodes

Shapes, lights, sounds, behaviors

Slide 4 : 4 / 28 : Group Class Hierarchy

Group Class Hierarchy

All groups share attributes inherited from the Group class

Class Hierarchy

java.lang.Object

javax.media.j3d.SceneGraphObject

javax.media.j3d.Node

javax.media.j3d.Group

javax.media.j3d.BranchGroup

javax.media.j3d.OrderedGroup

javax.media.j3d.DecalGroup

javax.media.j3d.SharedGroup

javax.media.j3d.Switch

javax.media.j3d.TransformGroup

Slide 5 : 5 / 28 : Groups

Groups

The Group class is the most general-purpose of the group nodes

Has exactly one parent

Can have any number of children

You can add, insert, remove, and get children in a group

Children are implicitly numbered starting with 0

Child rendering order is up to Java 3D!

Java 3D can sort shapes for better rendering efficiency

The Group node object is a general-purpose grouping node.
Group nodes have exactly one parent and an arbitrary number of children that
are rendered in an unspecified order (or in parallel). Null children are allowed;
no operation is performed on a null child node. Operations on Group node objects
include adding, removing, and enumerating the children of the Group node. The
subclasses of Group node add additional semantics.

Slide 6 : 6 / 28 : Group Class Methods

Group Class Methods

Method

Default

Group( )

-

void addChild( Node child )

Appends the specified child to this node's list
of children.

None

void setChild( Node child, int index )

Replaces the node's specified child with the child
provided.

None

void insertChild( Node child, int index )

Inserts the node's specified child at the specified
index location.

None

getChild(int index)

Returns the node's index selected child.

None

void removeChild( int index )

Removes the node's child at the specified index
location.

None

Slide 7 : 7 / 28 : BranchGroups

BranchGroups

A BranchGroup is a major sub-tree of the
scene graph

Can be attached to a Locale

Can be compiled as a unit

Can be included as a child of a group node in another subgraph

Can be reparented or removed at runtime

Adding a BranchGroup to a Locale makes the group live

Once live, changes are constrained to those enabled by capabilities

BranchGroup extends the Group class

DecalGroup adds no additional methods beyond those of the OrderedGroup
class

The BranchGroup serves as a pointer to the root of a scene
graph branch; BranchGroup objects are the only objects that can be inserted
into a Locale's set of objects. A subgraph, rooted by a BranchGroup node can
be thought of as a compile unit.

The following things may be done with BranchGroup:

A BranchGroup may be compiled by calling its compile
method. This causes the entire subgraph to be compiled. If any BranchGroup
nodes are contained within the subgraph, they are compiled as well (along
with their descendants).

A BranchGroup may be inserted into a virtual universe
by attaching it to a Locale. The entire subgraph is then said to be live.

A BranchGroup that is contained within another subgraph
may be reparented or detached at run time if the appropriate capabilities
are set.

Note that that if a BranchGroup is included in another
subgraph, as a child of some other group node, it may not be attached to a Locale.

The DecalGroup node is a subclass of the OrderedGroup
node. The DecalGroup node is an ordered group node used for defining decal geometry
on top of other geometry. The DecalGroup node specifies that its children should
be rendered in index order and that they generate coplanar objects. Examples
include painted decals or text on surfaces and a checkerboard layered on top
of a table.

The first child, at index 0, defines the surface on top
of which all other children are rendered. The geometry of this child must encompass
all other children; otherwise, incorrect rendering may result. The polygons
contained within each of the children must be facing the same way. If the polygons
defined by the first child are front facing, then all other surfaces should
be front facing. In this case, the polygons are rendered in order. The renderer
can use knowledge of the coplanar nature of the surfaces to avoid Z-buffer collisions.
(If, for example, the underlying implementation supports stenciling or polygon
offset, then these techniques may be employed.) If the main surface is back
facing, then all other surfaces should be back facing and need not be rendered
(even if back-face culling is disabled).

Note that using the DecalGroup node does not guarantee
that Z-buffer collisions are avoided. An implementation of Java 3D may fall
back to treating DecalGroup node as an ordinary OrderedGroup node.

Slide 11 : 11 / 28 : Switches

Switches

A Switch selects zero, one, or multiple children to render

Which child to render can be an integer child number, or bits in a mask

Similar to a Java "switch" statement

This node is only a switch, it does not imply any rendering order

Switch extends the Group class

The Switch group node allows a Java 3D application to
choose dynamically among a number of subgraphs. The Switch node contains an
ordered list of children and a switch value. The switch value determines which
child or children Java 3D will render. Note that the index order of children
is used only for selecting the appropriate child or children-it does not specify
rendering order.

Slide 12 : 12 / 28 : Selecting Children

Selecting Children

Select which child to render by its child index

Special values:

Render no children: CHILD_NONE

Render all children: CHILD_ALL

Or select a set of children with a bit mask

A value of CHILD_MASK enables mask use

Set a member of a Java BitSet for each
child to render

These values, when used in place of a nonnegative integer
index value, indicate which children of the Switch node are selected for rendering.
A value of CHILD_NONE indicates that no children are rendered. A value of CHILD_ALL
indicates that all children are rendered, effectively making this Switch node
operate as an ordinary Group node. A value of CHILD_MASK indicates that the
childMask BitSet is used to select the children that are rendered.

public class BitSet
extends Object
implements Cloneable, Serializable
This class implements a vector of bits that grows as needed. Each component
of the bit set has a boolean value. The bits of a BitSet are indexed by nonnegative
integers. Individual indexed bits can be examined, set, or cleared. One BitSet
may be used to modify the contents of another BitSet through logical AND, logical
inclusive OR, and logical exclusive OR operations.
By default, all bits in the set initially have the value false.

Transforming Shapes

By default, all shapes are built within a world coordinate system

Right-handed (X right, Y up, Z toward viewer)

TransformGroup

A TransformGroup enables you to build a new coordinate system relative
to a parent

Translate

Rotate

Scale

Shapes built in the new coordinate system are relative to it

If you translate the coordinate system, the shapes move too

Transformations accumulate as the scene graph is traversed

This creates an overall Composite Modeling Transform (CMT)

Transformations lower (closest to the geometry) in the scene graph appear
to happen before those farther up in the scene graph

TransformGroup extends the Group class

The TransformGroup node specifies a single spatial transformation-via
a Transform3D object -that can position, orient, and scale all of its children.
The specified transformation must be affine. Further, if the TransformGroup
node is used as an ancestor of a ViewPlatform node in the scene graph, then
the transformation must be congruent-only rotations, translations, and uniform
scales are allowed in a direct path from a Locale to a ViewPlatform node. A
BadTransformException is thrown if an attempt is made to specify an illegal
transform.
------------------------------------------------------------------------
Note: Even though arbitrary affine transformations are allowed, better performance
will result if all matrices within a branch graph are congruent-containing only
rotations, translation, and uniform scale.
------------------------------------------------------------------------
The effects of transformations in the scene graph are cumulative. The concatenation
of the transformations of each TransformGroup in a direct path from the Locale
to a Leaf node defines a composite model transformation (CMT) that takes points
in that Leaf node's local coordinates and transforms them into Virtual World
(Vworld) coordinates. This composite transformation is used to transform points,
normals, and distances into Vworld coordinates. Points are transformed by the
CMT. Normals are transformed by the inverse-transpose of the CMT. Distances
are transformed by the scale of the CMT. In the case of a transformation containing
a nonuniform scale or shear, the maximum scale value in any direction is used.
This ensures, for example, that a transformed bounding sphere, which is specified
as a point and a radius, continues to enclose all objects that are also transformed
using a nonuniform scale.

Slide 19 : 19 / 28 : TransformGroup Class Methods

TransformGroup Class Methods

Method

Default/possible values

public TransformGroup( )

Identity

public TransformGroup(Transform3D t1)

public void setTransform( Transform3D xform )

Identity

public void getTransform(Transform3D t1)

public final void setCapability(int bit) (from SceneGraphObject)

ALLOW_TRANSFORM_READ / ALLOW_TRANSFORM_WRITE

public final boolean getCapability(int bit)
(from SceneGraphObject)

Slide 20 : 20 / 28 : Transform3D

Transform3D

A Transform3D describes the transform used
by a TransformGroup

Represented as a 4x4 double precision matrix

Can represent translation, rotation, scaling, and shear

Must be affine (ie, no perspective-like homogeneous division)

Transforms must be congruent if used in a TransformGroup
that is an ancestor of a ViewPlatform (ie,
no non-uniform scaling)

Just stay with simple combination and you won't have any
trouble

Transform3D extends the Object
class

shear [n.]

(§ Homonym: sheer)
1. A machine that cuts sheet metal by passing a blade through it.
2. (Physics) A deformation of an object in which parallel planes remain parallel
but are shifted in a direction parallel to themselves; "the shear changed
the quadrilateral into a parallelogram."

Slide 21 : 21 / 28 : 4x4 Matrix Transforms

4x4 Matrix Transforms

x'
y'
z'
w'

=

A B C D
E F G H
I J K L
M N O P

*

x
y
z
w

Translation is encoded in D, H, L

Scaling and rotation are encoded in A, B, C, E,
F, G, I, J, K

Usually , [M N O P] = [0 0 0 1]

Slide 22 : 22 / 28 : Internal Matrix Types

Internal Matrix Types

Java 3D keeps track internally of what type of matrix this is

This enables Java 3D to perform operations more efficiently

AFFINE

CONGRUENT

IDENTITY

NEGATIVE_DETERMINANT

ORTHOGONAL

RIGID

SCALE

TRANSLATION

ZERO

getType()
Returns the type of this matrix as an or'ed bitmask of of all of the type
classifications to which it belongs.

A generalized transform object represented internally
as a 4x4 double-precision floating point matrix. The mathematical representation
is row major, as in traditional matrix mathematics. A Transform3D is used to
perform translations, rotations, and scaling and shear effects.
A transform has an associated type, and all type classification is left to the
Transform3D object. A transform will typically have multiple types, unless it
is a general, unclassifiable matrix, in which case it won't be assigned a type.
The Transform3D type is internally computed when the transform object is constructed
and updated any time it is modified. A matrix will typically have multiple types.
For example, the type associated with an identity matrix is the result of ORing
all of the types, except for ZERO and NEGATIVE_DETERMINANT, together. There
are public methods available to get the ORed type of the transformation, the
sign of the determinant, and the least general matrix type. The matrix type
flags are defined as follows:* ZERO - zero matrix. All of the elements in the
matrix have the value 0.
* IDENTITY - identity matrix. A matrix with ones on its main diagonal and zeros
every where else.
* SCALE - the matrix is a uniform scale matrix - there are no rotational or
translation components.
* ORTHOGONAL - the four row vectors that make up an orthogonal matrix form a
basis, meaning that they are mutually orthogonal. The scale is unity and there
are no translation components.
* RIGID - the upper 3 X 3 of the matrix is orthogonal, and there is a translation
component-the scale is unity.
* CONGRUENT - this is an angle- and length-preserving matrix, meaning that it
can translate, rotate, and reflect about an axis, and scale by an amount that
is uniform in all directions. These operations preserve the distance between
any two points, and the angle between any two intersecting lines.
* AFFINE - an affine matrix can translate, rotate, reflect, scale anisotropically,
and shear. Lines remain straight, and parallel lines remain parallel, but the
angle between intersecting lines can change.A matrix is also classified by the
sign of its determinant:NEGATIVE_DETERMINANT - this matrix has a negative determinant.
An orthogonal matrix with a positive determinant is a rotation matrix. An orthogonal
matrix with a negative determinant is a reflection and rotation matrix.The Java
3D model for 4 X 4 transformations is:

Leaves rest of transform unaffected Method

lookAt

public void lookAt(Point3d eye, Point3d center,
Vector3d up)

Helping function that specifies the position and orientation of a view matrix.
The inverse of this transform can be used to control the ViewPlatform object
within the scene graph.
Parameters:
eye - the location of the eye
center - a point in the virtual world where the eye is looking
up - an up vector specifying the frustum's up direction

AxisAngle4f(float x, float y, float z,
float angle)

Constructs and initializes a AxisAngle4f from the specified xyzw coordinates.

AxisAngle4f(Vector3f axis, float angle)

Constructs and initializes an AxisAngle4f from the specified axis
and angle.

Slide 27 : 27 / 28 : Transforming Vectors and Points

Transforming Vectors and Points

During rendering, Java 3D processes geometry coordinates and vectors through
each Transform3D

You can use Transform3D helper methods to do this processing on your own
points and vectors