Class FieldPortrayal3D

java.lang.Object
sim.portrayal.FieldPortrayal
sim.portrayal3d.FieldPortrayal3D
All Implemented Interfaces:
Portrayal, Portrayal3D
Direct Known Subclasses:
ObjectGridPortrayal3D, SparseFieldPortrayal3D, ValueGrid2DPortrayal3D, ValueGridPortrayal3D

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 benefit from knowing if their underlying fields are immutable.

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

  • Constructor Details

    • FieldPortrayal3D

      public FieldPortrayal3D()
    • FieldPortrayal3D

      public FieldPortrayal3D(javax.media.j3d.Transform3D transform)
  • Method Details

    • 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
    • setCurrentDisplay

      public void setCurrentDisplay(Display3D display)
      Description copied from interface: Portrayal3D
      Sets the current Display3D. Called by the Display3D on attach(...).
      Specified by:
      setCurrentDisplay in interface Portrayal3D
    • getCurrentDisplay

      public Display3D getCurrentDisplay()
      Description copied from interface: Portrayal3D
      Returns the current Display3D, or possibly null if it's not been set yet. SimplePortrayals should implement this method by returning a display if it's been set with setCurrentDisplay(...), else returning whatever the field portrayal's got set, else null if there is no field portrayal yet.
      Specified by:
      getCurrentDisplay in interface Portrayal3D
    • getCurrentGUIState

      public GUIState getCurrentGUIState()
      Description copied from interface: Portrayal3D
      Returns the current GUIState, or null if no GUIState has been set yet. The GUIState will be set *at least* immediately prior to getModel(...). You should implement this method as: { Display3D d = getCurrentDisplay(); return (d == null ? null : d.getSimulation()); }
      Specified by:
      getCurrentGUIState 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

      protected 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(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 ModelTransformGroup[InternalTransformGroup[model info]].

      InternalTransform is a hook for transforming the FieldPortrayal3D. The ModelTransformGroup 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 InternalTransformGroup[model info].

      ...where InternalTransformGroup 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 InternalTransformGroup[model info].

      ...where InternalTransformGroup 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, com.sun.j3d.utils.picking.PickResult pr)
      Given the provided PickIntersection and the PickResult it came from, fill in w the location of the picked object, and return it. Alternatively, return a new LocationWrapper with all information filled in. The PickResult is provided you in case the object is in a shared group and you need to identify what link had connected to it.
    • getObjectLocation

      public Object getObjectLocation(Object object, GUIState gui)
      Returns the first location in the underlying field of the given object, if such a thing is reasonable. Largely used for getObjectPosition(...). If null is returned, then the portrayal is unable to determine the position of the field location. Optionally overridable. The default implementation returns null.
      Overrides:
      getObjectLocation in class FieldPortrayal
    • setObjectLocation

      public void setObjectLocation(Object obj, Object location, GUIState gui)
      Sets location in the underlying field of the given object, if such a thing is reasonable. Largely used for setObjectPosition(...), and in the Inspector's LocationWrapper via the Stable classes. Optionally overridable. The default implementation does nothing.
      Overrides:
      setObjectLocation in class FieldPortrayal