org.mt4j.components.visibleComponents.shapes
Class AbstractShape

java.lang.Object
  extended by org.mt4j.components.MTComponent
      extended by org.mt4j.components.visibleComponents.AbstractVisibleComponent
          extended by org.mt4j.components.visibleComponents.shapes.AbstractShape
All Implemented Interfaces:
IMTComponent, IMTComponent3D, IMTInputEventListener, IGestureEventListener
Direct Known Subclasses:
MTLine, MTPolygon, MTTriangleMesh

public abstract class AbstractShape
extends AbstractVisibleComponent

    

Abstract superclass for all kinds of shapes defined by vertices.

Author:
Christopher Ruff

Field Summary
static int BOUNDS_CHECK_THEN_GEOMETRY_CHECK
          The Constant BOUNDS_CHECK_THEN_GEOMETRY_CHECK.
static int BOUNDS_DONT_USE
          The Constant BOUNDS_DONT_USE.
static int BOUNDS_ONLY_CHECK
          The Constant BOUNDS_ONLY_CHECK.
 
Constructor Summary
AbstractShape(GeometryInfo geometryInfo, processing.core.PApplet pApplet)
          Creates a new geometry with the geometryInfo provided.
AbstractShape(Vertex[] vertices, processing.core.PApplet pApplet)
          Creates a new shape with the vertices provided.
 
Method Summary
protected  boolean componentContainsPointLocal(Vector3D testPoint)
          Checks whether the specified point is contained in this component.
protected  IBoundingShape computeDefaultBounds()
          Computes a default bounding box for the shape.
 void destroy()
          Removes this component from its parent.
protected abstract  void destroyComponent()
          
Override this to clean up resources when destroying a component.
protected  void destroyDisplayLists()
          This is called during the shape's destroy() method.
 void disableAndDeleteDisplayLists()
          Deletes the displaylists of the object and sets setUseDisplayList() to false.
 void generateAndUseDisplayLists()
          Generates and uses openGL display lists for drawing this shape.
 void generateDisplayLists()
          Generates 2 openGL display lists for drawing this shape.
 IBoundingShape getBoundingShape()
          Gets the bounding shape.
 Vector3D getCenterPointGlobal()
          Gets the center point global.
abstract  Vector3D getCenterPointLocal()
          Gets the center point in local object space.
 Vector3D getCenterPointRelativeToParent()
          Gets the center point relative to parent.
 Vector3D[] getConvexHullXYGlobal()
          Calculates the 2D XY convex hull for this shape.
 GeometryInfo getGeometryInfo()
          Gets the geometry info.
abstract  Vector3D getGeometryIntersectionLocal(Ray ray)
          Tests if the ray intersects the shape and where.
abstract  float getHeightXY(TransformSpace transformSpace)
          Get the height of the shape in the XY-Plane.
 Vector3D getIntersectionLocal(Ray ray)
          Returns the intersection point of the ray and this component (children are not checked for intersections).
 processing.core.PImage getTexture()
          Gets the texture.
 int getTextureMode()
          Gets the processing texture mode.
 int getVertexCount()
          Gets the vertex count.
 Vertex[] getVerticesGlobal()
          Returns the vertices of this shape in real world (global) coordinates
Caution: If you alter them in anyway, changes will only be consistent if you call the setVertices() method of the shape.
 Vertex[] getVerticesLocal()
          Returns the vertices of this shape without any transformations applied
Caution: If you alter them in anyway, changes will only be consistent by calling the setVertices(Vertex[]) method with the changes vertices as an argument!.
abstract  float getWidthXY(TransformSpace transformSpace)
          Get the width of the shape in the XY-Plane.
 boolean isBoundingShapeSet()
          Checks if is bounding shape set.
 boolean isBoundsAutoCompute()
          Checks if is bounds auto compute.
 boolean isContainedIn(IFrustum frustum)
          Checks if this component is contained in the specified viewing frustum (is currently visible).
abstract  boolean isGeometryContainsPointLocal(Vector3D testPoint)
          Tests is the geometry of the shape contains the given point.
 boolean isTextureEnabled()
          Checks if is texture enabled.
 boolean isUseDirectGL()
          Checks if is use direct gl.
 boolean isUseDisplayList()
          Checks if is use display list.
 boolean isUseVBOs()
          Checks if this shape is drawn using VBOs.
 void setBoundingShape(IBoundingShape boundingShape)
          Sets the bounding shape.
 void setBoundsAutoCompute(boolean autoCompute)
          Sets the bounds auto compute.
 void setBoundsBehaviour(int boundsBehaviour)
          Sets the bounds behaviour.
 void setBoundsPickingBehaviour(int boundsPickingBehaviour)
          Deprecated. Method was renamed! Use setBoundsBehaviour()!
protected  void setDefaultGestureActions()
          Assigns the default gesture to this component, drag, rotate, scale.
 void setFillColor(MTColor color)
          Sets the fill color.
 void setGeometryInfo(GeometryInfo geometryInfo)
          Sets a new geometryInfo with new vertices for this shape.
 void setMatricesDirty(boolean baseMatrixDirty)
          Informs the object (and its children), that its matrix - OR ONE OF ITS PARENT'S MATRIX - has been altered.
 void setPositionGlobal(Vector3D pos)
          Sets the global position of the component.
 void setPositionRelativeToOther(MTComponent otherComp, Vector3D pos)
          Sets the position of this component, relative to the other specified component.
 void setPositionRelativeToParent(Vector3D pos)
          Sets the position of the component, relative to its parent coordinate frame.
 void setStrokeColor(MTColor strokeColor)
          Sets the stroke color.
 void setTexture(processing.core.PImage newTexImage)
          Sets a texture for this shape.
 void setTextureEnabled(boolean texture)
          Tells the shape to use its texture.
 void setTextureMode(int textureMode)
          Sets the way texture coordinates are handled in processing.
 void setUseDirectGL(boolean drawPureGL)
          If set to true - which is the default if using the OpenGL render mode - this shape will bypass processings rendering pipeline and use the OpenGL context directly for performance increases.
 void setUseDisplayList(boolean useDisplayList)
          Tries to use a opengl display list for rendering this shape.
 void setUseVBOs(boolean useVBOs)
          
Tries to use Vertex Buffer Objects for displaying this shape.
 void setVertices(Vertex[] vertices)
          Sets new vertices for that shape.
 void tweenTranslate(Vector3D directionVect, float interpolationDuration, float accelerationEndTime, float decelerationStartTime)
          Moves this shape in the specified direction with an animation specified by the other parameters.
 void tweenTranslate(Vector3D directionVect, float interpolationDuration, float accelerationEndTime, float decelerationStartTime, int triggerDelay)
          Tween translate.
 void tweenTranslateTo(float x, float y, float z, float interpolationDuration, float accelerationEndTime, float decelerationStartTime)
          Moves this shape to the specified global position using an animation specified by the last three parameters
 
Methods inherited from class org.mt4j.components.visibleComponents.AbstractVisibleComponent
applyStyle, drawComponent, getFillColor, getFillDrawMode, getFillPaint, getLineStipple, getMaterial, getStrokeColor, getStrokeWeight, getStyleInfo, isDrawSmooth, isNoFill, isNoStroke, postDraw, postDrawChildren, preDraw, setDrawSmooth, setFillDrawMode, setFillPaint, setLineStipple, setMaterial, setNoFill, setNoStroke, setStrokeWeight, setStyleInfo
 
Methods inherited from class org.mt4j.components.MTComponent
addChild, addChild, addChildren, addGestureListener, addInputListener, addStateChangeListener, applyLocalMatrix, attachCamera, containsChild, containsDirectChild, containsPointGlobal, fireInputEvent, fireStateChange, fireStateChange, getAttachedCamera, getChildbyID, getChildByIndex, getChildByName, getChildClip, getChildCount, getChildIndexOf, getChildList, getChildren, getClip, getController, getCustomViewportSetting, getDefaultViewportSetting, getGestureListeners, getGlobalInverseMatrix, getGlobalMatrix, getGlobalVecToParentRelativeSpace, getID, getInputListeners, getInputProcessors, getIntersectionGlobal, getLight, getLocalInverseMatrix, getLocalMatrix, getLocalVecToParentRelativeSpace, getName, getParent, getRenderer, getRoot, getTransformToDestinationLocalSpace, getTransformToDestinationParentSpace, getUserData, getViewingCamera, globalToLocal, globalToLocal, hasCustomViewPort, isComposite, isDepthBufferDisabled, isEnabled, isGestureAllowed, isPickable, isVisible, localToGlobal, pick, pick, processGestureEvent, processInputEvent, 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, setName, setPickable, setUserData, setViewPortSettings, setVisible, toString, transform, translate, translate, translateGlobal, unregisterAllInputProcessors, unregisterInputProcessor, updateComponent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

BOUNDS_ONLY_CHECK

public static final int BOUNDS_ONLY_CHECK
The Constant BOUNDS_ONLY_CHECK.

See Also:
Constant Field Values

BOUNDS_CHECK_THEN_GEOMETRY_CHECK

public static final int BOUNDS_CHECK_THEN_GEOMETRY_CHECK
The Constant BOUNDS_CHECK_THEN_GEOMETRY_CHECK.

See Also:
Constant Field Values

BOUNDS_DONT_USE

public static final int BOUNDS_DONT_USE
The Constant BOUNDS_DONT_USE.

See Also:
Constant Field Values
Constructor Detail

AbstractShape

public AbstractShape(Vertex[] vertices,
                     processing.core.PApplet pApplet)
Creates a new shape with the vertices provided.

Parameters:
vertices - the vertices
pApplet - the applet

AbstractShape

public AbstractShape(GeometryInfo geometryInfo,
                     processing.core.PApplet pApplet)
Creates a new geometry with the geometryInfo provided.

Parameters:
geometryInfo - the geometry info
pApplet - the applet
Method Detail

setDefaultGestureActions

protected void setDefaultGestureActions()
Assigns the default gesture to this component, drag, rotate, scale.
Gets called in the constructor. Can be overridden in subclasses to allow other/more default gestures.


setBoundsBehaviour

public void setBoundsBehaviour(int boundsBehaviour)
Sets the bounds behaviour. The behaviour influences calculations in methods like getIntersectionLocal (used in picking) and getComponentContainsPointLocal. Allowed values are:

Parameters:
boundsBehaviour - the new bounds behaviour

setBoundsPickingBehaviour

public void setBoundsPickingBehaviour(int boundsPickingBehaviour)
Deprecated. Method was renamed! Use setBoundsBehaviour()!

Sets the bounds picking behaviour.

Parameters:
boundsPickingBehaviour - the new bounds picking behaviour

setBoundingShape

public void setBoundingShape(IBoundingShape boundingShape)
Sets the bounding shape.

Parameters:
boundingShape - the new bounding shape

getBoundingShape

public IBoundingShape getBoundingShape()
Gets the bounding shape.

Returns:
the bounding shape

isBoundingShapeSet

public boolean isBoundingShapeSet()
Checks if is bounding shape set.

Returns:
true, if is bounding shape set

computeDefaultBounds

protected IBoundingShape computeDefaultBounds()
Computes a default bounding box for the shape. This gets called after setting creating a shape and its setGeometryInfo method is called.


setBoundsAutoCompute

public void setBoundsAutoCompute(boolean autoCompute)
Sets the bounds auto compute.

Parameters:
autoCompute - the new bounds auto compute

isBoundsAutoCompute

public boolean isBoundsAutoCompute()
Checks if is bounds auto compute.

Returns:
true, if is bounds auto compute

setGeometryInfo

public void setGeometryInfo(GeometryInfo geometryInfo)
Sets a new geometryInfo with new vertices for this shape.
If running in OpenGL mode, this also creates new vertex buffers for openGL use and eventually new Vertex Buffer Objects or Displaylists depending on the objects settings! So DONT create them (buffers or vbos) on the geometryinfo yourself manually, prior to setting it here!
Also calls computeDefaultBounds() if setAutoComputeBounds() is true (default) to recreate the bounding shape.
NOTE: Be aware, that an old geometryinfo of this shape may have created VBOs or displaylists on the gfx card which we should delete if not needed anywhere else!

Parameters:
geometryInfo - the geometry info

getGeometryInfo

public GeometryInfo getGeometryInfo()
Gets the geometry info. The geometryinfo contains the geometric information of this shape by managing the shapes vertices, OpenGL vertex buffer objects and OpenGL display list.

Returns:
the geometry info the geometry information object of that shape

setVertices

public void setVertices(Vertex[] vertices)
Sets new vertices for that shape. and generates new vertex arrays for opengl mode.