sim.portrayal3d
Class FieldPortrayal3D

java.lang.Object
  extended bysim.portrayal.FieldPortrayal
      extended bysim.portrayal3d.FieldPortrayal3D
All Implemented Interfaces:
Portrayal, Portrayal3D, java.io.Serializable
Direct Known Subclasses:
SparseFieldPortrayal3D, ValueGrid2DPortrayal3D

public abstract class FieldPortrayal3D
extends FieldPortrayal
implements Portrayal3D

Superclass of all Field Portrayals in J3D.

This class implements the getModel() function by breaking it down into two subsidiary functions which Field Portrayals need to implement: the createModel(...) and updateModel(...) functions.

FieldPortrayal3D maintains a user-modifiable transform called internalTransform, provides an additional layer of transform indirection goodness. internalTransform should be used primarily to adjust the location of the FieldPortrayal3D relative to other FieldPortrayal3Ds. Note that the internalTransform is not the root TransformGroup in the scenegraph handed to getModel(...) -- it's child of the root. However, the createModel() and updateModel() functions will see it as the root of their respective scenegraphs.

Many FieldPortrayals need to further transform themselves: for example, grids might need to shift themselves one-half a grid position. These operations should be done privately and should not fool around with internalTransform to get the job done.

Most FieldPortrayal3Ds can respond to being set to an immutable field, meaning that the underlying field is assumed to be unchanging. This is useful if you want to make a field of obstacles, for example. If told to make this assumption, the FieldPortrayal3Ds will not update themselves to reflect any changes -- this is much faster in drawing.

FieldPortrayal3Ds must also implement the completedWrapper() method, which provides them with a PickIntersection and a LocationWrapper found stored in the object at that intersection.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class sim.portrayal.FieldPortrayal
FieldPortrayal.CustomInspector
 
Field Summary
protected  java.lang.Object field
           
protected  boolean immutableField
           
 
Fields inherited from class sim.portrayal.FieldPortrayal
classPortrayals, portrayalForAll, portrayalForNull, portrayalForRemainder, portrayals
 
Constructor Summary
FieldPortrayal3D()
           
FieldPortrayal3D(javax.media.j3d.Transform3D transform)
           
 
Method Summary
abstract  LocationWrapper completedWrapper(LocationWrapper w, com.sun.j3d.utils.picking.PickIntersection pi)
          Given the provided PickIntersection, fill in w the location of the picked object, and return it.
protected abstract  javax.media.j3d.TransformGroup createModel()
          Returns a tree structure of the form InternalTransform[model info].
 Portrayal getDefaultPortrayal()
          Should return a portrayal which can portray any object regardless of whether it's valid or not
 javax.media.j3d.Transform3D getDefaultTransform()
          Returns the default internal transform suggested for this FieldPortrayal3D.
 java.lang.Object getField()
          Returns the current field.
 javax.media.j3d.TransformGroup getModel(java.lang.Object obj, javax.media.j3d.TransformGroup previousTransformGroup)
          Produces the requested model.
 javax.media.j3d.Transform3D getTransform()
          Returns a copy of the current internal transform for the FieldPortrayal3D.
 boolean isImmutableField()
          Returns true if the underlying field is assumed to be unchanging -- thus there's no reason to update once we're created.
 javax.media.j3d.PolygonAttributes polygonAttributes()
          Provides a PolygonAttributes which can be modified to change the underlying model's attributes (culling, vertex versus point versus fill).
 void resetTransform()
          Resets the internal transform to the value of getDefaultTransform()
 void rotateX(double degrees)
          Modifies the internal transform by rotating along the current X axis the provided number of degrees.
 void rotateY(double degrees)
          Modifies the internal transform by rotating along the current Y axis the provided number of degrees.
 void rotateZ(double degrees)
          Modifies the internal transform by rotating along the current Z axis the provided number of degrees.
 void scale(double value)
          Modifies the internal transform by uniformly scaling it in all directions by the provided amount.
 void scale(double sx, double sy, double sz)
          Modifies the internal transform by scaling it in a nonuniform fashion.
abstract  void setField(java.lang.Object field)
          Attaches the field portrayal to the given field.
 void setImmutableField(boolean val)
          Specifies that the underlying field is (or is not) to be assumed unchanging -- thus there's no reason to update once we're created.
 void setTransform(javax.media.j3d.Transform3D transform)
          Sets the FieldPortrayal3D's internal Transform.
 void transform(javax.media.j3d.Transform3D transform)
          Changes the internal transform of the FieldPortrayal3D by appending to it the provided transform operation.
 void translate(double dx, double dy, double dz)
          Modifies the internal transform by translating in the provided x, y, and z amounts.
protected  void updateModel(javax.media.j3d.TransformGroup previousTransformGroup)
          Returns a tree structure of the form InternalTransform[model info].
 
Methods inherited from class sim.portrayal.FieldPortrayal
getDefaultNullPortrayal, getInspector, getName, getPortrayalForAll, getPortrayalForNull, getPortrayalForObject, getPortrayalForRemainder, setPortrayalForAll, setPortrayalForClass, setPortrayalForNull, setPortrayalForObject, setPortrayalForRemainder, setSelected
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface sim.portrayal.Portrayal
getInspector, getName, setSelected
 

Field Detail

field

protected java.lang.Object field

immutableField

protected boolean immutableField
Constructor Detail

FieldPortrayal3D

public FieldPortrayal3D()

FieldPortrayal3D

public FieldPortrayal3D(javax.media.j3d.Transform3D transform)
Method Detail

isImmutableField

public boolean isImmutableField()
Returns true if the underlying field is assumed to be unchanging -- thus there's no reason to update once we're created.


setImmutableField

public void setImmutableField(boolean val)
Specifies that the underlying field is (or is not) to be assumed unchanging -- thus there's no reason to update once we're created.


getField

public java.lang.Object getField()
Description copied from class: FieldPortrayal
Returns the current field.

Specified by:
getField in class FieldPortrayal

setField

public abstract void setField(java.lang.Object field)
Description copied from class: FieldPortrayal
Attaches the field portrayal to the given field. Should throw an exception if the object is invalid.

Specified by:
setField in class FieldPortrayal

polygonAttributes

public javax.media.j3d.PolygonAttributes polygonAttributes()
Description copied from interface: Portrayal3D
Provides a PolygonAttributes which can be modified to change the underlying model's attributes (culling, vertex versus point versus fill). This is an optional function: you are free to return null

Specified by:
polygonAttributes in interface Portrayal3D

setTransform

public void setTransform(javax.media.j3d.Transform3D transform)
Sets the FieldPortrayal3D's internal Transform. This is a user-modifiable transform which should be used primarily to adjust the location of the FieldPortrayal3D relative to other FieldPortrayal3D objects. If null is provided, then the value of getDefaultTransform() is used.


getDefaultTransform

public javax.media.j3d.Transform3D getDefaultTransform()
Returns the default internal transform suggested for this FieldPortrayal3D.


getTransform

public javax.media.j3d.Transform3D getTransform()
Returns a copy of the current internal transform for the FieldPortrayal3D.


transform

public void transform(javax.media.j3d.Transform3D transform)
Changes the internal transform of the FieldPortrayal3D by appending to it the provided transform operation.


resetTransform

public void resetTransform()
Resets the internal transform to the value of getDefaultTransform()


rotateX

public void rotateX(double degrees)
Modifies the internal transform by rotating along the current X axis the provided number of degrees.


rotateY

public void rotateY(double degrees)
Modifies the internal transform by rotating along the current Y axis the provided number of degrees.


rotateZ

public void rotateZ(double degrees)
Modifies the internal transform by rotating along the current Z axis the provided number of degrees.


translate

public void translate(double dx,
                      double dy,
                      double dz)
Modifies the internal transform by translating in the provided x, y, and z amounts.


scale

public void scale(double value)
Modifies the internal transform by uniformly scaling it in all directions by the provided amount.


scale

public void scale(double sx,
                  double sy,
                  double sz)
Modifies the internal transform by scaling it in a nonuniform fashion. Note that this is less efficient than a uniform scale


getDefaultPortrayal

public Portrayal getDefaultPortrayal()
Description copied from class: FieldPortrayal
Should return a portrayal which can portray any object regardless of whether it's valid or not

Specified by:
getDefaultPortrayal in class FieldPortrayal

getModel

public javax.media.j3d.TransformGroup getModel(java.lang.Object obj,
                                               javax.media.j3d.TransformGroup previousTransformGroup)
Produces the requested model. You usually do not want to override this: instead you should implement the createModel and updateModel methods.

The TransformGroup tree structure should be of the form ModelTransform[InternalTransform[model info]].

InternalTransform is a hook for transforming the FieldPortrayal3D. ModelTransform should not be played with.

Specified by:
getModel in interface Portrayal3D

createModel

protected abstract javax.media.j3d.TransformGroup createModel()
Returns a tree structure of the form InternalTransform[model info].

...where InternalTransform is an identity transformgroup whose transform will be modified elsewhere (create it but don't play with it).


updateModel

protected void updateModel(javax.media.j3d.TransformGroup previousTransformGroup)
Returns a tree structure of the form InternalTransform[model info].

...where InternalTransform is an identity transformgroup whose transform will be modified elsewhere (don't play with it). By default, this function does nothing. Override it to update the model when it's called.


completedWrapper

public abstract LocationWrapper completedWrapper(LocationWrapper w,
                                                 com.sun.j3d.utils.picking.PickIntersection pi)
Given the provided PickIntersection, fill in w the location of the picked object, and return it. Alternatively, return a new LocationWrapper with all information filled in.