Class BaseTimeSensor
- All Implemented Interfaces:
VRMLNode,FrameStateListener,VRMLChildNodeType,VRMLNodeType,VRMLSensorNodeType,VRMLTimeControlledNodeType,VRMLTimeDependentNodeType,VRMLTimeListener,VRMLWorldRootChildNodeType
- Direct Known Subclasses:
NRTimeSensor,OGLTimeSensor
The implementation uses the standard VRML time clock to send and retrieve time information. As an efficiency measure, if the time sensor is disabled it will remove itself as a listener to the global clock. When it becomes re-enabled that listener will be added back again.
When setting values we always set the variable first and then set the flag indicating that the field has changed. This is so that we don't end up with a multi-threaded access thinking that a value has changed when it really hasn't (yet) and then ignoring the value. As we desperately try to avoid synchronized access internally, we try to set the real value first so that if someone does check and find it's changed, we can then give them the real value as soon as they ask for it.
- Version:
- $Revision: 1.41 $
- Author:
- Justin Couch, Alan Hudson
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final intThe field index for cycleIntervalprotected static final intThe field index for cycleTimeprotected static final intThe field index for enabledprotected static final intThe field index for fractionprotected static final intThe field index for isActiveprotected static final intThe field index for isPausedprotected static final intThe field index for timeprotected static final intThe last field index used by this classprotected static final intNumber of fields constantprotected doubleThe value of the cycle interval fieldprotected doubleThe value of the cycle time fieldprotected booleanThe value of the enabled fieldprotected floatThe value of the fraction intervalprotected booleanThe value of the isActive fieldprotected booleanThe value of the isPaused fieldprotected doubleThe value of the time fieldFields inherited from class org.web3d.vrml.renderer.common.nodes.BaseTimeControlledNode
FIELD_ELAPSED_TIME, FIELD_LOOP, FIELD_PAUSE_TIME, FIELD_RESUME_TIME, FIELD_START_TIME, FIELD_STOP_TIME, LAST_TIME_INDEX, vfElapsedTime, vfLoop, vfPauseTime, vfResumeTime, vfStartTime, vfStopTimeFields inherited from class org.web3d.vrml.renderer.common.nodes.BaseTimeDependentNode
vrmlClockFields inherited from class org.web3d.vrml.renderer.common.nodes.AbstractNode
errorReporter, FIELD_METADATA, fieldLocalData, hasChanged, inSetup, isDEF, isStatic, LAST_NODE_INDEX, layerIds, nodeName, pMetadata, refCounts, removedLayerIds, stateManager, STATIC_SCENE_GRAPH, vfMetadata, vrmlMajorVersion, vrmlMinorVersion -
Constructor Summary
ConstructorsConstructorDescriptionConstruct a new time sensor objectBaseTimeSensor(VRMLNodeType node) Construct a new instance of this node based on the details from the given node. -
Method Summary
Modifier and TypeMethodDescriptionvoidNotification that the rendering of the event model is complete and that rendering is about to begin.doubleGet the current value of the cycleInterval field.doubleGet the current value of the cycleTime field.booleanAccessor method to get current value to the enabled field.getFieldDeclaration(int index) Get the declaration of the field at the given index.intgetFieldIndex(String fieldName) Get the index of the given field name.getFieldValue(int index) Get the value of a field.floatGet the current value of the fraction field.booleanAccessor method to get current value of field isActive.int[]Get the list of indices that correspond to fields that contain nodes ie MFNode and SFNode).intGet the number of fields.intGet the primary type of this node.int[]Get the secondary type of this node.doublegetTime()Get the current value of the time field.voidsendRoute(double time, int srcIndex, VRMLNodeType destNode, int destIndex) Send a routed value from this node to the given destination node.voidsetCycleInterval(double newCycleInterval) Set the cycleInterval field value to the new value.voidsetEnabled(boolean newEnabled) Set the sensor enabled or disabled.voidsetLoop(boolean newLoop) Set the loop field value.voidsetPauseTime(double newPauseTime) Set a new value for the pause time.voidsetResumeTime(double newResumeTime) Set a new value for the resume time.voidsetStartTime(double newStartTime) Set a new value for the start time.voidsetStopTime(double newStopTime) Set a new value for the stop time.voidNotification that the construction phase of this node has finished.voidsetValue(int index, boolean value) Set the value of the field at the given index as a boolean.voidsetValue(int index, double value) Set the value of the field at the given index as a double for the SFTime fields.voidsetVRMLClock(VRMLClock clk) Set the vrmlClock that this time dependent node will be running with.voidtimeClick(long time) Notification that the time is now this value.Methods inherited from class org.web3d.vrml.renderer.common.nodes.BaseTimeControlledNode
copy, getLoop, getStartTime, getStopTimeMethods inherited from class org.web3d.vrml.renderer.common.nodes.AbstractNode
addNodeListener, checkNodeType, checkSecondaryType, checkSecondaryType, clearRemovedLayerIds, fireFieldChanged, getLayerIds, getMetadataObject, getRefCount, getRemovedLayerIds, getUserData, getVRMLNodeName, hasFieldChanged, isDEF, isSetupFinished, notifyExternProtoLoaded, removeNodeListener, setDEF, setErrorReporter, setFrameStateManager, setMetadataObject, setUserData, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setVersion, throwInitOnlyWriteException, throwInputOnlyWriteException, throwInvalidNodeException, throwInvalidProtoException, throwOutputOnlyWriteException, updateRefCount, updateRefsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.web3d.vrml.lang.VRMLNode
getUserData, getVRMLNodeName, isDEF, setErrorReporter, setUserData, setVersionMethods inherited from interface org.web3d.vrml.nodes.VRMLNodeType
addNodeListener, clearRemovedLayerIds, getLayerIds, getMetadataObject, getRefCount, getRemovedLayerIds, hasFieldChanged, isSetupFinished, notifyExternProtoLoaded, removeNodeListener, setDEF, setFrameStateManager, setMetadataObject, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, updateRefCount
-
Field Details
-
FIELD_CYCLE_INTERVAL
protected static final int FIELD_CYCLE_INTERVALThe field index for cycleInterval- See Also:
-
FIELD_FRACTION
protected static final int FIELD_FRACTIONThe field index for fraction- See Also:
-
FIELD_TIME
protected static final int FIELD_TIMEThe field index for time- See Also:
-
FIELD_CYCLE_TIME
protected static final int FIELD_CYCLE_TIMEThe field index for cycleTime- See Also:
-
FIELD_IS_ACTIVE
protected static final int FIELD_IS_ACTIVEThe field index for isActive- See Also:
-
FIELD_IS_PAUSED
protected static final int FIELD_IS_PAUSEDThe field index for isPaused- See Also:
-
FIELD_ENABLED
protected static final int FIELD_ENABLEDThe field index for enabled- See Also:
-
LAST_TIME_SENSOR_INDEX
protected static final int LAST_TIME_SENSOR_INDEXThe last field index used by this class- See Also:
-
NUM_FIELDS
protected static final int NUM_FIELDSNumber of fields constant- See Also:
-
vfCycleTime
protected double vfCycleTimeThe value of the cycle time field -
vfCycleInterval
protected double vfCycleIntervalThe value of the cycle interval field -
vfFraction
protected float vfFractionThe value of the fraction interval -
vfTime
protected double vfTimeThe value of the time field -
vfIsActive
protected boolean vfIsActiveThe value of the isActive field -
vfIsPaused
protected boolean vfIsPausedThe value of the isPaused field -
vfEnabled
protected boolean vfEnabledThe value of the enabled field
-
-
Constructor Details
-
BaseTimeSensor
public BaseTimeSensor()Construct a new time sensor object -
BaseTimeSensor
Construct a new instance of this node based on the details from the given node. If the node is not the same type, an exception will be thrown.- Parameters:
node- The node to copy- Throws:
IllegalArgumentException- The node is not the same type
-
-
Method Details
-
allEventsComplete
public void allEventsComplete()Notification that the rendering of the event model is complete and that rendering is about to begin. Used to update the transformation matrix only once per frame.- Specified by:
allEventsCompletein interfaceFrameStateListener- Overrides:
allEventsCompletein classAbstractNode
-
getCycleTime
public double getCycleTime()Get the current value of the cycleTime field.- Returns:
- the current time value
-
getCycleInterval
public double getCycleInterval()Get the current value of the cycleInterval field.- Returns:
- the current time value
-
setCycleInterval
Set the cycleInterval field value to the new value. If it is out of range the throw an exception.- Parameters:
newCycleInterval- The new time to set- Throws:
InvalidFieldValueException- The field is out of range
-
getFraction
public float getFraction()Get the current value of the fraction field.- Returns:
- the current time value
-
getTime
public double getTime()Get the current value of the time field.- Returns:
- the current time value
-
setVRMLClock
Set the vrmlClock that this time dependent node will be running with. The vrmlClock provides all the information and listeners for keeping track of time. If we are enabled at the time that this method is called we automatically register the listener. Then, all the events that need to be generated will be handled at the next vrmlClock tick we get issued.- Specified by:
setVRMLClockin interfaceVRMLTimeDependentNodeType- Overrides:
setVRMLClockin classBaseTimeDependentNode- Parameters:
clk- The vrmlClock to use for this node
-
setLoop
public void setLoop(boolean newLoop) Set the loop field value.- Specified by:
setLoopin interfaceVRMLTimeControlledNodeType- Overrides:
setLoopin classBaseTimeControlledNode- Parameters:
newLoop- Whether this field loops or not
-
setStartTime
public void setStartTime(double newStartTime) Set a new value for the start time. If the sensor is active then it is ignored.- Specified by:
setStartTimein interfaceVRMLTimeControlledNodeType- Overrides:
setStartTimein classBaseTimeControlledNode- Parameters:
newStartTime- The new start time
-
setPauseTime
public void setPauseTime(double newPauseTime) Set a new value for the pause time.- Overrides:
setPauseTimein classBaseTimeControlledNode- Parameters:
newPauseTime- The new start time
-
setResumeTime
public void setResumeTime(double newResumeTime) Set a new value for the resume time.- Overrides:
setResumeTimein classBaseTimeControlledNode- Parameters:
newResumeTime- The new resume time
-
setStopTime
public void setStopTime(double newStopTime) Set a new value for the stop time. If the sensor is active and the stop time is less than the current start time, it is ignored. If the stop time is less that now, it is set to the value now.- Specified by:
setStopTimein interfaceVRMLTimeControlledNodeType- Overrides:
setStopTimein classBaseTimeControlledNode- Parameters:
newStopTime- The new stop time
-
setEnabled
public void setEnabled(boolean newEnabled) Set the sensor enabled or disabled.- Specified by:
setEnabledin interfaceVRMLSensorNodeType- Parameters:
newEnabled- The new enabled value
-
getEnabled
public boolean getEnabled()Accessor method to get current value to the enabled field.- Specified by:
getEnabledin interfaceVRMLSensorNodeType- Returns:
- The value of the enabled field
-
getIsActive
public boolean getIsActive()Accessor method to get current value of field isActive.- Specified by:
getIsActivein interfaceVRMLSensorNodeType- Returns:
- The current value of isActive
-
setupFinished
public void setupFinished()Notification that the construction phase of this node has finished. If the node would like to do any internal processing, such as setting up geometry, then go for it now.- Specified by:
setupFinishedin interfaceVRMLNodeType- Overrides:
setupFinishedin classAbstractNode
-
getFieldIndex
Get the index of the given field name. If the name does not exist for this node then return a value of -1.- Specified by:
getFieldIndexin interfaceVRMLNode- Parameters:
fieldName- The name of the field we want the index from- Returns:
- The index of the field name or -1
-
getNodeFieldIndices
public int[] getNodeFieldIndices()Get the list of indices that correspond to fields that contain nodes ie MFNode and SFNode). Used for blind scene graph traversal without needing to spend time querying for all fields etc. If a node does not have any fields that contain nodes, this shall return null. The field list covers all field types, regardless of whether they are readable or not at the VRML-level.- Specified by:
getNodeFieldIndicesin interfaceVRMLNode- Returns:
- The list of field indices that correspond to SF/MFnode fields or null if none
-
getFieldDeclaration
Get the declaration of the field at the given index. This allows for reverse lookup if needed. If the field does not exist, this will give a value of null.- Specified by:
getFieldDeclarationin interfaceVRMLNode- Parameters:
index- The index of the field to get information- Returns:
- A representation of this field's information
-
getNumFields
public int getNumFields()Get the number of fields.- Specified by:
getNumFieldsin interfaceVRMLNode- Returns:
- The number of fields.
-
getPrimaryType
public int getPrimaryType()Get the primary type of this node. Replaces the instanceof mechanism for use in switch statements.- Specified by:
getPrimaryTypein interfaceVRMLNode- Returns:
- The primary type
-
getSecondaryType
public int[] getSecondaryType()Get the secondary type of this node. Replaces the instanceof mechanism for use in switch statements.- Specified by:
getSecondaryTypein interfaceVRMLNode- Overrides:
getSecondaryTypein classAbstractNode- Returns:
- The secondary type
-
getFieldValue
Get the value of a field. If the field is a primitive type, it will return a class representing the value. For arrays or nodes it will return the instance directly.- Specified by:
getFieldValuein interfaceVRMLNodeType- Overrides:
getFieldValuein classBaseTimeControlledNode- Parameters:
index- The index of the field to change.- Returns:
- The class representing the field value
- Throws:
InvalidFieldException- The field index is not known
-
sendRoute
Send a routed value from this node to the given destination node. The route should use the appropriate setValue() method of the destination node. It should not attempt to cast the node up to a higher level. Routing should also follow the standard rules for the loop breaking and other appropriate rules for the specification.- Specified by:
sendRoutein interfaceVRMLNodeType- Overrides:
sendRoutein classAbstractNode- Parameters:
time- The time that this route occurred (not necessarily epoch time. Should be treated as a relative value only)srcIndex- The index of the field in this node that the value should be sent fromdestNode- The node reference that we will be sending the value todestIndex- The index of the field in the destination node that the value should be sent to.
-
setValue
public void setValue(int index, double value) throws InvalidFieldException, InvalidFieldValueException Set the value of the field at the given index as a double for the SFTime fields. The fields effected by this cycleTime, cycleInterval, startTime, stopTime, fraction and time fields. This method does not currently check for negative values. Should it?- Specified by:
setValuein interfaceVRMLNodeType- Overrides:
setValuein classBaseTimeControlledNode- Parameters:
index- The index of destination field to setvalue- The new value to use for the node- Throws:
InvalidFieldException- The field index is not knownInvalidFieldValueException- The value provided is not in range or not appropriate for this field
-
setValue
public void setValue(int index, boolean value) throws InvalidFieldException, InvalidFieldValueException Set the value of the field at the given index as a boolean. This is be used to set SFBool field types isActive, enabled and loop.- Specified by:
setValuein interfaceVRMLNodeType- Overrides:
setValuein classBaseTimeControlledNode- Parameters:
index- The index of destination field to setvalue- The new value to use for the node- Throws:
InvalidFieldException- The field index is not knownInvalidFieldValueException- The value provided is not in range or not appropriate for this field
-
timeClick
public void timeClick(long time) Notification that the time is now this value.- Specified by:
timeClickin interfaceVRMLTimeListener- Parameters:
time- The current time
-