|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--edu.umd.cs.jazz.ZSceneGraphObject | +--edu.umd.cs.jazz.ZVisualComponent | +--edu.umd.cs.jazz.ZCamera
ZCamera represents a viewport onto a list of nodes. A camera can look at any number of ZLayerGroups, and can specify where in space it looks as specified by an arbitrary affine transformation.
When a ZCanvas is created, it automatically creates a top-level camera attached to that canvas that is the same size as the canvas. Thus, the whole scenegraph is rendered within that canvas.
It is also possible to create an "internal camera" that acts as a portal, or internal window. That is, it is an object within the scene that looks onto the scene. To do this, create a scenegraph where the top-level camera sees both the regular layer, and a new layer that contains the internal camera. Then, make the new internal camera look at the regular layer. The following code demonstrates this:
ZCamera portal = new ZCamera(); portal.setBounds(100, 100, 200, 200); portal.setFillColor(Color.red); ZVisualLeaf leaf = new ZVisualLeaf(portal); leaf.setFindable(false); ZVisualGroup border = new ZVisualGroup(leaf); ZRectangle rect = new ZRectangle(100, 100, 200, 200); rect.setPenColor(Color.blue); rect.setFillColor(null); rect.setPenWidth(5.0); border.setFrontVisualComponent(rect); ZLayerGroup layer = new ZLayerGroup(border); canvas.getRoot().addChild(layer); canvas.getCamera().addLayer(layer); portal.addLayer(canvas.getLayer());
At first glance, it might seem that all that is necessary for these special objects is to make the render method depend on camera parameters. However, it is a bit more complex because the effective bounds of the object changes if the pen width of the object changes. Thus, the bounds of the object must be computed depending on the properties of the camera it is being rendered within.
In order to compute bounds for different camera views, two things must be done specially. First, the object must be set to have 'volatile bounds' (with the setVolatileBounds() method) which tells Jazz not to cache the bounds of the object, but to recompute them every time they are needed. The second thing is that the relevant camera must be consulted to get the camera state (such as view magnification). This can be done through the 'current render context' which is maintained in the root of the scenegraph. This can be found with getRoot().getCurrentRenderContext(). Finally, certain objects may want to also redefine the pick method using the render context if the picking is dependent on some context-sensitive attribute that is used for rendering.
Warning: Serialized and ZSerialized objects of this class will not be compatible with future Jazz releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Jazz. A future release of Jazz will provide support for long term persistence.
Field Summary | |
static java.awt.Color |
fillColor_DEFAULT
The default fill color. |
Fields inherited from class edu.umd.cs.jazz.ZSceneGraphObject |
bounds, listenerList, volatileBounds, volatileBounds_DEFAULT |
Constructor Summary | |
ZCamera()
Constructs a new ZCamera. |
|
ZCamera(ZLayerGroup layer,
ZDrawingSurface aSurface)
Constructs a new ZCamera. |
Method Summary | |
void |
addCameraListener(ZCameraListener l)
Adds the specified camera listener to receive camera events from this camera |
void |
addLayer(ZLayerGroup layer)
Add a portion of the scenegraph that what this camera sees. |
void |
animate(java.awt.geom.AffineTransform at,
int millis,
ZDrawingSurface surface)
Set the transform of this camera to the specified transform, and animate the change from its current transformation over the specified number of milliseconds using a slow-in slow-out animation. |
double |
cameraToLocal(java.awt.geom.Point2D pt,
ZNode node)
Transform a point in the camera's coordinate system through the camera down the tree to the specified node's local coordinate system. |
double |
cameraToLocal(java.awt.geom.Rectangle2D rect,
ZNode node)
Transform a rectangle in the camera's coordinate system through the camera down the tree to the specified node's local coordinate system. |
void |
center(java.awt.geom.Rectangle2D refBounds,
int millis,
ZDrawingSurface aSurface)
Animates the camera view so that the specified bounds (in global coordinates) is centered within the view of the camera. |
void |
center(java.awt.geom.Rectangle2D srcBounds,
java.awt.geom.Rectangle2D destBounds,
int millis,
ZDrawingSurface surface)
Animates the camera view so that a given global bounds appear within a specified screen bounds given in camera coordinates. |
void |
centerWithAspectChange(java.awt.geom.Rectangle2D refBounds,
int millis,
ZDrawingSurface aSurface)
Animates the camera view so that the camera view will match the given bounds exactly. |
void |
centerWithAspectChange(java.awt.geom.Rectangle2D srcBounds,
java.awt.geom.Rectangle2D destBounds,
int millis,
ZDrawingSurface surface)
Animates the given camera view so that a given global bounds appear within a specified screen bounds given in camera coordinates. |
protected void |
computeInverseViewTransform()
Internal method to compute the inverse camera transform based on the camera transform. |
ZRenderContext |
createRenderContext(java.awt.Graphics2D aG2,
ZBounds visibleBounds,
ZDrawingSurface aSurface,
int qualityRequested)
This returns a new instance of a ZRenderContext for this node. |
ZRenderContext |
createRenderContext(ZCamera camera)
This returns a new instance of a ZRenderContext for this node. |
java.lang.String |
dump()
Generate a string that represents this object for debugging. |
protected java.lang.Object |
duplicateObject()
Clones this object. |
java.util.ArrayList |
findNodes(ZFindFilter filter)
Return the list of nodes that are accepted by the specified filter in the portion of the scenegraph visible through this camera. |
protected ZLayerGroup |
getAncestorLayerFor(ZNode node)
Return the camera layer associated with this camera that is the ancestor of the supplied node. |
ZDrawingSurface |
getDrawingSurface()
Get the value of surface. |
java.awt.Color |
getFillColor()
Get the value of fillColor. |
java.awt.geom.AffineTransform |
getInverseViewTransform()
Returns a copy of the inverse view transform associated with this camera. |
java.awt.geom.AffineTransform |
getInverseViewTransformReference()
Returns a reference to the inverse view transform associated with this camera. |
ZLayerGroup[] |
getLayers()
Returns a copy of the list of layers that this camera looks onto. |
ZLayerGroup[] |
getLayersReference()
Returns a reference to the actual layers array of this camera. |
double |
getMagnification()
Returns the current magnification of this camera. |
void |
getMatrix(double[] matrix)
Returns the view transform matrix. |
int |
getNumLayers()
Returns the number of layers of this camera. |
ZRoot |
getRoot()
Returns the root of the scene graph that this camera is looking at. |
double |
getScale()
Returns the current scale of this transform. |
double |
getTranslateX()
Returns the current X translation of this object |
double |
getTranslateY()
Returns the current Y translation of this object |
java.awt.geom.Point2D |
getTranslation()
Returns the current translation of this object |
ZBounds |
getViewBounds()
Returns the bounds that this Camera sees in global scene coordinates. |
java.awt.geom.AffineTransform |
getViewTransform()
Returns a copy of the view transform that specifes where in space this camera looks. |
double |
localToCamera(java.awt.geom.Point2D pt,
ZNode node)
Transform a point in a node's local coordinate system up the scenegraph backwards through the camera to the camera's coordinate system. |
double |
localToCamera(java.awt.geom.Rectangle2D rect,
ZNode node)
Transform a rectangle in a node's local coordinate system up the scenegraph backwards through the camera to the camera's coordinate system. |
boolean |
pick(java.awt.geom.Rectangle2D rect,
ZSceneGraphPath path)
Picks the first object under the specified rectangle (if there is one) as searched in reverse (front-to-back) order. |
void |
removeCameraListener(ZCameraListener l)
Removes the specified camera listener so that it no longer receives camera events from this camera. |
void |
removeLayer(ZLayerGroup layer)
Removes a portion of the scenegrpah from what this camera sees |
void |
render(ZRenderContext renderContext)
Renders the view this camera sees. |
void |
repaint()
Repaint causes the portions of the surfaces that this object appears in to be marked as needing painting, and queues events to cause those areas to be painted. |
void |
repaint(ZBounds repaintBounds)
This is an internal form of repaint that is only intended to be used by calls from within Jazz. |
void |
repaint(ZSceneGraphObject obj,
java.awt.geom.AffineTransform at,
ZBounds clipBounds)
This is an internal form of repaint that is only intended to be used by calls from within Jazz. |
void |
replaceLayer(ZLayerGroup original,
ZLayerGroup replacement)
Replaces the specified node out of the list of layers of this camera, and replaces it with the specified node. |
void |
scale(double dz)
Scale the object from its current scale to the scale specified by muliplying the current scale and dz. |
void |
scale(double dz,
double x,
double y)
Scale the object around the specified point (x, y) from its current scale to the scale specified by muliplying the current scale and dz. |
void |
scale(double dz,
double x,
double y,
int millis,
ZDrawingSurface surface)
Animate the object around the specified point (x, y) from its current scale to the scale specified by muliplying the current scale and dz |
void |
scale(double dz,
int millis,
ZDrawingSurface surface)
Animate the object from its current scale to the scale specified by muliplying the current scale and deltaZ |
void |
setBounds(int x,
int y,
int w,
int h)
Sets the bounds of this camera. |
void |
setBounds(java.awt.geom.Rectangle2D newBounds)
Sets the bounds of this camera. |
void |
setDrawingSurface(ZDrawingSurface aSurface)
Set the value of surface. |
void |
setFillColor(java.awt.Color aColor)
Set the value of fillColor. |
static void |
setRenderContextFactory(ZRenderContextFactory factory)
Define how render contexts should be created. |
void |
setScale(double finalz)
Sets the scale of the view transform |
void |
setScale(double finalz,
double x,
double y)
Set the scale of the object to the specified target scale, scaling the object around the specified point (x, y). |
void |
setScale(double finalz,
double x,
double y,
int millis,
ZDrawingSurface surface)
Animate the object around the specified point (x, y) to the specified target scale. |
void |
setScale(double finalz,
int millis,
ZDrawingSurface surface)
Animate the object from its current scale to the specified target scale. |
void |
setState(java.lang.String fieldType,
java.lang.String fieldName,
java.lang.Object fieldValue)
Set some state of this object as it gets read back in. |
void |
setTransform(double m00,
double m10,
double m01,
double m11,
double m02,
double m12)
Sets the view transform via the matrix values. |
void |
setTranslateX(double x)
Sets the current X translation of this object |
void |
setTranslateY(double y)
Sets the current Y translation of this object |
void |
setTranslation(double x,
double y)
Translate the object to the specified position |
void |
setTranslation(double x,
double y,
int millis,
ZDrawingSurface surface)
Animate the object from its current position to the position specified by x, y |
void |
setViewTransform(java.awt.geom.AffineTransform transform)
Sets the view transform associated with this camera. |
void |
setViewTransform(double m00,
double m10,
double m01,
double m11,
double m02,
double m12)
Sets the view transform associated with this camera. |
void |
translate(double dx,
double dy)
Translate the object by the specified deltaX and deltaY |
void |
translate(double dx,
double dy,
int millis,
ZDrawingSurface surface)
Animate the object from its current position by the specified deltaX and deltaY |
void |
trimToSize()
Trims the capacity of the array that stores the layers list points to the actual number of points. |
protected void |
updateObjectReferences(ZObjectReferenceTable objRefTable)
Called to update internal object references after a clone operation by ZSceneGraphObject.clone() . |
void |
writeObject(ZObjectOutputStream out)
Write out all of this object's state. |
void |
writeObjectRecurse(ZObjectOutputStream out)
Specify which objects this object references in order to write out the scenegraph properly |
Methods inherited from class edu.umd.cs.jazz.ZVisualComponent |
addParent, getNumParents, getParents, getParentsReference, paint, pickBounds, removeParent, updateBounds, updateParentBounds, updateVolatility |
Methods inherited from class edu.umd.cs.jazz.ZSceneGraphObject |
addMouseListener, addMouseMotionListener, clone, computeBounds, fireEvent, fireMouseEvent, getBounds, getBoundsReference, getListenerList, getVolatileBounds, hasLisenerOfType, hasMouseListener, processMouseEvent, removeEventListener, removeMouseListener, removeMouseMotionListener, reshape, setBounds, setVolatileBounds |
Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final java.awt.Color fillColor_DEFAULT
Constructor Detail |
public ZCamera()
public ZCamera(ZLayerGroup layer, ZDrawingSurface aSurface)
node
- The part of the scenegraph this camera sees.surf
- The surface this top-level camera projects ontoMethod Detail |
protected java.lang.Object duplicateObject()
The cloned camera will continue to see the same layers in the original scenegraph (the layers that the camera looks at are not cloned).
The cloned camera will not be attached to any surface, and must be made visible by attaching to a new surface (or by being visible through another camera.)
duplicateObject
in class ZVisualComponent
ZSceneGraphObject.duplicateObject()
protected void updateObjectReferences(ZObjectReferenceTable objRefTable)
ZSceneGraphObject.clone()
.updateObjectReferences
in class ZVisualComponent
ZSceneGraphObject.updateObjectReferences(edu.umd.cs.jazz.util.ZObjectReferenceTable)
public static void setRenderContextFactory(ZRenderContextFactory factory)
factory
- The new factory to create render contexts with.createRenderContext(edu.umd.cs.jazz.ZCamera)
public ZRenderContext createRenderContext(ZCamera camera)
setRenderContextFactory(edu.umd.cs.jazz.util.ZRenderContextFactory)
public ZRenderContext createRenderContext(java.awt.Graphics2D aG2, ZBounds visibleBounds, ZDrawingSurface aSurface, int qualityRequested)
setRenderContextFactory(edu.umd.cs.jazz.util.ZRenderContextFactory)
public void trimToSize()
trimToSize
in class ZVisualComponent
public void addLayer(ZLayerGroup layer)
layer
- The part of the scenegraph added to what this camera sees.public void removeLayer(ZLayerGroup layer)
layer
- The part of the scenegraph removed from what this camera sees.public void replaceLayer(ZLayerGroup original, ZLayerGroup replacement)
original
- is the old node that is being swapped out as a layerreplacement
- is the new node that is being swapped in as a layerpublic ZLayerGroup[] getLayers()
public ZLayerGroup[] getLayersReference()
getNumLayers()
.
Warning: This method returns a reference to an internal array. Any modification of this array will result in undefined behavior.
public int getNumLayers()
public ZDrawingSurface getDrawingSurface()
public void setDrawingSurface(ZDrawingSurface aSurface)
v
- Value to assign to surface.public java.awt.Color getFillColor()
getFillColor
in interface ZFillColor
public void setFillColor(java.awt.Color aColor)
setFillColor
in interface ZFillColor
v
- Value to assign to fillColor.public ZBounds getViewBounds()
public void setBounds(int x, int y, int w, int h)
x,y,w,h
- The new bounds of this camerapublic void setBounds(java.awt.geom.Rectangle2D newBounds)
newBounds
- The new bounds of this camerapublic double getMagnification()
public void repaint()
ZSceneGraphObject
Scenegraph objects should call repaint when their internal state has changed and they need to be redrawn on the screen.
Important note : Scenegraph objects should call reshape() instead of repaint() if the internal state change effects the bounds of the shape in any way (e.g. changing penwidth, selection, transform, adding points to a line, etc.)
repaint
in class ZVisualComponent
edu.umd.cs.jazz.ZSceneGraphObject
ZSceneGraphObject.reshape()
public void repaint(ZBounds repaintBounds)
repaint
in class ZVisualComponent
repaintBounds
- The bounds that need to be repainted (in global coordinates)public void repaint(ZSceneGraphObject obj, java.awt.geom.AffineTransform at, ZBounds clipBounds)
obj
- The object to repaintat
- The affine transformclipBounds
- The bounds to clip to when repaintingpublic void render(ZRenderContext renderContext)
The transform, clip, and composite will be set appropriately when this object is rendered. It is up to this object to restore the transform, clip, and composite of the Graphics2D if this node changes any of them. However, the color, font, and stroke are unspecified by Jazz. This object should set those things if they are used, but they do not need to be restored.
render
in class ZVisualComponent
renderContext
- The graphics context to use for rendering.public ZRoot getRoot()
getRoot
in class ZVisualComponent
public boolean pick(java.awt.geom.Rectangle2D rect, ZSceneGraphPath path)
pick
in class ZVisualComponent
rect
- Coordinates of pick rectangle in camera coordinates.path
- The path through the scenegraph to the picked node. Modified by this call.ZDrawingSurface.pick(int, int)
public java.util.ArrayList findNodes(ZFindFilter filter)
filter
- The filter that decides whether or not to include individual nodes in the find listZNode.isFindable()
,
ZFindFilter
public java.lang.String dump()
dump
in class ZSceneGraphObject
ZDebug.dump(edu.umd.cs.jazz.ZNode)
public void addCameraListener(ZCameraListener l)
l
- the camera listenerpublic void removeCameraListener(ZCameraListener l)
l
- the camera listenerpublic void getMatrix(double[] matrix)
getMatrix
in interface ZTransformable
matrix
- The matrix which needs to be setpublic void setTransform(double m00, double m10, double m01, double m11, double m02, double m12)
setTransform
in interface ZTransformable
m00
- The 00 element of the matrixm10
- The 10 element of the matrixm01
- The 01 element of the matrixm11
- The 11 element of the matrixm02
- The 02 element of the matrixm12
- The 12 element of the matrixpublic java.awt.geom.AffineTransform getViewTransform()
protected void computeInverseViewTransform()
public java.awt.geom.AffineTransform getInverseViewTransform()
public java.awt.geom.AffineTransform getInverseViewTransformReference()
public void setViewTransform(java.awt.geom.AffineTransform transform)
transform
- the new transform.public void setViewTransform(double m00, double m10, double m01, double m11, double m02, double m12)
m00, m01, m02, m10, m11, m12
- the
6 values that compose the 3x3 transformation matrixpublic double cameraToLocal(java.awt.geom.Point2D pt, ZNode node)
If the node is specified as null, then the point is transformed through the camera, but no further - thus transforming the point from window to global coordinates.
If the specified node is not on the portion of the scenegraph that is visible through the camera, then a ZNodeNotFoundException is thrown.
pt
- The point to be transformednode
- The node to transform toZNodeNotFoundException
- if the node is not in the subtree of the scenegraph
under one of the camera's layers.localToCamera(Point2D, ZNode)
public double cameraToLocal(java.awt.geom.Rectangle2D rect, ZNode node)
If the node is specified as null, then the rectangle is transformed through the camera, but no further - thus transforming the rectangle from window to global coordinates.
If the specified node is not on the portion of the scenegraph that is visible through the camera, then a ZNodeNotFoundException is thrown.
rect
- The rectangle to be transformednode
- The node to transform toZNodeNotFoundException
- if the node is not in the subtree of the scenegraph
under one of the camera's layers.localToCamera(Rectangle2D, ZNode)
public double localToCamera(java.awt.geom.Point2D pt, ZNode node)
If the node is specified as null, then the point is transformed from global coordinates through the camera, thus transforming the point from global to window coordinates.
If the specified node is not on the portion of the scenegraph that is visible through the camera, then a ZNodeNotFoundException is thrown.
pt
- The point to be transformednode
- The node that represents the local coordinates to transform fromZNodeNotFoundException
- if the node is not in the subtree of the scenegraph
under one of the camera's layers.cameraToLocal(Point2D, ZNode)
public double localToCamera(java.awt.geom.Rectangle2D rect, ZNode node)
If the node is specified as null, then the rectangle is transformed from global coordinates through the camera, thus transforming the rectangle from global to window coordinates.
If the specified node is not on the portion of the scenegraph that is visible through the camera, then a ZNodeNotFoundException is thrown.
rect
- The rectangle to be transformednode
- The node that represents the local coordinates to transform fromZNodeNotFoundException
- if the node is not in the subtree of the scenegraph
under one of the camera's layers.cameraToLocal(Rectangle2D, ZNode)
public void center(java.awt.geom.Rectangle2D refBounds, int millis, ZDrawingSurface aSurface)
refBounds
- The bounds (in global coordinates) to be centered.millis
- The time in milliseconds to perform the animationsurface
- The surface to be updated during the animationpublic void center(java.awt.geom.Rectangle2D srcBounds, java.awt.geom.Rectangle2D destBounds, int millis, ZDrawingSurface surface)
millis
- Number of milliseconds over which to perform the animation.surface
- The surface to be updated during animation.srcBounds
- A bounds in global coordinates.destBounds
- Bounds of the region in camera coordinates that bounds
should apperar in.public void centerWithAspectChange(java.awt.geom.Rectangle2D srcBounds, java.awt.geom.Rectangle2D destBounds, int millis, ZDrawingSurface surface)
millis
- Number of milliseconds over which to perform the animation.surface
- The surface to be updated during animation.srcBounds
- A bounds in global coordinates.destBounds
- Bounds of the region in camera coordinates that bounds
should apperar in.public void centerWithAspectChange(java.awt.geom.Rectangle2D refBounds, int millis, ZDrawingSurface aSurface)
millis
- Number of milliseconds over which to perform the animation.surface
- The surface to be updated during animation.refBounds
- A bounds in global coordinates.public java.awt.geom.Point2D getTranslation()
public double getTranslateX()
public void setTranslateX(double x)
public double getTranslateY()
public void setTranslateY(double y)
public void translate(double dx, double dy)
dx
- X-coord of translationdy
- Y-coord of translationpublic void translate(double dx, double dy, int millis, ZDrawingSurface surface)
dx
- X-coord of translationdy
- Y-coord of translationmillis
- Number of milliseconds over which to perform the animationsurface
- The surface to updated during animation.public void setTranslation(double x, double y)
x
- X-coord of translationy
- Y-coord of translationpublic void setTranslation(double x, double y, int millis, ZDrawingSurface surface)
x
- X-coord of translationy
- Y-coord of translationmillis
- Number of milliseconds over which to perform the animationsurface
- The surface to updated during animation.public double getScale()
public void scale(double dz)
dz
- scale factorpublic void scale(double dz, double x, double y)
dz
- scale factorx
- X coordinate of the point to scale aroundy
- Y coordinate of the point to scale aroundpublic void scale(double dz, int millis, ZDrawingSurface surface)
dz
- scale factormillis
- Number of milliseconds over which to perform the animationsurface
- The surface to updated during animation.public void scale(double dz, double x, double y, int millis, ZDrawingSurface surface)
dz
- scale factorx
- X coordinate of the point to scale aroundy
- Y coordinate of the point to scale aroundmillis
- Number of milliseconds over which to perform the animationsurface
- The surface to updated during animation.public void setScale(double finalz)
the
- new scalepublic void setScale(double finalz, double x, double y)
finalz
- scale factorx
- X coordinate of the point to scale aroundy
- Y coordinate of the point to scale aroundpublic void setScale(double finalz, int millis, ZDrawingSurface surface)
finalz
- scale factormillis
- Number of milliseconds over which to perform the animationsurface
- The surface to updated during animation.public void setScale(double finalz, double x, double y, int millis, ZDrawingSurface surface)
finalz
- scale factorx
- X coordinate of the point to scale aroundy
- Y coordinate of the point to scale aroundmillis
- Number of milliseconds over which to perform the animationsurface
- The surface to updated during animation.public void animate(java.awt.geom.AffineTransform at, int millis, ZDrawingSurface surface)
If millis is 0, then the transform is updated once, and the scene is not repainted immediately, but rather a repaint request is queued, and will be processed by an event handler.
at
- Final transformationmillis
- Number of milliseconds over which to perform the animationsurface
- The surface to updated during animation.public void writeObject(ZObjectOutputStream out) throws java.io.IOException
writeObject
in class ZVisualComponent
out
- The stream that this object writes intopublic void writeObjectRecurse(ZObjectOutputStream out) throws java.io.IOException
writeObjectRecurse
in class ZVisualComponent
out
- The stream that this object writes intopublic void setState(java.lang.String fieldType, java.lang.String fieldName, java.lang.Object fieldValue)
setState
in class ZVisualComponent
fieldType
- The fully qualified type of the fieldfieldName
- The name of the fieldfieldValue
- The value of the fieldprotected ZLayerGroup getAncestorLayerFor(ZNode node)
node
- The node whos layer ancestor is needed.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |