org.mt4j.components
Class MTCanvas

java.lang.Object
  extended by org.mt4j.components.MTComponent
      extended by org.mt4j.components.MTCanvas
All Implemented Interfaces:
IMTComponent, IMTComponent3D, IHitTestInfoProvider, IMTInputEventListener, IGestureEventListener

public class MTCanvas
extends MTComponent

    
implements IHitTestInfoProvider

    

The canvas to add all objects to.

Author:
Christopher Ruff

Constructor Summary
MTCanvas(processing.core.PApplet pApplet, Icamera attachedCamera)
          The Constructor.
MTCanvas(processing.core.PApplet pApplet, java.lang.String name, Icamera attachedCamera)
          The Constructor.
 
Method Summary
protected  void destroyComponent()
          
Override this to clean up resources when destroying a component.
 void drawAndUpdateCanvas(processing.core.PGraphics graphics, long updateTime)
          Updates and then draws every visible object in the canvas.
 int getCacheClearTime()
          Gets the cache clear time.
 long getCacheTimeDelta()
          Gets the cache time delta.
 ClusterManager getClusterManager()
          Gets the cluster manager.
 IMTComponent3D getComponentAt(float x, float y)
          Method for asking the canvas whether and which object is at the specified screen position.
 boolean isBackGroundAt(float x, float y)
          Checks if is back ground at.
 boolean isFrustumCulling()
           
 boolean isUseHitTestCache()
          Checks if is use hit test cache.
 boolean processInputEvent(MTInputEvent inEvt)
          Processes the input event.
 void setCacheClearTime(int cacheClearTime)
          Sets the time intervals in ms in which the canvas clears its hit test cache Default value is: 20000 ms This is important to prevent the hit test cache from growing indefinitely.
 void setCacheTimeDelta(long cacheTimeDelta)
          If repeated calls to getObjectAt(float x, float y) in MTCanvas class are called during the provided cacheTimeDelta, the Canvas looks into his cache instead of querying all objects again Default value is: 80.
 void setClusterManager(ClusterManager selectionManager)
          Sets the cluster manager.
 void setFrustumCulling(boolean frustumCulling)
           
 void setUseHitTestCache(boolean useHitTestCache)
          The canvas can be set to look into a hit test cache if repeated calls to getComponentAt() with the same coordinates during a short period of time are made.
 void updateComponent(long timeDelta)
          Tells the component to update its state if neccessary.
 
Methods inherited from class org.mt4j.components.MTComponent
addChild, addChild, addChildren, addGestureListener, addInputListener, addStateChangeListener, applyLocalMatrix, attachCamera, componentContainsPointLocal, containsChild, containsDirectChild, containsPointGlobal, destroy, drawComponent, fireInputEvent, fireStateChange, fireStateChange, getAttachedCamera, getChildbyID, getChildByIndex, getChildByName, getChildClip, getChildCount, getChildIndexOf, getChildList, getChildren, getClip, getController, getCustomViewportSetting, getDefaultViewportSetting, getGestureListeners, getGlobalInverseMatrix, getGlobalMatrix, getGlobalVecToParentRelativeSpace, getID, getInputListeners, getInputProcessors, getIntersectionGlobal, getIntersectionLocal, getLight, getLocalInverseMatrix, getLocalMatrix, getLocalVecToParentRelativeSpace, getName, getParent, getRenderer, getRoot, getTransformToDestinationLocalSpace, getTransformToDestinationParentSpace, getUserData, getViewingCamera, globalToLocal, globalToLocal, hasCustomViewPort, isComposite, isContainedIn, isDepthBufferDisabled, isEnabled, isGestureAllowed, isPickable, isVisible, localToGlobal, pick, pick, postDraw, postDrawChildren, preDraw, processGestureEvent, registerInputProcessor, removeAllChildren, removeAllGestureEventListeners, removeAllGestureEventListeners, removeChild, removeChild, removeFromParent, removeGestureEventListener, removeInputListener, removeStateChangeListener, reOrthogonalize, rotateX, rotateX, rotateXGlobal, rotateY, rotateY, rotateYGlobal, rotateZ, rotateZ, rotateZGlobal, scale, scale, scaleGlobal, sendChildToFront, sendToFront, setChildClip, setClip, setComposite, setController, setDepthBufferDisabled, setEnabled, setGestureAllowance, setLight, setLocalMatrix, setMatricesDirty, setName, setPickable, setUserData, setViewPortSettings, setVisible, toString, transform, translate, translate, translateGlobal, unregisterAllInputProcessors, unregisterInputProcessor
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MTCanvas

public MTCanvas(processing.core.PApplet pApplet,
                Icamera attachedCamera)
The Constructor.

Parameters:
pApplet - the applet
globalCamera - the global camera

MTCanvas

public MTCanvas(processing.core.PApplet pApplet,
                java.lang.String name,
                Icamera attachedCamera)
The Constructor.

Parameters:
pApplet - the applet
name - the name
attachedCamera - the attached camera
Method Detail

destroyComponent

protected void destroyComponent()
Description copied from class: MTComponent

Override this to clean up resources when destroying a component. This method gets called by the destroy method. So you shouldnt invoke this method directly.

Overrides:
destroyComponent in class MTComponent

getComponentAt

public IMTComponent3D getComponentAt(float x,
                                     float y)
Method for asking the canvas whether and which object is at the specified screen position.

IMPORTANT: this method returns the MTCanvas instance if no other object is hit. This means that the MTCanvas instance acts like the background => Gestures that are supposed to be performed on the background have to check if they hit the canvas. And the gestureevents should then have the canvas as their targetComponent! Also, you have to be careful in other gestures, as even when you dont hit an object, you will get the mtcanvas returned as the hit component - not null!

Note: if the hit component is part of a cluster, the cluster is returned!

Specified by:
getComponentAt in interface IHitTestInfoProvider
Parameters:
x - the screen x coordinate
y - the screen y coordinate
Returns:
the object at that position or this MTCanvas instance if no component was hit

isBackGroundAt

public boolean isBackGroundAt(float x,
                              float y)
Description copied from interface: IHitTestInfoProvider
Checks if is back ground at.

Specified by:
isBackGroundAt in interface IHitTestInfoProvider
Parameters:
x - the x
y - the y
Returns:
true, if is back ground at

updateComponent

public void updateComponent(long timeDelta)
Description copied from class: MTComponent
Tells the component to update its state if neccessary. This is called shortly before the component's drawComponent() method is invoked. The timeDelta parameter indicates the time passed since the last frame was drawn and can be used for animation for example.
Also, this updates the associated IMTController object if existing. If overriden, the superclass implementation should always be called!

Specified by:
updateComponent in interface IMTComponent
Overrides:
updateComponent in class MTComponent
Parameters:
timeDelta - the time delta

drawAndUpdateCanvas

public void drawAndUpdateCanvas(processing.core.PGraphics graphics,
                                long updateTime)
Updates and then draws every visible object in the canvas. First calls the updateComponent(long timeDelta) method. Then the drawComponent() method of each object in the scene graph. Also handles the setting of cameras attached to the objects.

Parameters:
graphics -
updateTime - the time passed since the last update (in ms)

processInputEvent

public boolean processInputEvent(MTInputEvent inEvt)
Description copied from interface: IMTComponent
Processes the input event.

Specified by:
processInputEvent in interface IMTComponent
Specified by:
processInputEvent in interface IMTInputEventListener
Overrides:
processInputEvent in class MTComponent
Parameters:
inEvt - the in evt
Returns:
true, if successful

getClusterManager

public ClusterManager getClusterManager()
Gets the cluster manager.

Returns:
the cluster manager

setClusterManager

public void setClusterManager(ClusterManager selectionManager)
Sets the cluster manager.

Parameters:
selectionManager - the new cluster manager

getCacheTimeDelta

public long getCacheTimeDelta()
Gets the cache time delta.

Returns:
the cache time delta

setCacheTimeDelta

public void setCacheTimeDelta(long cacheTimeDelta)
If repeated calls to getObjectAt(float x, float y) in MTCanvas class are called during the provided cacheTimeDelta, the Canvas looks into his cache instead of querying all objects again Default value is: 80.

Parameters:
cacheTimeDelta - the cache time delta

isUseHitTestCache

public boolean isUseHitTestCache()
Checks if is use hit test cache.

Returns:
true, if is use hit test cache

setUseHitTestCache

public void setUseHitTestCache(boolean useHitTestCache)
The canvas can be set to look into a hit test cache if repeated calls to getComponentAt() with the same coordinates during a short period of time are made. This period of time can be set with setCacheTimeDelta(long cacheTimeDelta)

This is useful for example when a click is made many gestureanalyzers call getObjectAt() almost concurrently.

Parameters:
useHitTestCache - the use hit test cache

getCacheClearTime

public int getCacheClearTime()
Gets the cache clear time.

Returns:
the cache clear time

setCacheClearTime

public void setCacheClearTime(int cacheClearTime)
Sets the time intervals in ms in which the canvas clears its hit test cache Default value is: 20000 ms

This is important to prevent the hit test cache from growing indefinitely.

Parameters:
cacheClearTime - the cache clear time

isFrustumCulling

public boolean isFrustumCulling()

setFrustumCulling

public void setFrustumCulling(boolean frustumCulling)