wobs.scene3d.player
Class X3DNode

java.lang.Object
  extended by wobs.scene3d.player.X3DNode
All Implemented Interfaces:
java.lang.Cloneable
Direct Known Subclasses:
X3DScene

public abstract class X3DNode
extends java.lang.Object
implements java.lang.Cloneable

This class is used to represent a X3D/VRML node of any type. All node types are listed in the class wobs.scene3d.nodes.Node. A node contains specific fields depending on the node type. Every supported node type is associated with a field access class found in the wobs.scene3d.nodes package. To access a field of a node you use the method X3DNode.getField(int) with the appropriate field access constant.

Ex. If you want to access the appearance field from a node of type Shape, you would call:
node.getField(Shape.appearance) (provided that you have imported the class wobs.scene3d.nodes.Shape).


Field Summary
 java.lang.String name
          Deprecated. should use getName() instead
 byte type
          Deprecated. should use getType() instead
 
Method Summary
 void addChild(X3DNode node)
          Adds a node to the children field of this object.
abstract  java.lang.Object clone()
          Creates and returns a copy of this object.
 X3DNode[] getChildren()
          Retrieves the children nodes of this object.
 X3DField getField(int fieldIndex)
          Retrieves a field of this object.
 java.lang.String getName()
          Returns the unique user defined name of this node.
 X3DNode getNode(int fieldIndex)
          Retrieves the contained node in the specified field of this object.
 X3DNode getNode(java.lang.String name)
          Retrieves the node with the specified name by searching for it in this object's fields and sub-nodes.
 X3DNode getParent()
          Returns the parent node in the Scene graph of this node.
 int getType()
          Returns the type of this node.
 void move(float moveX, float moveY, float moveZ)
          Moves the object and all its sub-objects relative to the parent object.
 void removeChild(X3DNode node)
          Removes a node from the children field of this object.
 void rotN(float x, float y, float z, float Nx, float Ny, float Nz, float angle)
          Rotates the object relative to the parent object.
 void scale(float scaleX, float scaleY, float scaleZ)
          Scales the object and all its sub-objects.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

name

public java.lang.String name
Deprecated. should use getName() instead
The unique user defined name of this node.


type

public byte type
Deprecated. should use getType() instead
The type of this node. See the Nodes class for more information.

Method Detail

clone

public abstract java.lang.Object clone()
Creates and returns a copy of this object.

Overrides:
clone in class java.lang.Object
Returns:
a clone of this instance.

getName

public java.lang.String getName()
Returns the unique user defined name of this node. This is the same name as the one defined using the "DEF" or "USE" mechanism in a X3D/VRML file.

Returns:
the X3D Node name

getType

public int getType()
Returns the type of this node. See the Nodes class for more information on existing types.

Returns:
the X3D Node type

getChildren

public X3DNode[] getChildren()
Retrieves the children nodes of this object. The method returns the nodes as an array of X3DNode objects. This method does exactly the same thing as calling getField("nodeTypeClass".children).getNodeArray().

Returns:
the children node of this field.

getParent

public X3DNode getParent()
Returns the parent node in the Scene graph of this node.

Returns:
the parent node for this node

addChild

public void addChild(X3DNode node)
Adds a node to the children field of this object.

Parameters:
node - the node to be added to the children field.

removeChild

public void removeChild(X3DNode node)
Removes a node from the children field of this object.

Parameters:
node - the node to be removed from the children field.

getNode

public X3DNode getNode(int fieldIndex)
Retrieves the contained node in the specified field of this object. This method calls getField(fieldIndex).getNode().

Parameters:
fieldIndex - the index of the field to be accessed.
Returns:
the node in the specified field.

getField

public X3DField getField(int fieldIndex)
Retrieves a field of this object. The fieldIndex parameter indicate which field to return. The field index used for accessing a particular field is found under the node classes in the Nodes package. Ex. accessing field translation in a Transform node is done with this code:
transformNode.getField(Nodes.Transform.translation);

Parameters:
fieldIndex - the index of the field to be accessed
Returns:
the X3DField that represent the specified field

getNode

public X3DNode getNode(java.lang.String name)
Retrieves the node with the specified name by searching for it in this object's fields and sub-nodes. If the node was not found this method returns null.

Parameters:
name - The name of the node to retrieve
Returns:
The X3DNode representing the named node.

scale

public void scale(float scaleX,
                  float scaleY,
                  float scaleZ)
Scales the object and all its sub-objects.

This method works for nodes of type DirectionalLight, PointLight, Scene, Shape and Transform.

Parameters:
scaleX - the scaling along the x axis
scaleY - the scaling along the y axis
scaleZ - the scaling along the z axis

move

public void move(float moveX,
                 float moveY,
                 float moveZ)
Moves the object and all its sub-objects relative to the parent object.

This method works for nodes of type DirectionalLight, PointLight, Scene, Shape and Transform.

Parameters:
moveX - the movement along the x axis
moveY - the movement along the y axis
moveZ - the movement along the z axis

rotN

public void rotN(float x,
                 float y,
                 float z,
                 float Nx,
                 float Ny,
                 float Nz,
                 float angle)
Rotates the object relative to the parent object. The parameters specify a rotation point (around which the rotation will be performed), a normalised rotation vector (specifying a direction to rotate around) and an angle (in radians) that control the amount of rotation. A normalised vector means that sqrt(Nx*Nx + Ny*Ny + Nz*Nz) = 1, which can be ensured by dividing each Nx, Ny and Nz by the amount sqrt(Nx*Nx + Ny*Ny + Nz*Nz).

For example, rotating 45 degrees (PI/4 radians) around the point (5, 0, 10) and the y-axis would be achieved by calling rotN(5, 0, 10, 0, 1, 0, Math.PI/4)
This method works for nodes of type DirectionalLight, PointLight, Scene, Shape and Transform.

Parameters:
x - the x coordinate of the point around which the rotation will be performed
y - the y coordinate of the point around which the rotation will be performed
z - the z coordinate of the point around which the rotation will be performed
Nx - the x coordinate of the normalised rotation vector
Ny - the y coordinate of the normalised rotation vector
Nz - the z coordinate of the normalised rotation vector
angle - the rotation angle, in radians (1 radian = PI/180 degrees)