Aviatrix3D
2.1.0

org.j3d.aviatrix3d
Class SphereBackground

java.lang.Object
  extended by org.j3d.aviatrix3d.SceneGraphObject
      extended by org.j3d.aviatrix3d.Node
          extended by org.j3d.aviatrix3d.Leaf
              extended by org.j3d.aviatrix3d.Background
                  extended by org.j3d.aviatrix3d.SphereBackground
All Implemented Interfaces:
java.lang.Comparable, BackgroundRenderable, Cullable, DeletableRenderable, EnvironmentCullable, ObjectRenderable, Renderable

public class SphereBackground
extends Background
implements DeletableRenderable

Background node that renders a single user-provided texture on a sphere.

The background geometry is created internally to be a sphere. The user's texture is applied to the sphere such that the seam is located in the direction of the +Z axis (ie behind the viewer from the default view direction along the -Z axis). The top of the texture image is located at the +Y direction. If the texture contains some transparent section(s) then the clear colour can be used as well.

Note that this will take any 2D texture component as the source. However, if that image defines mipmapping, the background ignores it. Only the first (primary) image is used to render the texture.

This will set the background colour to a single colour for the entire viewport. If used, this will override the setClearColor() on GraphicsOutputDevice.

Version:
$Revision: 1.13 $
Author:
Justin Couch

Field Summary
protected  int height
          The height of the main texture.
protected  boolean stateChanged
          Flag to say that the display lists must be cleared and regenerated because some state changed
protected  java.util.HashMap<javax.media.opengl.GL,java.lang.Integer> textureIdMap
          The mapping of GL context to OpenGL texture ID
protected  int width
          The width of the main texture.
 
Fields inherited from class org.j3d.aviatrix3d.Background
color, dispListMap, INVALID_ALPHA_PROP, INVALID_BLUE_PROP, INVALID_GREEN_PROP, INVALID_RED_PROP, useClearColor
 
Fields inherited from class org.j3d.aviatrix3d.Node
bounds, implicitBounds, INVALID_BOUNDS, parent
 
Fields inherited from class org.j3d.aviatrix3d.SceneGraphObject
alive, LISTENER_SET_TIMING_ERR_PROP, updateHandler
 
Constructor Summary
SphereBackground()
          Constructs a background node for a base colour of black.
SphereBackground(float[] c)
          Construct a background node for a user-provided colour.
 
Method Summary
 void cleanup(javax.media.opengl.GL gl)
          Cleanup the object now for the given GL context.
 int compareTo(java.lang.Object o)
          Compares this object with the specified object for order.
 int compareTo(SphereBackground bg)
          Compares this object with the specified object for order.
 boolean equals(java.lang.Object o)
          Compare this object for equality to the given object.
 boolean equals(SphereBackground bg)
          Compares this object with the specified object to check for equivalence.
 void getColor(float[] c)
          Get the current drawing colour
 TextureComponent2D getTexture()
          Get the current image that is being used on the background.
 boolean is2D()
          Check to see whether this shape is something that represents 2D or 3D renderable background.
 void postRender(javax.media.opengl.GL gl)
          Restore all openGL state to the given drawable.
 void render(javax.media.opengl.GL gl)
          Issue ogl commands needed for this component
 void setColor(float[] c)
          Change the colour to the new colour.
 void setColor(float r, float g, float b, float a)
          Change the colour to the new colour.
 void setTexture(TextureComponent2D srcImage)
          Set the image source to be used for the background.
 
Methods inherited from class org.j3d.aviatrix3d.Background
compareColor4, equalsColor4, getCullableParent, getRenderable, isColorClearEnabled, markBoundsDirty, setColorClearEnabled
 
Methods inherited from class org.j3d.aviatrix3d.Node
boundsChanged, checkForCyclicParent, getBounds, getParent, recomputeBounds, removeParent, requestBoundsUpdate, setBounds, setParent, updateBounds, updateParentBounds
 
Methods inherited from class org.j3d.aviatrix3d.SceneGraphObject
checkForCyclicChild, dataChanged, getAppUpdateWriteTimingMessage, getBoundsWriteTimingMessage, getDataWriteTimingMessage, getUserData, isLive, setLive, setUpdateHandler, setUserData
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

width

protected int width
The width of the main texture.


height

protected int height
The height of the main texture.


stateChanged

protected boolean stateChanged
Flag to say that the display lists must be cleared and regenerated because some state changed


textureIdMap

protected java.util.HashMap<javax.media.opengl.GL,java.lang.Integer> textureIdMap
The mapping of GL context to OpenGL texture ID

Constructor Detail

SphereBackground

public SphereBackground()
Constructs a background node for a base colour of black.


SphereBackground

public SphereBackground(float[] c)
Construct a background node for a user-provided colour. The colour provided should have 3 or 4 elements. If 3 are provided, a fully opaque background is assumed. If less than 3 elements are provided, an exception is generated. If the array is null, this assumes the a default black background.

Parameters:
c - The array of colours to use, or null
Throws:
java.lang.IllegalArgumentException - The colour array is not long enough
Method Detail

cleanup

public void cleanup(javax.media.opengl.GL gl)
Cleanup the object now for the given GL context.

Specified by:
cleanup in interface DeletableRenderable
Parameters:
gl - The gl context to draw with

is2D

public boolean is2D()
Check to see whether this shape is something that represents 2D or 3D renderable background. Pure 2D backgrounds do not need transformation stacks or frustums set up to render - they can blit straight to the screen as needed.

Specified by:
is2D in interface BackgroundRenderable
Returns:
True if this is 2D background, false if this is 3D

render

public void render(javax.media.opengl.GL gl)
Issue ogl commands needed for this component

Specified by:
render in interface ObjectRenderable
Parameters:
gl - The gl context to draw with

postRender

public void postRender(javax.media.opengl.GL gl)
Restore all openGL state to the given drawable.

Specified by:
postRender in interface ObjectRenderable
Parameters:
gl - The gl context to draw with

compareTo

public int compareTo(java.lang.Object o)
              throws java.lang.ClassCastException
Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
o - The objec to be compared
Returns:
-1, 0 or 1 depending on order
Throws:
java.lang.ClassCastException - The specified object's type prevents it from being compared to this Object

equals

public boolean equals(java.lang.Object o)
Compare this object for equality to the given object.

Specified by:
equals in interface Renderable
Overrides:
equals in class java.lang.Object
Parameters:
o - The object to be compared
Returns:
True if these represent the same values

setColor

public void setColor(float[] c)
              throws InvalidWriteTimingException
Change the colour to the new colour. Colour takes RGBA.

Overrides:
setColor in class Background
Parameters:
c - The colour to copy in
Throws:
InvalidWriteTimingException - An attempt was made to write outside of the NodeUpdateListener data changed callback method

setColor

public void setColor(float r,
                     float g,
                     float b,
                     float a)
              throws InvalidWriteTimingException
Change the colour to the new colour. Colour takes RGBA.

Overrides:
setColor in class Background
Parameters:
r - The red colour component to use
g - The green colour component to use
b - The blue colour component to use
a - The alpha colour component to use
Throws:
InvalidWriteTimingException - An attempt was made to write outside of the NodeUpdateListener data changed callback method

getColor

public void getColor(float[] c)
Get the current drawing colour

Overrides:
getColor in class Background
Parameters:
c - An array of length 4 or more to copy the colour to

setTexture

public void setTexture(TextureComponent2D srcImage)
                throws InvalidWriteTimingException
Set the image source to be used for the background. If the texture is a single component only, then a luminance texture format is used. Alpha- only textures aren't really useful.

Parameters:
srcImage - The image data to use
Throws:
InvalidWriteTimingException - An attempt was made to write outside of the NodeUpdateListener data changed callback method

getTexture

public TextureComponent2D getTexture()
Get the current image that is being used on the background. If none is defined, return null.

Returns:
The current texture source or null

compareTo

public int compareTo(SphereBackground bg)
Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

Parameters:
bg - The argument instance to be compared
Returns:
-1, 0 or 1 depending on order

equals

public boolean equals(SphereBackground bg)
Compares this object with the specified object to check for equivalence.

Parameters:
bg - The background instance to be compared
Returns:
true if the objects represent identical values

Aviatrix3D
2.1.0

Latest Info from http://aviatrix3d.j3d.org/
Copyright © 2003 - 2009 j3d.org