public abstract class Node
extends java.lang.Object
A node has zero or more parents. Because the number of parents can
be greater than one, the scene graph forms a directed acyclic graph
(DAG). However, the DAG has a single root node, called a World
.
A node can be moved from one world to another, but cannot exist in more
than one world at a time.
A world maintains a selected set of nodes within it. Only nodes that
implement the marker interface Selectable
can be selected.
For convenience, the methods of that interface are implemented in this
abstract base class. Classes that extend this abstract base class may
override the method selectedChanged()
, typically to modify
the appearance of selected nodes.
Nodes are drawn in what is called the draw process. The draw
process is applied to a node in three steps by calling the methods
drawBegin(DrawContext)
,
draw(DrawContext)
, and
drawEnd(DrawContext)
, in that order. The actual drawing occurs
in the method draw(DrawContext)
. Think of the other two methods
as like opening and closing braces. They might save and restore OpenGL
state, or otherwise push and pop state required for drawing. Nodes must
not leak OpenGL state set while drawing.
To facilitate drawing and picking, all nodes have a bounding sphere. Ideally, this bounding sphere is the smallest sphere that contains the node's geometry. Nodes with bounding spheres that do not intersect a view's frustum will be culled, and not drawn or picked within that view. Bounding spheres are specified in local coordinates.
Constructor and Description |
---|
Node() |
Modifier and Type | Method and Description |
---|---|
protected BoundingSphere |
computeBoundingSphere(boolean finite)
Computes the bounding sphere for this node, including its children.
|
int |
countParents()
Returns the number of parents of this node.
|
protected void |
cull(CullContext cc)
Culls this node.
|
protected void |
cullApply(CullContext cc)
Applies the cull process to this node.
|
protected void |
cullBegin(CullContext cc)
Begins the cull process for this node.
|
protected void |
cullEnd(CullContext cc)
Ends the cull process for this node.
|
void |
dirtyBoundingSphere()
Marks dirty the bounding sphere of this node (and any parent nodes).
|
void |
dirtyDraw()
Marks dirty the drawing of this node.
|
protected void |
draw(DrawContext dc)
Draws this node.
|
protected void |
drawApply(DrawContext dc)
Applies the draw process to this node.
|
protected void |
drawBegin(DrawContext dc)
Begins the draw process for this node.
|
protected void |
drawEnd(DrawContext dc)
Ends the draw process for this node.
|
protected int |
getAttributeBits()
Gets the OpenGL attribute bits for this node.
|
BoundingSphere |
getBoundingSphere(boolean finite)
Gets the bounding sphere for this node.
|
java.util.Iterator<Group> |
getParents()
Gets an iterator for the parents of this node.
|
StateSet |
getStates()
Gets the OpenGL states for this node.
|
World |
getWorld()
Gets the world for this node.
|
boolean |
isSelected()
Determines whether this node is currently selected.
|
void |
pick(PickContext pc)
Picks this node.
|
protected void |
pickApply(PickContext pc)
Applies the pick process to this node.
|
protected void |
pickBegin(PickContext pc)
Begins the pick process for this node.
|
protected void |
pickEnd(PickContext pc)
Ends the pick process for this node.
|
protected void |
selectedChanged()
This method is called when the selected state of this node has changed.
|
void |
setSelected(boolean selected)
Sets the selected state for this node.
|
void |
setStates(StateSet states)
Sets the OpenGL states for this node.
|
public final boolean isSelected()
Selectable
can be selected.public final void setSelected(boolean selected)
Selectable
can be selected. This method does
nothing if this node is not selectable.
Classes that extend this abstract base class may override the method
selectedChanged()
, typically to alter the appearance of a
node that has been selected or deselected.
selected
- true, for selected; false, otherwise.public int countParents()
public java.util.Iterator<Group> getParents()
public World getWorld()
public void dirtyDraw()
public BoundingSphere getBoundingSphere(boolean finite)
finite
- true, to force bounding sphere to be finite.public void dirtyBoundingSphere()
getBoundingSphere(boolean)
is next called, this node's bounding sphere will be recomputed.public StateSet getStates()
public void setStates(StateSet states)
states
- the OpenGL states.public void pick(PickContext pc)
pc
- the pick context.protected void selectedChanged()
This implementation does nothing.
protected BoundingSphere computeBoundingSphere(boolean finite)
getBoundingSphere(boolean)
when this
node's bounding sphere is dirty.
If a finite bounding sphere is specified, then any infinite bounding sphere is replaced by an empty bounding sphere, so that the returned sphere is always finite.
Classes that extend this abstract base class should override this implementation, which simply returns an empty or infinite bounding sphere, depending on whether or not a finite sphere is requested.
finite
- true, to force bounding sphere to be finite.protected int getAttributeBits()
drawBegin(DrawContext)
and drawEnd(DrawContext)
.
The attribute bits returned by this method need not include any
bits from this node's StateSet
, if it has one. Those bits
will be combined with any bits returned by this method.
Classes that extend this base class may override this method to return only those bits corresponding to OpenGL state that they modify but do not restore. However, classes that do so should take care to include all relevant bits. Nodes must not leak OpenGL state!
This implementation simply returns GL_ALL_ATTRIB_BITS, which is safe, but may be inefficient.
protected void cullApply(CullContext cc)
cullBegin(CullContext)
,
cull(CullContext)
, and
cullEnd(CullContext)
, in that order.cc
- the cull context.protected void cullBegin(CullContext cc)
cc
- the cull context.protected void cull(CullContext cc)
cc
- the cull context.protected void cullEnd(CullContext cc)
cc
- the cull context.protected void drawApply(DrawContext dc)
drawBegin(DrawContext)
,
draw(DrawContext)
, and
drawEnd(DrawContext)
, in that order.dc
- the draw context.protected void drawBegin(DrawContext dc)
dc
- the draw context.protected void draw(DrawContext dc)
dc
- the draw context.protected void drawEnd(DrawContext dc)
dc
- the draw context.protected void pickApply(PickContext pc)
pickBegin(PickContext)
,
pick(PickContext)
, and
pickEnd(PickContext)
, in that order.pc
- the pick context.protected void pickBegin(PickContext pc)
pc
- the pick context.protected void pickEnd(PickContext pc)
pc
- the pick context.