org.mt4j.components
Class MTComponent

java.lang.Object
  extended by org.mt4j.components.MTComponent
All Implemented Interfaces:
IMTComponent, IMTComponent3D, IMTInputEventListener, IGestureEventListener
Direct Known Subclasses:
AbstractVisibleComponent, Cluster, MTCanvas, MTOverlayContainer, MTSvg

public class MTComponent
extends java.lang.Object

    
implements IMTComponent3D, IMTInputEventListener, IGestureEventListener

    

This is the base class for all scenegraph nodes. It provides basic methods for adding and managing child nodes. It also allows for changing the components position and orientation in space. Picking those components with a picking ray is also supported, if intersection testing is properly implemented by extending subclasses.

This base class has no visible representation an thus can be used as a group container node for other scene graph objects.

Author:
Christopher Ruff

Constructor Summary
MTComponent(processing.core.PApplet pApplet)
          Creates a new component.
MTComponent(processing.core.PApplet pApplet, Icamera attachedCamera)
          Creates a new component.
MTComponent(processing.core.PApplet pApplet, java.lang.String name)
          Creates a new component.
MTComponent(processing.core.PApplet pApplet, java.lang.String name, Icamera attachedCamera)
          Creates a new component.
 
Method Summary
 void addChild(int i, MTComponent tangibleComp)
          Adds the child at the specified position in the list of children.
 void addChild(MTComponent tangibleComp)
          Adds a component as a child to this component.
 void addChildren(MTComponent[] tangibleComps)
          Adds an array of components to this component as children.
 void addGestureListener(java.lang.Class gestureEvtSender, IGestureEventListener listener)
          Adds a gesture listener to this component.
 void addInputListener(IMTInputEventListener inputListener)
          Adds an input listener to this component.
 void addStateChangeListener(StateChange state, StateChangeListener listener)
          Adds the state change listener.
protected  void applyLocalMatrix()
          Applies (multiplies) this components local matrix to processings current matrix.
 void attachCamera(Icamera attachedCamera)
          Attaches a camera to this component.
protected  boolean componentContainsPointLocal(Vector3D testPoint)
          Checks whether the specified point is contained in this component.
 boolean containsChild(MTComponent tangibleComp)
          Goes through all children and their children to check if this component tree contains the given component.
 boolean containsDirectChild(MTComponent tangibleComp)
          Checks if the given component is a direct child of this component.
 boolean containsPointGlobal(Vector3D testPoint)
          Checks whether this, or this component's children contains the specified point.
 void destroy()
          Removes this component from its parent.
protected  void destroyComponent()
          
Override this to clean up resources when destroying a component.
 void drawComponent(processing.core.PGraphics g)
          Draws this component only (Not its children!).
protected  void fireInputEvent(MTInputEvent iEvt)
           
protected  void fireStateChange(StateChange state)
          Fire state change.
protected  void fireStateChange(StateChangeEvent evt)
          Fire state change.
 Icamera getAttachedCamera()
          Gets the camera attached to this component or null if it doesent have one.
 MTComponent getChildbyID(int ID)
          Gets the child by its unique ID.
 MTComponent getChildByIndex(int index)
          Gets the child by index.
 MTComponent getChildByName(java.lang.String name)
          Gets the child by name.
 Clip getChildClip()
          Gets the child clip.
 int getChildCount()
          Gets the child count.
 int getChildIndexOf(MTComponent comp)
          Gets the child index of a child.
protected  java.util.List<MTComponent> getChildList()
          Gets the child list which is also used internally in MTComponent.
 MTComponent[] getChildren()
          Gets the children.
 Clip getClip()
          Gets the clip.
 IMTController getController()
          Gets the controller.
 ViewportSetting getCustomViewportSetting()
          Gets the custom viewport setting.
 ViewportSetting getDefaultViewportSetting()
          Gets the default viewport setting.
 IGestureEventListener[] getGestureListeners()
          Returns the gesture listeners.
 Matrix getGlobalInverseMatrix()
          Returns the absolute inverse matrix (inverse of the global) which inverts all transforms made from the parents down to this child.
 Matrix getGlobalMatrix()
          Multiplies all transformation matrices of the objects parents up the this object and returns it.
static Vector3D getGlobalVecToParentRelativeSpace(MTComponent referenceComp, Vector3D point)
          Transforms the given vector in global space coordinates to be relative to the given reference objects parent space.
 int getID()
          Gets the iD.
 IMTInputEventListener[] getInputListeners()
          Gets the input listeners.
 AbstractComponentProcessor[] getInputProcessors()
          Gets the component input processors.
 Vector3D getIntersectionGlobal(Ray ray)
          Checks if the specified ray intersects this component or one if its childcomponents.
 Vector3D getIntersectionLocal(Ray localRay)
          Returns the intersection point of the ray and this component (children are not checked for intersections).
 MTLight getLight()
          Gets the light.
 Matrix getLocalInverseMatrix()
          Gets the local inverse matrix.
 Matrix getLocalMatrix()
          Gets the local basis matrix.
static Vector3D getLocalVecToParentRelativeSpace(MTComponent referenceComp, Vector3D point)
          Transforms the point - defined in the objects coordinate space - into parent relative space.
 java.lang.String getName()
          Gets the name.
 MTComponent getParent()
          Gets the parent.
 processing.core.PApplet getRenderer()
          Gets the renderer.
 MTComponent getRoot()
          Gets the ancestor.
static Matrix getTransformToDestinationLocalSpace(MTComponent originComponent, MTComponent destinationComponent)
          Gets the transform to destination local space.
static Matrix getTransformToDestinationParentSpace(MTComponent originComponent, MTComponent destinationComponent)
          Calculates the transformation necessary to transform a component to be relative to the destination component.
 java.lang.Object getUserData(java.lang.Object key)
          Gets the user data associated with the specified key.
 Icamera getViewingCamera()
          Gets the camera through which this component is being viewed.
 Ray globalToLocal(Ray globalRay)
          Transforms the global ray into local coordinate space and returns the new ray.
 Vector3D globalToLocal(Vector3D point)
          Converts the Vector3D object from the world (global) coordinates to the component's (local) coordinates.
 boolean hasCustomViewPort()
          Checks for custom view port.
 boolean isComposite()
          Checks if is composite.
 boolean isContainedIn(IFrustum frustum)
          Checks if this component is contained in the specified viewing frustum (is currently visible).
 boolean isDepthBufferDisabled()
          Checks if is always drawn on top.
 boolean isEnabled()
          Checks if the component is enabled.
 boolean isGestureAllowed(java.lang.Class c)
          Checks if the gesture is allowed on this component.
 boolean isPickable()
          Checks if is pickable.
 boolean isVisible()
          Checks if the component is visible.
 Vector3D localToGlobal(Vector3D point)
          Converts the Vector3D object from the component's (local) coordinates to the world/canvas (global) coordinates.
 PickResult pick(float x, float y)
          Checks which object lies under the specified screen coordinates.
 PickResult pick(float x, float y, boolean onlyPickables)
          Checks which object lies under the specified screen coordinates.
 void postDraw(processing.core.PGraphics g)
          Post draw.
 void postDrawChildren(processing.core.PGraphics g)
          Post draw Children.
 void preDraw(processing.core.PGraphics g)
          This method is called just before the components drawComponent method is invoked.
 boolean processGestureEvent(MTGestureEvent gestureEvent)
          Processes gesture events.
 boolean processInputEvent(MTInputEvent inEvt)
          Processes the input event.
 void registerInputProcessor(AbstractComponentProcessor inputProcessor)
          Registers an component input processor with this component.
 void removeAllChildren()
          Removes all direct children of this component.
 void removeAllGestureEventListeners()
          Removes the all gesture event listeners.
 void removeAllGestureEventListeners(java.lang.Class gestureEvtSender)
          Removes the all gesture event listeners who listen to the specified input processor.
 void removeChild(int i)
          Tries to remove the specified child from this component.
 void removeChild(MTComponent comp)
          Tries to remove the specified child from this component.
 void removeFromParent()
          Removes this component from its parent.
 void removeGestureEventListener(java.lang.Class gestureEvtSender, IGestureEventListener listener)
          Removes the gesture event listener.
 void removeInputListener(IMTInputEventListener inputListener)
          Removes the input listener.
 void removeStateChangeListener(StateChange state, StateChangeListener listener)
          Removes the state change listener.
 void reOrthogonalize()
          Re orthogonalizes the components local matrix.
 void rotateX(Vector3D rotationPoint, float degree)
          X rotate.
 void rotateX(Vector3D rotationPoint, float degree, TransformSpace transformSpace)
          X rotate.
 void rotateXGlobal(Vector3D rotationPoint, float degree)
          Rotates the component around its x-axis and the rotation point (in global coordiantes).
 void rotateY(Vector3D rotationPoint, float degree)
          Y rotate.
 void rotateY(Vector3D rotationPoint, float degree, TransformSpace transformSpace)
          Y rotate.
 void rotateYGlobal(Vector3D rotationPoint, float degree)
          Rotates the component around its y-axis and the rotation point (in global coordiantes).
 void rotateZ(Vector3D rotationPoint, float degree)
          Rotates the obj around the z-axis around the rotationpoint.
 void rotateZ(Vector3D rotationPoint, float degree, TransformSpace transformSpace)
          Rotates the component around the specified point on the Z axis.
 void rotateZGlobal(Vector3D rotationPoint, float degree)
          Rotates the component around its z-axis and the rotation point (in world coordiantes).
 void scale(float X, float Y, float Z, Vector3D scalingPoint)
          CURRENTLY DOES NOT REALLY SUPPORT NON-UNIFORM SCALING!
 void scale(float X, float Y, float Z, Vector3D scalingPoint, TransformSpace transformSpace)
          Scales the obj around the scalingPoint.
 void scaleGlobal(float X, float Y, float Z, Vector3D scalingPoint)
          Scales the component in world from the scalingpoint (in world coordiantes) in the 3 axis.
protected  void sendChildToFront(MTComponent child)
          Puts this child to the end of the children list of this component.
 void sendToFront()
          Puts this components to the end of the children list of its parent.
 void setChildClip(Clip childClip)
          Sets the clip mask for this components children.
 void setClip(Clip clip)
          Sets the clip mask for this component.
 void setComposite(boolean composite)
          Setting a components setComposite to 'true' will result in THIS component getting picked and returned when a child of this component is picked.
 IMTController setController(IMTController controller)
          This attaches a controller object to the component.
 void setDepthBufferDisabled(boolean drawOnTop)
          
If the depth buffer is disabled, the order in which the components are drawn alone decides which objects will appear ontop of others, instead of their distance to the camera.
 void setEnabled(boolean enabled)
          Sets the component enabled.
 void setGestureAllowance(java.lang.Class c, boolean allowed)
          Sets the gesture allowance.
 void setLight(MTLight light)
          Sets the light.
 void setLocalMatrix(Matrix localBasisMatrix)
          Sets a matrix by which this component and its children will be transformed.
 void setMatricesDirty(boolean matricesDirty)
          Informs the object (and its children), that its matrix - OR ONE OF ITS PARENT'S MATRIX - has been altered.
 void setName(java.lang.String name)
          Sets the name of the component.
 void setPickable(boolean pickable)
          If set to true, this component will be testable for intersections.
 void setUserData(java.lang.Object key, java.lang.Object value)
          Sets user data for this component.
 void setViewPortSettings(ViewportSetting viewPortSettings)
          Sets the view port settings.
 void setVisible(boolean visible)
          Sets the visibility.
 java.lang.String toString()
           
 void transform(Matrix transformMatrix)
          Transforms the shapes local coordinate space by the specified matrix.
 void translate(Vector3D dirVect)
          Translates this component in the give direction, relative to its parent component.
 void translate(Vector3D dirVect, TransformSpace transformSpace)
          Translate.
 void translateGlobal(Vector3D dirVect)
          Translates the object in the given direction relative to the global world coordinate frame.
 void unregisterAllInputProcessors()
          Unregister all previously registered component input processors.
 void unregisterInputProcessor(AbstractComponentProcessor inputProcessor)
          Unregister a component input processor.
 void updateComponent(long timeDelta)
          Tells the component to update its state if neccessary.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MTComponent

public MTComponent(processing.core.PApplet pApplet)
Creates a new component. The component has no initial visual representation.

Parameters:
pApplet - the applet

MTComponent

public MTComponent(processing.core.PApplet pApplet,
                   java.lang.String name)
Creates a new component. The component has no visual representation.

Parameters:
pApplet - the applet
name - the name

MTComponent

public MTComponent(processing.core.PApplet pApplet,
                   Icamera attachedCamera)
Creates a new component. The component has no visual representation.

Parameters:
pApplet - the applet
attachedCamera - the camera to view this and this components children with

MTComponent

public MTComponent(processing.core.PApplet pApplet,
                   java.lang.String name,
                   Icamera attachedCamera)
Creates a new component. The component has no visual representation.

Parameters:
pApplet - the applet
name - the name of the component
attachedCamera - a camera to view this and this components children with
Method Detail

addInputListener

public void addInputListener(IMTInputEventListener inputListener)
Adds an input listener to this component. The listener will be informed if this component recieves an input event.

Parameters:
inputListener - the input listener

removeInputListener

public void removeInputListener(IMTInputEventListener inputListener)
Removes the input listener.

Parameters:
inputListener - the input listener

getInputListeners

public IMTInputEventListener[] getInputListeners()
Gets the input listeners.

Returns:
the input listeners

fireInputEvent

protected void fireInputEvent(MTInputEvent iEvt)

getViewingCamera

public Icamera getViewingCamera()
Description copied from interface: IMTComponent3D
Gets the camera through which this component is being viewed. This is the attached camera of this, or one of its parant's attached cameras.

Specified by:
getViewingCamera in interface IMTComponent3D
Returns:
the responsible camera

getAttachedCamera

public Icamera getAttachedCamera()
Gets the camera attached to this component or null if it doesent have one.

Returns:
the attached camera

attachCamera

public void attachCamera(Icamera attachedCamera)
Attaches a camera to this component. This component and all its children will be viewed through the specified camera.

Parameters:
attachedCamera - the attached camera

registerInputProcessor

public void registerInputProcessor(AbstractComponentProcessor inputProcessor)
Registers an component input processor with this component. Input processors are used to process the input events a component recieves by checking them for special patterns and conditions and firing gesture events back to the component. To recognize a multi-touch drag gesture on a component for example, we would register a DragProcessor object with this component.

Parameters:
inputProcessor - the input processor

unregisterInputProcessor

public void unregisterInputProcessor(AbstractComponentProcessor inputProcessor)
Unregister a component input processor.

Parameters:
inputProcessor - the input processor

unregisterAllInputProcessors

public void unregisterAllInputProcessors()
Unregister all previously registered component input processors.


getInputProcessors

public AbstractComponentProcessor[] getInputProcessors()
Gets the component input processors.

Returns:
the input processors

addGestureListener

public void addGestureListener(java.lang.Class gestureEvtSender,
                               IGestureEventListener listener)
Adds a gesture listener to this component. The specified gesture listener's processGestureEvent(..) method will be called when a gesture event is processed by this component. The IInputProcessor paramter type specifies the source of the gesture event we are interested in. So to listen to drag events only for example, we would specify the DragProcessor.class as the first parameter.

Parameters:
gestureEvtSender - the gesture evt sender
listener - the listener

removeGestureEventListener

public void removeGestureEventListener(java.lang.Class gestureEvtSender,
                                       IGestureEventListener listener)
Removes the gesture event listener.

Parameters:
gestureEvtSender - the gesture evt sender
listener - the listener

removeAllGestureEventListeners

public void removeAllGestureEventListeners()
Removes the all gesture event listeners.


removeAllGestureEventListeners

public void removeAllGestureEventListeners(java.lang.Class gestureEvtSender)
Removes the all gesture event listeners who listen to the specified input processor.

Parameters:
gestureEvtSender - the gesture evt sender

getGestureListeners

public final IGestureEventListener[] getGestureListeners()
Returns the gesture listeners.

Returns:
the gesture listeners

addStateChangeListener

public void addStateChangeListener(StateChange state,
                                   StateChangeListener listener)
Adds the state change listener.

Parameters:
state - the state
listener - the listener

removeStateChangeListener

public void removeStateChangeListener(StateChange state,
                                      StateChangeListener listener)
Removes the state change listener.

Parameters:
state - the state
listener - the listener

fireStateChange

protected void fireStateChange(StateChangeEvent evt)
Fire state change.

Parameters:
evt - the evt

fireStateChange

protected void fireStateChange(StateChange state)
Fire state change.

Parameters:
state - the state

destroy

public void destroy()