|
j3d.org Code | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectorg.j3d.renderer.java3d.overlay.OverlayBase
An implementation of the overlay and screen component interfaces to provide a ready-made overlay system.
The implementation uses textured objects that are mapped to screen space coordinates. This can be both good and bad. The overlay can operate in one of two modes - fixed size, dynamic size according to the canvas.
Fixed Size Overlays
The size should be set to a value that is a power of two for the best performance. The code divides the supplied area into smaller sections, with a maximum size of 256 pixels in either direction. Left over pieces are then subdivided into lots that are power of two. The minimum size of one of these pieces is 16 pixels. If you have an odd size, sich as 55 pixels, then you get weird artifacts appearing on screen.
A fixed size overlay may operate without being given a canvas to work with. This would be used when you are using an overlay manager to work with the overlay instance.
Resizable Overlays
A resizable overlay is created when the bounds are set to null in the constructor. In this case the overlay then listens for resizing information from the component and resizes the internal subsections to accomodate this. For this system, in order to remain visually accurate, we subdivide down to shapes that are 1 pixel across. Obviously this impacts performance quite dramatically to have so many tiny objects.
The class implements the AWT component listener interface so that it can automatically resize the overlay's base image in response to the canvas changing size. This will ensure that everything is correctly located on the screen after the resize.
| Field Summary | |
protected int |
activeBuffer
The currently active buffer index |
protected java.awt.Color |
backgroundColor
Background colour of the overlay |
protected int |
backgroundMode
The current background mode. |
protected int |
bottomInset
Inset (border spacing) for the bottom edge |
protected java.awt.image.BufferedImage |
canvas
Drawing area that we scribble our stuff on |
protected java.awt.Dimension |
componentSize
The bounds of the Canvas3D this overlay is rendered in |
protected javax.media.j3d.BranchGroup |
consoleBG
Root branchgroup for the entire overlay system |
protected javax.media.j3d.TransformGroup |
consoleTG
Transformation to make the raster become screen coords as well |
protected static int |
DEFAULT_INSET
Default amount of inset that this overlay uses |
protected static int |
DIRTY_ACTIVE_BUFFER
Mark the active buffer as dirty and needing swapping |
protected static int |
DIRTY_POSITION
Mark the position as dirty and needing correction |
protected static int |
DIRTY_SIZE
Mark the size as dirty and needing correction |
protected static int |
DIRTY_VISIBLE
Mark the visible flag as dirty |
protected double |
fieldOfView
The field of view for the canvas |
protected boolean |
fixedSize
Flag indicating whether this is a fixed size or resizable overlay. |
protected int |
leftInset
Inset (border spacing) for the left edge |
protected java.awt.Rectangle |
overlayBounds
Canvas bounds occupied by this overlay. |
protected javax.media.j3d.BranchGroup |
overlayTexGrp
Contains the texture objects from the suboverlays. |
protected int |
rightInset
Inset (border spacing) for the right edge |
protected org.j3d.renderer.java3d.overlay.SubOverlay[] |
subOverlay
The list of sub-overlay areas. |
protected int |
topInset
Inset (border spacing) for the top edge |
| Fields inherited from interface org.j3d.renderer.java3d.overlay.Overlay |
BACKGROUND_COPY, BACKGROUND_NONE |
| Constructor Summary | |
protected |
OverlayBase(javax.media.j3d.Canvas3D canvas,
java.awt.Dimension size)
Creates a new overlay covering the given canvas bounds. |
protected |
OverlayBase(javax.media.j3d.Canvas3D canvas,
java.awt.Dimension size,
boolean clipAlpha,
boolean blendAlpha)
Constructs an overlay window that can have alpha capabilities. |
protected |
OverlayBase(javax.media.j3d.Canvas3D canvas,
java.awt.Dimension size,
boolean clipAlpha,
boolean blendAlpha,
UpdateManager updateManager)
Constructs an overlay window. |
protected |
OverlayBase(javax.media.j3d.Canvas3D canvas,
java.awt.Dimension size,
boolean clipAlpha,
boolean blendAlpha,
UpdateManager updateManager,
int numBuffers)
Constructs an overlay window. |
protected |
OverlayBase(javax.media.j3d.Canvas3D canvas,
java.awt.Dimension size,
UpdateManager manager)
Constructs an overlay window with an update manager. |
| Method Summary | |
void |
componentHidden(java.awt.event.ComponentEvent e)
Notification that the component has been hidden. |
void |
componentMoved(java.awt.event.ComponentEvent e)
Notification that the component has been moved. |
void |
componentResized(java.awt.event.ComponentEvent e)
Notification that the component has been resized. |
void |
componentShown(java.awt.event.ComponentEvent e)
Notification that the component has been shown. |
boolean |
contains(java.awt.Point p)
Check to see if the point passed in is contained within the bounds of the overlay. |
protected void |
dirty(int property)
Mark a specific property as being dirty and needing to be rechecked. |
java.awt.image.BufferedImage |
getBackgroundImage()
Returns the background for the overlay. |
java.awt.Rectangle |
getBounds()
Get the bounds of the visible object in screen space coordinates. |
protected java.awt.Graphics2D |
getGraphics()
Prepares the canvas to be painted. |
javax.media.j3d.BranchGroup |
getRoot()
Return the root of the overlay and its sub-overlays so it can be added to the scene graph. |
UpdateManager |
getUpdateManager()
Returns the UpdateManager responsible for seeing that updates to the Overlay only take place between frames. |
void |
initialize()
Empty method that can be used to provide post construction initialisation. |
boolean |
isAntialiased()
Check to see whether this overlay is currently antialiased. |
boolean |
isVisible()
Returns the visiblity of the Overlay. |
void |
paint(java.awt.Graphics2D g)
This is where the actualy drawing of the window takes place. |
void |
repaint()
This is called to trigger a repaint of the overlay. |
protected void |
setActiveBuffer(int bufferIndex)
Set the active buffer to the new index. |
void |
setAntialiased(boolean antialiased)
Sets whether drawing onto this Overlay is anialiased. |
void |
setBackgroundColor(java.awt.Color color)
Sets the background to a solid color. |
void |
setBackgroundImage(java.awt.image.BufferedImage img)
Sets the background image to the one specified. |
void |
setBackgroundMode(int mode)
Sets the background mode. |
void |
setComponentDetails(java.awt.Dimension size,
double fov)
Update the canvas component details of size and field of view settings. |
void |
setInsets(java.awt.Insets insets)
Set the insets for this overlay. |
void |
setInsets(int left,
int top,
int right,
int bottom)
Set the insets for this overlay. |
void |
setLocation(int x,
int y)
Sets the location of the top-left corner of the overlay. |
void |
setSize(int w,
int h)
Change the size of the texture to the new size. |
void |
setUpdateManager(UpdateManager mgr)
Set the UpdateManager to the new value. |
void |
setVisible(boolean visible)
Changes the visibility of the overlay. |
void |
update()
Notification from the update manager that something has changed and we should fix up the appropriate bits. |
protected void |
updateBuffer(java.awt.image.BufferedImage image,
int bufferIndex)
Force an update of the nominated buffer with the contents of the given image. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
protected static final int DIRTY_VISIBLE
protected static final int DIRTY_POSITION
protected static final int DIRTY_ACTIVE_BUFFER
protected static final int DIRTY_SIZE
protected static final int DEFAULT_INSET
protected int leftInset
protected int rightInset
protected int topInset
protected int bottomInset
protected int backgroundMode
protected java.awt.Rectangle overlayBounds
protected java.awt.Dimension componentSize
protected double fieldOfView
protected java.awt.image.BufferedImage canvas
protected java.awt.Color backgroundColor
protected org.j3d.renderer.java3d.overlay.SubOverlay[] subOverlay
protected int activeBuffer
protected javax.media.j3d.BranchGroup consoleBG
protected javax.media.j3d.BranchGroup overlayTexGrp
protected javax.media.j3d.TransformGroup consoleTG
protected final boolean fixedSize
| Constructor Detail |
protected OverlayBase(javax.media.j3d.Canvas3D canvas,
java.awt.Dimension size)
canvas - Canvas being drawn ontosize - The size of the overlay in pixels
java.lang.IllegalArgumentException - Both the canvas and bounds are null
protected OverlayBase(javax.media.j3d.Canvas3D canvas,
java.awt.Dimension size,
UpdateManager manager)
canvas - The canvas the overlay is drawn onsize - The size of the overlay in pixels
java.lang.IllegalArgumentException - Both the canvas and bounds are null
protected OverlayBase(javax.media.j3d.Canvas3D canvas,
java.awt.Dimension size,
boolean clipAlpha,
boolean blendAlpha)
canvas - The canvas the overlay is drawn onsize - The size of the overlay in pixelsclipAlpha - Should the polygon clip where alpha is zeroblendAlpha - Should we blend to background where alpha is < 1
java.lang.IllegalArgumentException - Both the canvas and bounds are null
protected OverlayBase(javax.media.j3d.Canvas3D canvas,
java.awt.Dimension size,
boolean clipAlpha,
boolean blendAlpha,
UpdateManager updateManager)
canvas - The canvas the overlay is drawn onsize - The size of the overlay in pixelsclipAlpha - Should the polygon clip where alpha is zeroblendAlpha - Should we blend to background where alpha is < 1updateManager - Responsible for allowing the Overlay to update
between renders. If this is null a default manager is created
java.lang.IllegalArgumentException - Both the canvas and bounds are null
protected OverlayBase(javax.media.j3d.Canvas3D canvas,
java.awt.Dimension size,
boolean clipAlpha,
boolean blendAlpha,
UpdateManager updateManager,
int numBuffers)
canvas - The canvas the overlay is drawn onsize - The size of the overlay in pixelsclipAlpha - Should the polygon clip where alpha is zeroblendAlpha - Should we blend to background where alpha is < 1updateManager - Responsible for allowing the Overlay to update
between renders. If this is null a default manager is creatednumBuffers - The number of buffers to generate, the default is two| Method Detail |
public void initialize()
initialize in interface Overlay
public void setComponentDetails(java.awt.Dimension size,
double fov)
setComponentDetails in interface Overlaysize - The new dimensions of the componentfov - The new field of view for the current view
public void setLocation(int x,
int y)
setLocation in interface Overlayx - The x coordinate of the locationy - The y coordinate of the location
public void setSize(int w,
int h)
setSize in interface Overlayw - The new width of the overlayh - The new height of the overlaypublic void setInsets(java.awt.Insets insets)
insets - The new set of values to use for insets
public void setInsets(int left,
int top,
int right,
int bottom)
public javax.media.j3d.BranchGroup getRoot()
getRoot in interface Overlaypublic void setAntialiased(boolean antialiased)
setAntialiased in interface Overlayantialiased - The new setting for anti-aliasing.public boolean isAntialiased()
isAntialiased in interface Overlaypublic void setVisible(boolean visible)
setVisible in interface Overlayvisible - The new visibility statepublic boolean isVisible()
isVisible in interface Overlaypublic void setBackgroundMode(int mode)
mode - The new mode to use for the backgroundpublic UpdateManager getUpdateManager()
getUpdateManager in interface Overlaypublic void setUpdateManager(UpdateManager mgr)
setUpdateManager in interface Overlaymgr - A reference to the new manage instance to usepublic void update()
update in interface UpdatableEntitypublic java.awt.Rectangle getBounds()
getBounds in interface Overlaypublic boolean contains(java.awt.Point p)
contains in interface Overlayp - The point to check if it is contained
public void componentResized(java.awt.event.ComponentEvent e)
componentResized in interface java.awt.event.ComponentListenere - The event that caused this method to be calledpublic void componentMoved(java.awt.event.ComponentEvent e)
componentMoved in interface java.awt.event.ComponentListenere - The event that caused this method to be calledpublic void componentShown(java.awt.event.ComponentEvent e)
componentShown in interface java.awt.event.ComponentListenere - The event that caused this method to be calledpublic void componentHidden(java.awt.event.ComponentEvent e)
componentHidden in interface java.awt.event.ComponentListenere - The event that caused this method to be calledpublic void setBackgroundColor(java.awt.Color color)
color - The new color to usepublic java.awt.image.BufferedImage getBackgroundImage()
public void setBackgroundImage(java.awt.image.BufferedImage img)
protected void dirty(int property)
property - The index of the property to be updatedprotected void setActiveBuffer(int bufferIndex)
bufferIndex - The index of the buffer to useprotected java.awt.Graphics2D getGraphics()
public void paint(java.awt.Graphics2D g)
g - The graphics context to paint withpublic void repaint()
protected void updateBuffer(java.awt.image.BufferedImage image,
int bufferIndex)
image - The contents to display as the imagebufferIndex - The buffer to update
|
j3d.org Code | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||