Class BaseViewpoint
java.lang.Object
org.web3d.vrml.renderer.common.nodes.AbstractNode
org.web3d.vrml.renderer.common.nodes.BaseBindableNode
org.web3d.vrml.renderer.common.nodes.navigation.BaseViewpoint
- All Implemented Interfaces:
VRMLNode
,FrameStateListener
,VRMLBindableNodeType
,VRMLChildNodeType
,VRMLNodeType
,VRMLTimeDependentNodeType
,VRMLViewpointNodeType
,VRMLWorldRootChildNodeType
- Direct Known Subclasses:
NRViewpoint
,OGLViewpoint
Common implementation of a Viewpoint node.
VRML requires the use of a headlight from the NavigationInfo node. For convenience, we provide a headlight here that binds with the same transform as the view platform.
Viewpoints cannot be shared using DEF/USE. They may be named as such for Anchor purposes, but attempting to reuse them will cause an error. This implementation does not provide any protection against USE of this node and attempting to do so will result in throwing exceptions - most probably in the grouping node that includes this node.
- Version:
- $Revision: 1.15 $
- Author:
- Alan Hudson
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final int
Index of the centerOfRotation fieldprotected static final int
Index of the description fieldprotected static final int
Index of the farDistance fieldprotected static final int
Index of the fieldOfView fieldprotected static final int
Index of the jump fieldprotected static final int
Index of the nearDistance fieldprotected static final int
Index of the orientation fieldprotected static final int
Index of the position fieldprotected static final int
Index of the retainUserOffsets fieldprotected static final int
Index of the viewAll fieldprotected static final int
The last index of the nodes used by the viewpointprotected static final int
Number of fields constantprotected float[]
SFVec3f centerOfRotation 0 0 0protected String
SFString description ""protected float
SFFloat farDistance -1protected float
SFFloat fieldOfView 0.785398protected boolean
SFBool jump TRUEprotected float
SFFloat nearDistance -1protected float[]
SFRotation orientation 0 0 1 0protected float[]
SFVec3f position 0 0 10protected boolean
SFBool retainUserOffsets FALSEprotected boolean
SFBool viewAll FALSEprotected List
<ViewpointListener> List of those who want to know about role changes, likely 1Fields inherited from class org.web3d.vrml.renderer.common.nodes.BaseBindableNode
FIELD_BIND, FIELD_BIND_TIME, FIELD_IS_BOUND, isOnStack, LAST_BINDABLE_INDEX, vfBindTime, vfIsBound
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
Fields inherited from interface org.web3d.vrml.nodes.VRMLViewpointNodeType
PROJECTION_ORTHO, PROJECTION_PERSPECTIVE
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Construct a default viewpoint instanceprotected
BaseViewpoint
(VRMLNodeType node) Construct a new instance of this node based on the details from the given node. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add a ViewpointListener.protected void
fireCenterOfRotationChanged
(float[] val) Send a notification to the registered listeners the center of rotation has changed.protected void
fireFieldOfViewChanged
(float[] val) Send a notification to the registered listeners the field of view has changed.float[]
Get the center of rotation defined by this viewpoint.Get the description string associated with this viewpoint.float
Get the farDistance value associated with this viewpoint.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.float[]
Get the field of view used by this viewpoint.getFieldValue
(int index) Get the value of a field.boolean
getJump()
Get the Jump field value of this viewpoint.float
Get the nearDistance value associated with this viewpoint.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 projection type.boolean
Get the retainUserOffsets field value of this viewpoint.boolean
Get the viewAll field value of this viewpoint.void
Remove a ViewpointListener.void
sendRoute
(double time, int srcIndex, VRMLNodeType destNode, int destIndex) Send a routed value from this node to the given destination node.void
setCenterOfRotation
(float[] pos) Set the center of rotation of this viewpoint.void
setDescription
(String desc) Set the description string of this viewpoint.void
setFarDistance
(float newValue) Set the farDistance value of this viewpointvoid
setFieldOfView
(float fov) Set the field of view for this viewpoint.void
setJump
(boolean jump) Set the jump field value of this viewpoint to the new valuevoid
setNearDistance
(float newValue) Set the nearDistance value of this viewpointprotected void
setOrientation
(float[] dir) Convenience method to set the orientation of the viewpoint.protected void
setPosition
(float[] pos) Convenience method to set the position of the viewpoint.void
setRetainUserOffsets
(boolean retainUserOffsets) Set the retainUserOffsets field value of this viewpoint to the new valuevoid
setValue
(int index, boolean value) Set the value of the field at the given index as an boolean.void
setValue
(int index, float value) Set the value of the field at the given index as a float.void
setValue
(int index, float[] value, int numValid) Set the value of the field at the given index as an array of floats.void
Set the value of the field at the given index as a string.void
setViewAll
(boolean viewAll) Set the viewAll field value of this viewpoint to the new valueMethods inherited from class org.web3d.vrml.renderer.common.nodes.BaseBindableNode
addBindableNodeListener, copy, fireIsBoundChanged, getBindTime, getIsBound, getSecondaryType, removeBindableNodeListener, setBind, setOnStack, setVRMLClock
Methods inherited from class org.web3d.vrml.renderer.common.nodes.AbstractNode
addNodeListener, allEventsComplete, checkNodeType, checkSecondaryType, checkSecondaryType, clearRemovedLayerIds, fireFieldChanged, getLayerIds, getMetadataObject, getRefCount, getRemovedLayerIds, getUserData, getVRMLNodeName, hasFieldChanged, isDEF, isSetupFinished, notifyExternProtoLoaded, removeNodeListener, setDEF, setErrorReporter, setFrameStateManager, setMetadataObject, setupFinished, setUserData, 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.nodes.FrameStateListener
allEventsComplete
Methods inherited from interface org.web3d.vrml.nodes.VRMLBindableNodeType
addBindableNodeListener, getBindTime, getIsBound, removeBindableNodeListener, setBind, setOnStack
Methods inherited from interface org.web3d.vrml.lang.VRMLNode
getSecondaryType, 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, setupFinished, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, updateRefCount
-
Field Details
-
FIELD_FIELDOFVIEW
protected static final int FIELD_FIELDOFVIEWIndex of the fieldOfView field- See Also:
-
FIELD_JUMP
protected static final int FIELD_JUMPIndex of the jump field- See Also:
-
FIELD_ORIENTATION
protected static final int FIELD_ORIENTATIONIndex of the orientation field- See Also:
-
FIELD_POSITION
protected static final int FIELD_POSITIONIndex of the position field- See Also:
-
FIELD_DESCRIPTION
protected static final int FIELD_DESCRIPTIONIndex of the description field- See Also:
-
FIELD_CENTEROFROTATION
protected static final int FIELD_CENTEROFROTATIONIndex of the centerOfRotation field- See Also:
-
FIELD_RETAIN_USER_OFFSETS
protected static final int FIELD_RETAIN_USER_OFFSETSIndex of the retainUserOffsets field- See Also:
-
FIELD_VIEWALL
protected static final int FIELD_VIEWALLIndex of the viewAll field- See Also:
-
FIELD_FARDISTANCE
protected static final int FIELD_FARDISTANCEIndex of the farDistance field- See Also:
-
FIELD_NEARDISTANCE
protected static final int FIELD_NEARDISTANCEIndex of the nearDistance field- See Also:
-
LAST_VIEWPOINT_INDEX
protected static final int LAST_VIEWPOINT_INDEXThe last index of the nodes used by the viewpoint- See Also:
-
NUM_FIELDS
protected static final int NUM_FIELDSNumber of fields constant- See Also:
-
vfFieldOfView
protected float vfFieldOfViewSFFloat fieldOfView 0.785398 -
vfJump
protected boolean vfJumpSFBool jump TRUE -
vfRetainUserOffsets
protected boolean vfRetainUserOffsetsSFBool retainUserOffsets FALSE -
vfViewAll
protected boolean vfViewAllSFBool viewAll FALSE -
vfOrientation
protected float[] vfOrientationSFRotation orientation 0 0 1 0 -
vfPosition
protected float[] vfPositionSFVec3f position 0 0 10 -
vfCenterOfRotation
protected float[] vfCenterOfRotationSFVec3f centerOfRotation 0 0 0 -
vfDescription
SFString description "" -
vfFarDistance
protected float vfFarDistanceSFFloat farDistance -1 -
vfNearDistance
protected float vfNearDistanceSFFloat nearDistance -1 -
viewpointListeners
List of those who want to know about role changes, likely 1
-
-
Constructor Details
-
BaseViewpoint
protected BaseViewpoint()Construct a default viewpoint instance -
BaseViewpoint
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
-
addViewpointListener
Add a ViewpointListener.- Specified by:
addViewpointListener
in interfaceVRMLViewpointNodeType
- Parameters:
l
- The listener. Duplicates and nulls are ignored.
-
removeViewpointListener
Remove a ViewpointListener.- Specified by:
removeViewpointListener
in interfaceVRMLViewpointNodeType
- Parameters:
l
- The listener
-
getProjectionType
public int getProjectionType()Get the projection type.- Specified by:
getProjectionType
in interfaceVRMLViewpointNodeType
- Returns:
- The type of projection. One of the PROJECTION_ constants.
-
getFieldOfView
public float[] getFieldOfView()Get the field of view used by this viewpoint. The value returned is an angle that is not less than zero and less than or equal to PI. The number of items in the list is dependent on the Viewpoint type.- Specified by:
getFieldOfView
in interfaceVRMLViewpointNodeType
- Returns:
- The field of view used by this viewpoint
-
setFieldOfView
Set the field of view for this viewpoint. The value must be between zero and pie or an exception will be thrown.- Parameters:
fov
- The new field of view to use- Throws:
InvalidFieldValueException
- The field used is out of range
-
getJump
public boolean getJump()Get the Jump field value of this viewpoint.- Specified by:
getJump
in interfaceVRMLViewpointNodeType
- Returns:
- true if this viewpoint should jump to new positions
-
setJump
public void setJump(boolean jump) Set the jump field value of this viewpoint to the new value- Specified by:
setJump
in interfaceVRMLViewpointNodeType
- Parameters:
jump
- True if the viewpoint should jump to ne positions
-
getRetainUserOffsets
public boolean getRetainUserOffsets()Get the retainUserOffsets field value of this viewpoint.- Specified by:
getRetainUserOffsets
in interfaceVRMLViewpointNodeType
- Returns:
- true if this viewpoint should retainUserOffsets on a bind
-
setRetainUserOffsets
public void setRetainUserOffsets(boolean retainUserOffsets) Set the retainUserOffsets field value of this viewpoint to the new value- Specified by:
setRetainUserOffsets
in interfaceVRMLViewpointNodeType
- Parameters:
retainUserOffsets
- True if the viewpoint should retainUserOffsets on a bind
-
getViewAll
public boolean getViewAll()Get the viewAll field value of this viewpoint.- Specified by:
getViewAll
in interfaceVRMLViewpointNodeType
- Returns:
- true if this viewpoint should viewAll geometry
-
setViewAll
public void setViewAll(boolean viewAll) Set the viewAll field value of this viewpoint to the new value- Specified by:
setViewAll
in interfaceVRMLViewpointNodeType
- Parameters:
viewAll
- True if the viewpoint should viewAll geometry
-
getDescription
Get the description string associated with this viewpoint. If no description is set, this will return null.- Specified by:
getDescription
in interfaceVRMLViewpointNodeType
- Returns:
- The description string of this viewpoint
-
setDescription
Set the description string of this viewpoint. A zero length string or null will clear the currently set description.- Specified by:
setDescription
in interfaceVRMLViewpointNodeType
- Parameters:
desc
- The new description to use
-
getFarDistance
public float getFarDistance()Get the farDistance value associated with this viewpoint.- Returns:
- The value for this viewpoint
-
setFarDistance
public void setFarDistance(float newValue) Set the farDistance value of this viewpoint- Parameters:
newValue
- The new value to use
-
getNearDistance
public float getNearDistance()Get the nearDistance value associated with this viewpoint.- Returns:
- The value for this viewpoint
-
setNearDistance
public void setNearDistance(float newValue) Set the nearDistance value of this viewpoint- Parameters:
newValue
- The new value to use
-
getCenterOfRotation
public float[] getCenterOfRotation()Get the center of rotation defined by this viewpoint. The center of rotation is a point in space relative to the coordinate systems of this node.- Specified by:
getCenterOfRotation
in interfaceVRMLViewpointNodeType
- Returns:
- The position of the center of rotation
-
setCenterOfRotation
Set the center of rotation of this viewpoint. The center is a position in 3-space.- Specified by:
setCenterOfRotation
in interfaceVRMLViewpointNodeType
- Parameters:
pos
- The new position to use- Throws:
InvalidFieldValueException
- The field used is not 3 values
-
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
-
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 classBaseBindableNode
- 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 classBaseBindableNode
- 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, boolean value) throws InvalidFieldException, InvalidFieldValueException Set the value of the field at the given index as an boolean. This would be used to set SFBool field types.- Specified by:
setValue
in interfaceVRMLNodeType
- Overrides:
setValue
in classBaseBindableNode
- Parameters:
index
- The index of destination field to setvalue
- The new value to use for the node- Throws:
InvalidFieldException
- The index does not relate to one of our fieldsInvalidFieldValueException
- The value does not contain an in range value or bad numerical type
-
setValue
public void setValue(int index, float value) throws InvalidFieldException, InvalidFieldValueException Set the value of the field at the given index as a float. This would be used to set SFFloat field types.- Specified by:
setValue
in interfaceVRMLNodeType
- Overrides:
setValue
in classAbstractNode
- Parameters:
index
- The index of destination field to setvalue
- The new value to use for the node- Throws:
InvalidFieldException
- The index does not relate to one of our fieldsInvalidFieldValueException
- The value does not contain an in range value or bad numerical type
-
setValue
public void setValue(int index, float[] value, int numValid) throws InvalidFieldException, InvalidFieldValueException Set the value of the field at the given index as an array of floats. This would be used to set MFFloat, SFVec2f, SFVec3f and SFRotation field types.- Specified by:
setValue
in interfaceVRMLNodeType
- Overrides:
setValue
in classAbstractNode
- Parameters:
index
- The index of destination field to setvalue
- The new value to use for the nodenumValid
- The number of valid values to copy from the array- Throws:
InvalidFieldException
- The index does not relate to one of our fieldsInvalidFieldValueException
- The value does not contain an in range value or bad numerical type
-
setValue
Set the value of the field at the given index as a string. This would be used to set SFString field types.- Specified by:
setValue
in interfaceVRMLNodeType
- Overrides:
setValue
in classAbstractNode
- Parameters:
index
- The index of destination field to setvalue
- The new value to use for the node- Throws:
InvalidFieldException
- The field index is not know
-
setPosition
protected void setPosition(float[] pos) Convenience method to set the position of the viewpoint. Designed to be overridden by derived classes. Make sure you also call this first to set the field values.- Parameters:
pos
- The position vector to use
-
setOrientation
protected void setOrientation(float[] dir) Convenience method to set the orientation of the viewpoint. Designed to be overridden by derived classes. Make sure you also call this first to set the field values.- Parameters:
dir
- The orientation quaternion to use
-
fireCenterOfRotationChanged
protected void fireCenterOfRotationChanged(float[] val) Send a notification to the registered listeners the center of rotation has changed. If no listeners have been registered, then this does nothing, so always call it regardless.- Parameters:
val
- The new center of Rotation
-
fireFieldOfViewChanged
protected void fireFieldOfViewChanged(float[] val) Send a notification to the registered listeners the field of view has changed. If no listeners have been registered, then this does nothing, so always call it regardless.- Parameters:
val
- The new center of Rotation
-