org.j3d.geom.overlay
Class TextureOverlay
- public class TextureOverlay
- implements org.j3d.geom.overlay.Overlay, java.awt.event.ComponentListener
- An overlay implementation that uses a Java3D javax.media.j3d.Texture2D object for the renderable surface.
This is different to other overlays in this package in that it assumes another part of the application has created the pre-canned texture instance to use rather than internally generating it.
Note:
Textures, by default, don't look too good if you just give it the straight image. In order to have pixel-perfect textures, you should also have the following setup prior to passing the textures to this class:
texture.setMagFilter(Texture.NICEST);
texture.setMinFilter(Texture.FASTEST);
- Version:
- $Revision: 1.7 $
- Author:
- Justin Couch
CONSOLE_Z
private static final double CONSOLE_Z
- I do not undersand what this is for
TEXTURE_COORDS
private static final float[] TEXTURE_COORDS
- Common texture coordinates used for all overlay instances
DIRTY_VISIBLE
protected static final int DIRTY_VISIBLE
- Mark the visible flag as dirty
DIRTY_POSITION
protected static final int DIRTY_POSITION
- Mark the position as dirty and needing correction
DIRTY_ACTIVE_BUFFER
protected static final int DIRTY_ACTIVE_BUFFER
- Mark the active buffer as dirty and needing swapping
DIRTY_SIZE
protected static final int DIRTY_SIZE
- Mark the size as dirty and needing correction
backgroundMode
private int backgroundMode
- The current background mode. Defaults to copy
visible
private boolean visible
- Flag holding the visibility state of this overlay
antialiased
private boolean antialiased
- Flag for the anti-aliased state
overlayBounds
private java.awt.Rectangle overlayBounds
- Canvas bounds occupied by this overlay.
componentSize
private java.awt.Dimension componentSize
- The bounds of the Canvas3D this overlay is rendered in
fieldOfView
private double fieldOfView
- The field of view for the canvas
updateManager
private org.j3d.geom.overlay.UpdateManager updateManager
- The update manager for keeping us in sync
canvas3D
private javax.media.j3d.Canvas3D canvas3D
- Canvas we are displayed on
consoleBG
protected javax.media.j3d.BranchGroup consoleBG
- Root branchgroup for the entire overlay system
consoleTG
private javax.media.j3d.TransformGroup consoleTG
- Transformation to make the raster become screen coords as well
appearance
private javax.media.j3d.Appearance appearance
- Appearance used by the overlay so that we can change the textures
geometry
private javax.media.j3d.QuadArray geometry
- The geometry of the object to allow resetting
renderAttributes
private javax.media.j3d.RenderingAttributes renderAttributes
- Rendering attributes to allow the visibility state to change
transAttr
private javax.media.j3d.TransparencyAttributes transAttr
- Transparency attributes to allow the mode state to change
transMode
private int transMode
- The current transparency mode mode in use
fixedSize
private boolean fixedSize
- Flag indicating whether this is a fixed size or resizable overlay. Fixed size is when the user gives us bounds. Resizable when they don't and we track the canvas.
painting
private boolean painting
- Used to avoid calls to repaint backing up
initComplete
private boolean initComplete
- Flag to say whether initialisation has been completed yet
dirtyCheck
private boolean[] dirtyCheck
- List of the dirty flag settings
TextureOverlay
public TextureOverlay(javax.media.j3d.Canvas3D canvas,
java.awt.Dimension size)
- Constructs an overlay window. This window will not be visible unless it is added to the scene under the view platform transform If the bounds are null, then resize the overlay to fit the canvas and then track the size of the canvas.
- Parameters:
canvas
- The canvas the overlay is drawn on
size
- The size of the overlay in pixels
- Throws:
IllegalArgumentException
- Both the canvas and bounds are null
TextureOverlay
public TextureOverlay(javax.media.j3d.Canvas3D canvas,
java.awt.Dimension size,
javax.media.j3d.Texture2D texture)
- Constructs an overlay window. This window will not be visible unless it is added to the scene under the view platform transform If the bounds are null, then resize the overlay to fit the canvas and then track the size of the canvas.
- Parameters:
canvas
- The canvas the overlay is drawn on
size
- The size of the overlay in pixels
The
- texture to be displayed. May be null
- Throws:
IllegalArgumentException
- Both the canvas and bounds are null
TextureOverlay
public TextureOverlay(javax.media.j3d.Canvas3D canvas,
java.awt.Dimension size,
boolean hasAlpha,
org.j3d.geom.overlay.UpdateManager updateManager,
javax.media.j3d.Texture2D texture)
- Constructs an overlay window. This window will not be visible unless it is added to the scene under the view platform transform If the bounds are null, then resize the overlay to fit the canvas and then track the size of the canvas.
- Parameters:
canvas
- The canvas the overlay is drawn on
size
- The size of the overlay in pixels
hasAlpha
- True if the texture has an alpha component
updateManager
- Responsible for allowing the Overlay to update between renders. If this is null a default manager is created
The
- texture to be displayed. May be null
- Throws:
IllegalArgumentException
- Both the canvas and bounds are null
initialize
public void initialize()
- Post construction initialisation before turning the overlay live. Should always be called by the end user before starting to make use of this overlay instance.
getRoot
public javax.media.j3d.BranchGroup getRoot()
- Return the root of the Overlay so it can be added to the scene graph. This should be added to the view transform group of the parent application. A branch group representing the overlay
getBounds
public java.awt.Rectangle getBounds()
- Returns the rectangular portion of the canvas that this overlay covers.
- Returns:
- A rectangle representing the bounds
contains
public boolean contains(java.awt.Point p)
- Check to see if the point passed in is contained within the bounds of the overlay.
- Parameters:
p
- The point to check if it is contained
- Returns:
- true if the point is contained within the bounds of this overlay
getUpdateManager
public org.j3d.geom.overlay.UpdateManager getUpdateManager()
- Returns the UpdateManager responsible for seeing that updates to the Overlay only take place between frames.
- Parameters:
The
- update manage instance for this overlay
setUpdateManager
public void setUpdateManager(org.j3d.geom.overlay.UpdateManager mgr)
- Set the UpdateManager to the new value. If the reference is null, it will clear the current manager.
- Parameters:
mgr
- A reference to the new manage instance to use
setLocation
public void setLocation(int x,
int y)
- Sets the location of the top-left corner of the overlay. It will move the overlay to that position on the next update cycle.
- Parameters:
x
- The x coordinate of the location
y
- The y coordinate of the location
setSize
public void setSize(int w,
int h)
- Change the size of the texture to the new size. The new size will be in pixels and must be valid >= 0.
- Parameters:
w
- The new width of the overlay
h
- The new height of the overlay
setAntialiased
public void setAntialiased(boolean state)
- Sets whether drawing onto this Overlay is anialiased. If called after the overlay has gone live, it will have no effect.
- Parameters:
state
- true if this overlay should antialias the lines
isAntialiased
public boolean isAntialiased()
- Returns whether drawing on this overlay is anti-aliased.
- Returns:
- true if the overlay is antialiased
setVisible
public void setVisible(boolean visible)
- Changes the visibility of the Overlay.
- Parameters:
visible
- true to make the overlay visible
isVisible
public boolean isVisible()
- Returns the visiblity of the Overlay.
- Returns:
- true if the overlay is currently visible
setComponentDetails
public void setComponentDetails(java.awt.Dimension size,
double fov)
- Update the canvas component details of size and field of view settings. This is mainly called when the overlay is part of a larger management system and it needs to inform the overlay of new screen information.
- Parameters:
size
- The new dimensions of the component
fov
- The new field of view for the current view
update
public void update()
- Notification from the update manager that something has changed and we should fix up the appropriate bits.
componentResized
public void componentResized(java.awt.event.ComponentEvent e)
- Notification that the component has been resized.
- Parameters:
e
- The event that caused this method to be called
componentMoved
public void componentMoved(java.awt.event.ComponentEvent e)
- Notification that the component has been moved.
- Parameters:
e
- The event that caused this method to be called
componentShown
public void componentShown(java.awt.event.ComponentEvent e)
- Notification that the component has been shown. This is the component being shown, not the window that it is contained in.
- Parameters:
e
- The event that caused this method to be called
componentHidden
public void componentHidden(java.awt.event.ComponentEvent e)
- Notification that the component has been hidden.
- Parameters:
e
- The event that caused this method to be called
setTexture
public void setTexture(javax.media.j3d.Texture2D tex)
- Change the texture to the new version. If the constructor set a bounds then the texture will be sized to fit that. If no bounds were set then the object will be resized to fit the texture's new size. Note that if you are calling this method when the scene graph is live, you must have ALLOW_FORMAT_READ capability set.
- Parameters:
tex
- The new texture object to use
dirty
private void dirty(int property)
- Mark a specific property as being dirty and needing to be rechecked.
- Parameters:
property
- The index of the property to be updated
syncVisible
private void syncVisible()
- Update the visibility state to either turn on or off the overlay.
syncPosition
private void syncPosition()
- Update the position of the overlay in the overall window. Note that it does not change the size of the overlay, just re-adjusts the transforms in the scene graph so that the overlay maintains the correct position relative the canvas.
syncSize
private void syncSize()
- Fixup the size of the overlay textures. Resizes and clears the texture to fit the new size. Current implementation is really dumb - just tosses everything and starts again. A more intelligent one would only replace the border parts.