Class FieldPortrayal3D
- All Implemented Interfaces:
Portrayal
,Portrayal3D
- Direct Known Subclasses:
ObjectGridPortrayal3D
,SparseFieldPortrayal3D
,ValueGrid2DPortrayal3D
,ValueGridPortrayal3D
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.
-
Field Summary
Fields inherited from class sim.portrayal.FieldPortrayal
classPortrayals, field, immutableField, portrayalForAll, portrayalForNonNull, portrayalForNull, portrayalForRemainder, portrayals
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionabstract 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.protected abstract javax.media.j3d.TransformGroup
Returns a tree structure of the form InternalTransformGroup[model info].Returns the current Display3D, or possibly null if it's not been set yet.Returns the current GUIState, or null if no GUIState has been set yet.Should return a portrayal which can portray any object regardless of whether it's valid or notprotected javax.media.j3d.Transform3D
Returns the default internal transform suggested for this FieldPortrayal3D.javax.media.j3d.TransformGroup
Produces the requested model.getObjectLocation
(Object object, GUIState gui) Returns the first location in the underlying field of the given object, if such a thing is reasonable.javax.media.j3d.Transform3D
Returns a copy of the current internal transform for the FieldPortrayal3D.javax.media.j3d.PolygonAttributes
Provides a PolygonAttributes which can be modified to change the underlying model's attributes (culling, vertex versus point versus fill).void
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.void
setCurrentDisplay
(Display3D display) Sets the current Display3D.void
setObjectLocation
(Object obj, Object location, GUIState gui) Sets location in the underlying field of the given object, if such a thing is reasonable.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 InternalTransformGroup[model info].Methods inherited from class sim.portrayal.FieldPortrayal
getAlternatePortrayalOrdering, getDefaultNullPortrayal, getField, getInspector, getName, getPortrayalForAll, getPortrayalForNonNull, getPortrayalForNull, getPortrayalForObject, getPortrayalForRemainder, getStatus, isDirtyField, isImmutableField, reset, setAlternatePortrayalOrdering, setDirtyField, setField, setImmutableField, setPortrayalForAll, setPortrayalForClass, setPortrayalForNonNull, setPortrayalForNull, setPortrayalForObject, setPortrayalForRemainder, setSelected, 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, getStatus, setSelected
-
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 interfacePortrayal3D
-
setCurrentDisplay
Description copied from interface:Portrayal3D
Sets the current Display3D. Called by the Display3D on attach(...).- Specified by:
setCurrentDisplay
in interfacePortrayal3D
-
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 interfacePortrayal3D
-
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 interfacePortrayal3D
-
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
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 classFieldPortrayal
-
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 interfacePortrayal3D
-
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
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 classFieldPortrayal
-
setObjectLocation
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 classFieldPortrayal
-