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 int
The field index for cycleIntervalprotected static final int
The field index for cycleTimeprotected static final int
The field index for enabledprotected static final int
The field index for fractionprotected static final int
The field index for isActiveprotected static final int
The field index for isPausedprotected static final int
The field index for timeprotected static final int
The last field index used by this classprotected static final int
Number of fields constantprotected double
The value of the cycle interval fieldprotected double
The value of the cycle time fieldprotected boolean
The value of the enabled fieldprotected float
The value of the fraction intervalprotected boolean
The value of the isActive fieldprotected boolean
The value of the isPaused fieldprotected double
The 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, vfStopTime
Fields inherited from class org.web3d.vrml.renderer.common.nodes.BaseTimeDependentNode
vrmlClock
Fields 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 TypeMethodDescriptionvoid
Notification that the rendering of the event model is complete and that rendering is about to begin.double
Get the current value of the cycleInterval field.double
Get the current value of the cycleTime field.boolean
Accessor method to get current value to the enabled field.getFieldDeclaration
(int index) Get the declaration of the field at the given index.int
getFieldIndex
(String fieldName) Get the index of the given field name.getFieldValue
(int index) Get the value of a field.float
Get the current value of the fraction field.boolean
Accessor 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).int
Get the number of fields.int
Get the primary type of this node.int[]
Get the secondary type of this node.double
getTime()
Get the current value of the time field.void
sendRoute
(double time, int srcIndex, VRMLNodeType destNode, int destIndex) Send a routed value from this node to the given destination node.void
setCycleInterval
(double newCycleInterval) Set the cycleInterval field value to the new value.void
setEnabled
(boolean newEnabled) Set the sensor enabled or disabled.void
setLoop
(boolean newLoop) Set the loop field value.void
setPauseTime
(double newPauseTime) Set a new value for the pause time.void
setResumeTime
(double newResumeTime) Set a new value for the resume time.void
setStartTime
(double newStartTime) Set a new value for the start time.void
setStopTime
(double newStopTime) Set a new value for the stop time.void
Notification that the construction phase of this node has finished.void
setValue
(int index, boolean value) Set the value of the field at the given index as a boolean.void
setValue
(int index, double value) Set the value of the field at the given index as a double for the SFTime fields.void
setVRMLClock
(VRMLClock clk) Set the vrmlClock that this time dependent node will be running with.void
timeClick
(long time) Notification that the time is now this value.Methods inherited from class org.web3d.vrml.renderer.common.nodes.BaseTimeControlledNode
copy, getLoop, getStartTime, getStopTime
Methods 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, updateRefs
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.web3d.vrml.lang.VRMLNode
getUserData, getVRMLNodeName, isDEF, setErrorReporter, setUserData, setVersion
Methods 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:
allEventsComplete
in interfaceFrameStateListener
- Overrides:
allEventsComplete
in 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:
setVRMLClock
in interfaceVRMLTimeDependentNodeType
- Overrides:
setVRMLClock
in classBaseTimeDependentNode
- Parameters:
clk
- The vrmlClock to use for this node
-
setLoop
public void setLoop(boolean newLoop) Set the loop field value.- Specified by:
setLoop
in interfaceVRMLTimeControlledNodeType
- Overrides:
setLoop
in 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:
setStartTime
in interfaceVRMLTimeControlledNodeType
- Overrides:
setStartTime
in classBaseTimeControlledNode
- Parameters:
newStartTime
- The new start time
-
setPauseTime
public void setPauseTime(double newPauseTime) Set a new value for the pause time.- Overrides:
setPauseTime
in classBaseTimeControlledNode
- Parameters:
newPauseTime
- The new start time
-
setResumeTime
public void setResumeTime(double newResumeTime) Set a new value for the resume time.- Overrides:
setResumeTime
in 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:
setStopTime
in interfaceVRMLTimeControlledNodeType
- Overrides:
setStopTime
in classBaseTimeControlledNode
- Parameters:
newStopTime
- The new stop time
-
setEnabled
public void setEnabled(boolean newEnabled) Set the sensor enabled or disabled.- Specified by:
setEnabled
in interfaceVRMLSensorNodeType
- Parameters:
newEnabled
- The new enabled value
-
getEnabled
public boolean getEnabled()Accessor method to get current value to the enabled field.- Specified by:
getEnabled
in interfaceVRMLSensorNodeType
- Returns:
- The value of the enabled field
-
getIsActive
public boolean getIsActive()Accessor method to get current value of field isActive.- Specified by:
getIsActive
in 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:
setupFinished
in interfaceVRMLNodeType
- Overrides:
setupFinished
in 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:
getFieldIndex
in 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:
getNodeFieldIndices
in 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:
getFieldDeclaration
in 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:
getNumFields
in 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:
getPrimaryType
in 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:
getSecondaryType
in interfaceVRMLNode
- Overrides:
getSecondaryType
in 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:
getFieldValue
in interfaceVRMLNodeType
- Overrides:
getFieldValue
in 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:
sendRoute
in interfaceVRMLNodeType
- Overrides:
sendRoute
in 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:
setValue
in interfaceVRMLNodeType
- Overrides:
setValue
in 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:
setValue
in interfaceVRMLNodeType
- Overrides:
setValue
in 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:
timeClick
in interfaceVRMLTimeListener
- Parameters:
time
- The current time
-