Class BaseRigidBodyCollection
java.lang.Object
org.web3d.vrml.renderer.common.nodes.AbstractNode
org.web3d.vrml.renderer.common.nodes.rigidphysics.BaseRigidBodyCollection
- All Implemented Interfaces:
VRMLNode
,FrameStateListener
,VRMLChildNodeType
,VRMLNodeType
,VRMLRigidBodyGroupNodeType
,VRMLWorldRootChildNodeType
- Direct Known Subclasses:
NRRigidBodyCollection
,OGLRigidBodyCollection
public class BaseRigidBodyCollection
extends AbstractNode
implements VRMLRigidBodyGroupNodeType, VRMLChildNodeType
Implementation of the RigidBodyCollection node.
In this implementation, the sets of nodes for the bodies and geometry are not expected to change much, if at all. As such, arrays are used to represent the field values, rather than the more customary ArrayList that other classes use for MFNode fields The X3D definition of RigidBody is:
RigidBodyCollection : X3DChildNode { MFNode [in] set_contacts [Contact] SFBool [in,out] autoDisable FALSE MFNode [in,out] bodies [] [RigidBody] SFFloat [in,out] contactSurfaceThickness 0 [0,∞) SFFloat [in,out] disableAngularSpeed 0 [0,∞) SFFloat [in,out] disableLinearSpeed 0 [0,∞) SFFloat [in,out] disableTime 0 [0,∞) SFBool [in,out] enabled TRUE SFFloat [in,out] errorCorrectionFactor 0 [0,1] SFVec3f [in,out] gravity 0 -9.8 0 SFInt32 [in,out] iterations 10 [0,∞) MFNode [in,out] joints [] [X3DRigidJointNode] SFFloat [in,out] maxCorrectionSpeed -1 [0,∞) or -1 SFNode [in,out] metadata NULL [X3DMetadataObject] SFBool [in,out] preferAccuracy FALSE }
- Version:
- $Revision: 1.14 $
- Author:
- Justin Couch
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final String
Message for when the node in setValue() is not a Contactprotected static final String
Message for when the proto is not a Bodyprotected static final String
Message for when the node in setValue() is not a primitiveprotected static final String
Message for when the node in setValue() is not a primitiveprotected static final String
Message for when the node in setValue() is not a Contactprotected static final String
Message for when the proto is not a Bodyprotected static final String
Message when the stopBounce value is out of rangeprotected static final String
Message when the stopBounce value is out of rangeprotected static final int
The field index for autoDisableprotected static final int
The field index for bodiesprotected static final int
The field index for colliderprotected static final int
The field index for constantForceMixprotected static final int
The field index for contactSurfaceThicknessprotected static final int
The field index for disableAngularSpeedprotected static final int
The field index for disableLinearSpeedprotected static final int
The field index for disableTimeprotected static final int
The field index for enabledprotected static final int
The field index for errorCorrectionprotected static final int
The field index for gravityprotected static final int
The field index for iterationsprotected static final int
The field index for jointsprotected static final int
The field index for maxCorrectionVelocityprotected static final int
The field index for preferAccuracyprotected static final int
The field index for set_contactsprotected static final String
protected static final String
protected static final int
Last index used by this collection nodeprotected static final String
Message when the constantForceMix is negativeprotected static final String
Message when the errorCorrection is negativeprotected static final String
Message when the iterations are negativeprotected static final String
Message when the contactSurfaceThickness is negativeprotected int
The number of valid bodies to useprotected int
The number of valid values in vfJointsprotected VRMLProtoInstance
The proto version of vfColliderprotected boolean
The value of the autoDisable fieldprotected VRMLNodeType[]
The value of the bodies fieldprotected VRMLNBodyGroupNodeType
The value of the collider fieldprotected float
The value of the constantForceMix fieldprotected float
The value of the contactSurfaceThickness fieldprotected float
The value of the disableAngularSpeed fieldprotected float
The value of the disableLinearSpeed fieldprotected float
The value of the disableTime fieldprotected boolean
The value of the enabled fieldprotected float
The value of the errorCorrection fieldprotected float[]
The value of the gravity fieldprotected int
The value of the iterations fieldprotected VRMLNodeType[]
The value of the joints fieldprotected float
The value of the maxCorrectionSpeed fieldprotected boolean
The value of the preferAccuracy fieldprotected List
<BaseContact> Values set for set_contacts input eventFields 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 default RigidBodyCollection node object.Construct a new instance of this node based on the details from the given node. -
Method Summary
Modifier and TypeMethodDescriptionvoid
delete()
This node is about to be deleted due to a change in loaded world.void
Instruct the group node to evaluate itself right now based on the given time delta from the last time this was evaluated.Get the body list, provides a live reference not a copy.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.void
getGravity
(float[] gravity) Get the current gravity vector applying to this collection.Get the joint list, provides a live reference not a copy.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.boolean
Is this group enabled for use right now?int
Get the number of valid bodies that this body has as sub objects.int
Get the number of valid joints that this collection has.void
Go through the list of input contacts, process them and send them off to ODE.void
sendRoute
(double time, int srcIndex, VRMLNodeType destNode, int destIndex) Send a routed value from this node to the given destination node.void
setBodies
(VRMLNodeType[] bodies, int numValid) Set the collection of RigidBody nodes that this body should manage.void
setCollider
(VRMLNodeType coll) Set the node that should be used to represent the collider collection.void
setGravity
(float[] gravity) Set the global gravity direction for this collection.void
setJoints
(VRMLNodeType[] joints, int numValid) Set the collection of Joint nodes that this collection should manage.void
setTimestep
(float deltaT) Adjust the model's timestep to the new value (in seconds).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 single boolean.void
setValue
(int index, float value) Set the value of the field at the given index as a single 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
setValue
(int index, int value) Set the value of the field at the given index as a single boolean.void
setValue
(int index, VRMLNodeType child) Set the value of the field at the given index as a node.void
setValue
(int index, VRMLNodeType[] children, int numValid) Set the value of the field at the given index as a node.void
Update everything from ODE, back into the node fields.void
updateRefCount
(int layer, boolean add) Change the reference count up or down by one.Methods inherited from class org.web3d.vrml.renderer.common.nodes.AbstractNode
addNodeListener, allEventsComplete, checkNodeType, checkSecondaryType, checkSecondaryType, clearRemovedLayerIds, fireFieldChanged, getLayerIds, getMetadataObject, getRefCount, getRemovedLayerIds, getSecondaryType, getUserData, getVRMLNodeName, hasFieldChanged, isDEF, isSetupFinished, notifyExternProtoLoaded, removeNodeListener, setDEF, setErrorReporter, setFrameStateManager, setMetadataObject, setUserData, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setVersion, throwInitOnlyWriteException, throwInputOnlyWriteException, throwInvalidNodeException, throwInvalidProtoException, throwOutputOnlyWriteException, 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.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, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue
-
Field Details
-
FIELD_SET_CONTACTS
protected static final int FIELD_SET_CONTACTSThe field index for set_contacts- See Also:
-
FIELD_AUTO_DISABLE
protected static final int FIELD_AUTO_DISABLEThe field index for autoDisable- See Also:
-
FIELD_BODIES
protected static final int FIELD_BODIESThe field index for bodies- See Also:
-
FIELD_CONSTANT_FORCE_MIX
protected static final int FIELD_CONSTANT_FORCE_MIXThe field index for constantForceMix- See Also:
-
FIELD_CONTACT_SURFACE_THICKNESS
protected static final int FIELD_CONTACT_SURFACE_THICKNESSThe field index for contactSurfaceThickness- See Also:
-
FIELD_DISABLE_ANGULAR_SPEED
protected static final int FIELD_DISABLE_ANGULAR_SPEEDThe field index for disableAngularSpeed- See Also:
-
FIELD_DISABLE_LINEAR_SPEED
protected static final int FIELD_DISABLE_LINEAR_SPEEDThe field index for disableLinearSpeed- See Also:
-
FIELD_DISABLE_TIME
protected static final int FIELD_DISABLE_TIMEThe field index for disableTime- See Also:
-
FIELD_ENABLED
protected static final int FIELD_ENABLEDThe field index for enabled- See Also:
-
FIELD_ERROR_CORRECTION
protected static final int FIELD_ERROR_CORRECTIONThe field index for errorCorrection- See Also:
-
FIELD_GRAVITY
protected static final int FIELD_GRAVITYThe field index for gravity- See Also:
-
FIELD_ITERATIONS
protected static final int FIELD_ITERATIONSThe field index for iterations- See Also:
-
FIELD_JOINTS
protected static final int FIELD_JOINTSThe field index for joints- See Also:
-
FIELD_MAX_CORRECTION_SPEED
protected static final int FIELD_MAX_CORRECTION_SPEEDThe field index for maxCorrectionVelocity- See Also:
-
FIELD_PREFER_ACCURACY
protected static final int FIELD_PREFER_ACCURACYThe field index for preferAccuracy- See Also:
-
FIELD_COLLIDER
protected static final int FIELD_COLLIDERThe field index for collider- See Also:
-
LAST_COLLECTION_INDEX
protected static final int LAST_COLLECTION_INDEXLast index used by this collection node- See Also:
-
BODY_PROTO_MSG
-
BODY_NODE_MSG
Message for when the node in setValue() is not a Contact- See Also:
-
CONTACT_PROTO_MSG
-
CONTACT_NODE_MSG
Message for when the node in setValue() is not a Contact- See Also:
-
COLL_PROTO_MSG
Message for when the node in setValue() is not a primitive- See Also:
-
COLL_NODE_MSG
Message for when the node in setValue() is not a primitive- See Also:
-
INVALID_BODY_NODE_MSG
- See Also:
-
INVALID_JOINT_NODE_MSG
- See Also:
-
DIS_ANG_VEL_RANGE_MSG
Message when the stopBounce value is out of range- See Also:
-
DIS_LIN_VEL_RANGE_MSG
Message when the stopBounce value is out of range- See Also:
-
NEG_SURFACE_MSG
Message when the contactSurfaceThickness is negative- See Also:
-
NEG_ERR_CORR_MSG
Message when the errorCorrection is negative- See Also:
-
NEG_ITERATIONS_MSG
-
NEG_CFM_MSG
-
vfSetContacts
Values set for set_contacts input event -
vfAutoDisable
protected boolean vfAutoDisableThe value of the autoDisable field -
vfContactSurfaceThickness
protected float vfContactSurfaceThicknessThe value of the contactSurfaceThickness field -
vfConstantForceMix
protected float vfConstantForceMixThe value of the constantForceMix field -
vfBodies
The value of the bodies field -
numBodies
protected int numBodiesThe number of valid bodies to use -
vfDisableTime
protected float vfDisableTimeThe value of the disableTime field -
vfDisableAngularSpeed
protected float vfDisableAngularSpeedThe value of the disableAngularSpeed field -
vfDisableLinearSpeed
protected float vfDisableLinearSpeedThe value of the disableLinearSpeed field -
vfEnabled
protected boolean vfEnabledThe value of the enabled field -
vfErrorCorrection
protected float vfErrorCorrectionThe value of the errorCorrection field -
vfGravity
protected float[] vfGravityThe value of the gravity field -
vfIterations
protected int vfIterationsThe value of the iterations field -
vfJoints
The value of the joints field -
numJoints
protected int numJointsThe number of valid values in vfJoints -
vfMaxCorrectionSpeed
protected float vfMaxCorrectionSpeedThe value of the maxCorrectionSpeed field -
vfPreferAccuracy
protected boolean vfPreferAccuracyThe value of the preferAccuracy field -
vfCollider
The value of the collider field -
pCollider
The proto version of vfCollider
-
-
Constructor Details
-
BaseRigidBodyCollection
public BaseRigidBodyCollection()Construct a new default RigidBodyCollection node object. -
BaseRigidBodyCollection
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
-
processInputContacts
public void processInputContacts()Go through the list of input contacts, process them and send them off to ODE.- Specified by:
processInputContacts
in interfaceVRMLRigidBodyGroupNodeType
-
setTimestep
public void setTimestep(float deltaT) Adjust the model's timestep to the new value (in seconds). This is called periodically to adjust the timestep made based on the current frame rate to adjust the model.- Specified by:
setTimestep
in interfaceVRMLRigidBodyGroupNodeType
- Parameters:
deltaT
- The time change in seconds
-
evaluateModel
public void evaluateModel()Instruct the group node to evaluate itself right now based on the given time delta from the last time this was evaluated.- Specified by:
evaluateModel
in interfaceVRMLRigidBodyGroupNodeType
-
delete
public void delete()This node is about to be deleted due to a change in loaded world. Clear up the ODE resources in use.- Specified by:
delete
in interfaceVRMLRigidBodyGroupNodeType
-
updatePostSimulation
public void updatePostSimulation()Update everything from ODE, back into the node fields. This is done at the start of the next frame so that all the events, listeners etc fire at the right time in the event model.- Specified by:
updatePostSimulation
in interfaceVRMLRigidBodyGroupNodeType
-
isEnabled
public boolean isEnabled()Is this group enabled for use right now?- Specified by:
isEnabled
in interfaceVRMLRigidBodyGroupNodeType
- Returns:
- true if this is enabled
-
setGravity
public void setGravity(float[] gravity) Set the global gravity direction for this collection.- Specified by:
setGravity
in interfaceVRMLRigidBodyGroupNodeType
- Parameters:
gravity
- An array of 3 values for the gravity vector
-
getGravity
public void getGravity(float[] gravity) Get the current gravity vector applying to this collection.- Specified by:
getGravity
in interfaceVRMLRigidBodyGroupNodeType
- Parameters:
gravity
- An array to copy the values into
-
numJoints
public int numJoints()Get the number of valid joints that this collection has.- Specified by:
numJoints
in interfaceVRMLRigidBodyGroupNodeType
- Returns:
- A number greater than or equal to zero
-
getJoints
Get the joint list, provides a live reference not a copy. The number of valid values is available from numJoints();- Specified by:
getJoints
in interfaceVRMLRigidBodyGroupNodeType
- Returns:
- An array of VRMLNodeTypes
-
setJoints
Set the collection of Joint nodes that this collection should manage. If passed a zero for numValid this method will remove all current values.- Specified by:
setJoints
in interfaceVRMLRigidBodyGroupNodeType
- Parameters:
joints
- Array of new joint node instances to usenumValid
- The number of valid values to get from the array- Throws:
InvalidFieldValueException
- one of the provided nodes is not a X3DRigidJointNode instance
-
numBodies
public int numBodies()Get the number of valid bodies that this body has as sub objects.- Specified by:
numBodies
in interfaceVRMLRigidBodyGroupNodeType
- Returns:
- A number greater than or equal to zero
-
getBodies
Get the body list, provides a live reference not a copy. The number of valid values is available from numBodies();- Specified by:
getBodies
in interfaceVRMLRigidBodyGroupNodeType
- Returns:
- An array of VRMLNodeTypes
-
setBodies
Set the collection of RigidBody nodes that this body should manage. If passed a zero for numValid this method will remove all current values.- Specified by:
setBodies
in interfaceVRMLRigidBodyGroupNodeType
- Parameters:
bodies
- Array of new joint node instances to usenumValid
- The number of valid values to get from the array- Throws:
InvalidFieldValueException
- one of the provided nodes is not a X3DRigidBodyNode instance
-
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
-
updateRefCount
public void updateRefCount(int layer, boolean add) Change the reference count up or down by one.- Specified by:
updateRefCount
in interfaceVRMLNodeType
- Overrides:
updateRefCount
in classAbstractNode
- Parameters:
layer
- The id of the layer to modify the ref count onadd
- true to increment the reference count, false to decrement
-
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 classAbstractNode
- 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, boolean value) throws InvalidFieldValueException, InvalidFieldException Set the value of the field at the given index as a single boolean. This would be used to set SFBool 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 knowInvalidFieldValueException
- The value provided is not in range or not appropriate for this field
-
setValue
Set the value of the field at the given index as a single boolean. This would be used to set SFInt32 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 knowInvalidFieldValueException
- The value provided is not in range or not appropriate for this field
-
setValue
public void setValue(int index, float value) throws InvalidFieldValueException, InvalidFieldException Set the value of the field at the given index as a single 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 field index is not knownInvalidFieldValueException
- The value provided is not in range or not appropriate for this field
-
setValue
public void setValue(int index, float[] value, int numValid) throws InvalidFieldValueException, InvalidFieldException Set the value of the field at the given index as an array of floats. This would be used to set MFFloat, SFVec3f etc 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 items to use from the array- Throws:
InvalidFieldException
- The field index is not knowInvalidFieldValueException
- The value provided is not in range or not appropriate for this field
-
setValue
public void setValue(int index, VRMLNodeType child) throws InvalidFieldValueException, InvalidFieldException Set the value of the field at the given index as a node. This would be used to set SFNode field types.- Specified by:
setValue
in interfaceVRMLNodeType
- Overrides:
setValue
in classAbstractNode
- Parameters:
index
- The index of destination field to setchild
- The new value to use for the node- Throws:
InvalidFieldException
- The field index is not knowInvalidFieldValueException
- The value provided does not fit this type of node
-
setValue
public void setValue(int index, VRMLNodeType[] children, int numValid) throws InvalidFieldValueException, InvalidFieldException Set the value of the field at the given index as a node. This would be used to set SFNode field types.- Specified by:
setValue
in interfaceVRMLNodeType
- Overrides:
setValue
in classAbstractNode
- Parameters:
index
- The index of destination field to setchildren
- The new value to use for the nodenumValid
- The number of valid items to use from the array- Throws:
InvalidFieldException
- The field index is not knowInvalidFieldValueException
- The value provided does not fit this type of node
-
setCollider
Set the node that should be used to represent the collider collection. Setting a value of null will clear the current model in use and return the system to a spherical model.- Parameters:
coll
- The new instance to use or null- Throws:
InvalidFieldValueException
- This was not a valid node type
-