j3d.org Code

org.j3d.renderer.java3d.overlay
Class TextureOverlay

java.lang.Object
  extended byorg.j3d.renderer.java3d.overlay.TextureOverlay
All Implemented Interfaces:
java.awt.event.ComponentListener, java.util.EventListener, Overlay, UpdatableEntity
Direct Known Subclasses:
InteractiveTextureOverlay

public class TextureOverlay
extends java.lang.Object
implements Overlay, java.awt.event.ComponentListener

An overlay implementation that uses a Java3D 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.2 $
Author:
Justin Couch

Field Summary
protected  javax.media.j3d.BranchGroup consoleBG
          Root branchgroup for the entire overlay system
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
 
Fields inherited from interface org.j3d.renderer.java3d.overlay.Overlay
BACKGROUND_COPY, BACKGROUND_NONE
 
Constructor Summary
TextureOverlay(javax.media.j3d.Canvas3D canvas, java.awt.Dimension size)
          Constructs an overlay window.
TextureOverlay(javax.media.j3d.Canvas3D canvas, java.awt.Dimension size, boolean hasAlpha, UpdateManager updateManager, javax.media.j3d.Texture2D texture)
          Constructs an overlay window.
TextureOverlay(javax.media.j3d.Canvas3D canvas, java.awt.Dimension size, javax.media.j3d.Texture2D texture)
          Constructs an overlay window.
 
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.
 java.awt.Rectangle getBounds()
          Returns the rectangular portion of the canvas that this overlay covers.
 javax.media.j3d.BranchGroup getRoot()
          Return the root of the Overlay 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()
          Post construction initialisation before turning the overlay live.
 boolean isAntialiased()
          Returns whether drawing on this overlay is anti-aliased.
 boolean isVisible()
          Returns the visiblity of the Overlay.
 void setAntialiased(boolean state)
          Sets whether drawing onto this Overlay is anialiased.
 void setComponentDetails(java.awt.Dimension size, double fov)
          Update the canvas component details of size and field of view settings.
 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 setTexture(javax.media.j3d.Texture2D tex)
          Change the texture to the new version.
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DIRTY_VISIBLE

protected static final int DIRTY_VISIBLE
Mark the visible flag as dirty

See Also:
Constant Field Values

DIRTY_POSITION

protected static final int DIRTY_POSITION
Mark the position as dirty and needing correction

See Also:
Constant Field Values

DIRTY_ACTIVE_BUFFER

protected static final int DIRTY_ACTIVE_BUFFER
Mark the active buffer as dirty and needing swapping

See Also:
Constant Field Values

DIRTY_SIZE

protected static final int DIRTY_SIZE
Mark the size as dirty and needing correction

See Also:
Constant Field Values

consoleBG

protected javax.media.j3d.BranchGroup consoleBG
Root branchgroup for the entire overlay system

Constructor Detail

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:
java.lang.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
Throws:
java.lang.IllegalArgumentException - Both the canvas and bounds are null

TextureOverlay

public TextureOverlay(javax.media.j3d.Canvas3D canvas,
                      java.awt.Dimension size,
                      boolean hasAlpha,
                      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
Throws:
java.lang.IllegalArgumentException - Both the canvas and bounds are null
Method Detail

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.

Specified by:
initialize in interface Overlay

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

Specified by:
getRoot in interface Overlay

getBounds

public java.awt.Rectangle getBounds()
Returns the rectangular portion of the canvas that this overlay covers.

Specified by:
getBounds in interface Overlay
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.

Specified by:
contains in interface 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 UpdateManager getUpdateManager()
Returns the UpdateManager responsible for seeing that updates to the Overlay only take place between frames.

Specified by:
getUpdateManager in interface Overlay

setUpdateManager

public void setUpdateManager(UpdateManager mgr)
Set the UpdateManager to the new value. If the reference is null, it will clear the current manager.

Specified by:
setUpdateManager in interface Overlay
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.

Specified by:
setLocation in interface Overlay
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.

Specified by:
setSize in interface Overlay
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.

Specified by:
setAntialiased in interface Overlay
Parameters:
state - true if this overlay should antialias the lines

isAntialiased

public boolean isAntialiased()
Returns whether drawing on this overlay is anti-aliased.

Specified by:
isAntialiased in interface Overlay
Returns:
true if the overlay is antialiased

setVisible

public void setVisible(boolean visible)
Changes the visibility of the Overlay.

Specified by:
setVisible in interface Overlay
Parameters:
visible - true to make the overlay visible

isVisible

public boolean isVisible()
Returns the visiblity of the Overlay.

Specified by:
isVisible in interface 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.

Specified by:
setComponentDetails in interface Overlay
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.

Specified by:
update in interface UpdatableEntity

componentResized

public void componentResized(java.awt.event.ComponentEvent e)
Notification that the component has been resized.

Specified by:
componentResized in interface java.awt.event.ComponentListener
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.

Specified by:
componentMoved in interface java.awt.event.ComponentListener
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.

Specified by:
componentShown in interface java.awt.event.ComponentListener
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.

Specified by:
componentHidden in interface java.awt.event.ComponentListener
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

j3d.org Code

Latest Info from http://code.j3d.org/
Copyright © 2001 - j3d.org