Class BaseRigidBody
java.lang.Object
org.web3d.vrml.renderer.common.nodes.AbstractNode
org.web3d.vrml.renderer.common.nodes.rigidphysics.BaseRigidBody
- All Implemented Interfaces:
VRMLNode,FrameStateListener,VRMLNodeType,VRMLRigidBodyNodeType
- Direct Known Subclasses:
NRRigidBody,OGLRigidBody
Implementation of the RigidBody 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:
RigidBody : X3DNode {
SFVec3f [in,out] angularVelocity 0 0 0
SFBool [in,out] autoDisable FALSE
SFVec3f [in,out] centerOfMass 0 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
SFVec3f [in,out] finiteRotationAxis 0 0 0
SFBool [in,out] fixed FALSE
MFVec3f [in,out] forces []
MFNode [in,out] geometry [] [X3DNBodyCollidableNode]
SFMatrix3f [in,out] inertia 1 0 0 0 1 0 0 0 1
SFVec3f [in,out] linearVelocity 0 0 0
SFFloat [in,out] mass 1 (0,∞)
SFNode [in,out] massDensityModel NULL [Sphere, Box, Cone]
SFNode [in,out] metadata NULL [X3DMetadataObject]
SFRotation [in,out] orientation 0 0 1 0 [0,1]
SFVec3f [in,out] position 0 0 0 (-∞,∞)
MFVec3f [in,out] torques []
SFBool [in,out] useFiniteRotation FALSE
SFBool [in,out] useGlobalGravity TRUE
}
- Version:
- $Revision: 1.12 $
- Author:
- Justin Couch
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final StringMessage when the stopBounce value is out of rangeprotected static final StringMessage when the stopBounce value is out of rangeprotected static final intThe field index for angularDampingFactorprotected static final intThe field index for angularVelocityprotected static final intThe field index for autoDampprotected static final intThe field index for autoDisableprotected static final intThe field index for centerOfMassprotected static final intThe field index for disableAngularSpeedprotected static final intThe field index for disableLinearSpeedprotected static final intThe field index for disableTimeprotected static final intThe field index for enabledprotected static final intThe field index for finiteRotationAxisprotected static final intThe field index for forcesprotected static final intThe field index for geometryprotected static final intThe field index for inertiaprotected static final intThe field index for linearDampingFactorprotected static final intThe field index for linearVelocityprotected static final intThe field index for massprotected static final intThe field index for massDensityModelprotected static final intThe field index for orientationprotected static final intThe field index for positionprotected static final intThe field index for torquesprotected static final intThe field index for useFiniteRotationprotected static final intThe field index for useGlobalGravityprotected static final Stringprotected static final Stringprotected static final intLast index used by this rigid body nodeprotected static final StringMessage for when the node in setValue() is not a primitiveprotected static final StringMessage for when the node in setValue() is not a primitiveprotected static final StringMessage for when the proto for mass density is not a primitiveprotected static final StringMessage for when the proto for mass density is not a primitiveprotected static final StringWhen the mass value is non-positive, provide this valueprotected intThe number of valid values in vfForcesprotected intThe number of valid values in vfGeometryprotected intThe number of valid values in the inertia matrixprotected intThe number of valid values in vfTorquesprotected VRMLProtoInstanceThe proto version of vfMassDensityModelprotected floatThe value of the angularDampingFactor fieldprotected float[]The value of the angularVelocity fieldprotected booleanThe value of the autoDamp fieldprotected booleanThe value of the autoDisable fieldprotected float[]The value of the centerOfMass fieldprotected floatThe value of the disableAngularSpeed fieldprotected floatThe value of the disableLinearSpeed fieldprotected floatThe value of the disableTime fieldprotected booleanThe value of the enabled fieldprotected float[]The value of the finiteRotationAxis fieldprotected float[]The value of the forces fieldprotected VRMLNodeType[]The value of the geometry fieldprotected float[]The value of the inertia matrix fieldprotected floatThe value of the linearDampingFactor fieldprotected float[]The value of the linearVelocity fieldprotected floatThe value of the mass fieldprotected VRMLGeometryNodeTypeThe value of the massDensityModel fieldprotected float[]The value of the orientation fieldprotected float[]The value of the position fieldprotected float[]The value of the torques fieldprotected booleanThe value of the useFiniteRotation fieldprotected booleanThe value of the useGlobalGravity fieldFields 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 RigidBody node object.BaseRigidBody(VRMLNodeType node) Construct a new instance of this node based on the details from the given node. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddGeometry(VRMLNodeType node) Add a geometry node to the list for this body during setup.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.Get the geometry list, provides a live reference not a copy.Fetch the reference to the node that represents the mass density model.int[]Get the list of indices that correspond to fields that contain nodes ie MFNode and SFNode).intGet the number of fields.org.odejava.BodyGet the ODE object that represents the odeBody to evaluate.intGet the primary type of this node.intGet the number of valid geometry that this odeBody has as sub objects.voidsendRoute(double time, int srcIndex, VRMLNodeType destNode, int destIndex) Send a routed value from this node to the given destination node.voidsetGeometry(VRMLNodeType[] geometry, int numValid) Set the collection of geometry nodes that this odeBody should use to render the main scene transformation.voidSet the node that should be used to represent the mass density model.voidsetODEWorld(org.odejava.World wld) Set the parent world that this odeBody belongs to.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 single boolean.voidsetValue(int index, float value) Set the value of the field at the given index as a single float.voidsetValue(int index, float[] value, int numValid) Set the value of the field at the given index as an array of floats.voidsetValue(int index, VRMLNodeType child) Set the value of the field at the given index as a node.voidsetValue(int index, VRMLNodeType[] children, int numValid) Set the value of the field at the given index as a node.voidUpdate the local fields after the physics model has been evaluated.voidUpdate any pre-evaluation values for the body.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, 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.nodes.FrameStateListener
allEventsCompleteMethods inherited from interface org.web3d.vrml.lang.VRMLNode
getSecondaryType, 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, updateRefCount
-
Field Details
-
FIELD_ANGULAR_DAMPING_FACTOR
protected static final int FIELD_ANGULAR_DAMPING_FACTORThe field index for angularDampingFactor- See Also:
-
FIELD_ANGULAR_VELOCITY
protected static final int FIELD_ANGULAR_VELOCITYThe field index for angularVelocity- See Also:
-
FIELD_AUTO_DAMP
protected static final int FIELD_AUTO_DAMPThe field index for autoDamp- See Also:
-
FIELD_AUTO_DISABLE
protected static final int FIELD_AUTO_DISABLEThe field index for autoDisable- See Also:
-
FIELD_CENTER_OF_MASS
protected static final int FIELD_CENTER_OF_MASSThe field index for centerOfMass- See Also:
-
FIELD_DISABLE_TIME
protected static final int FIELD_DISABLE_TIMEThe field index for disableTime- 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_ENABLED
protected static final int FIELD_ENABLEDThe field index for enabled- See Also:
-
FIELD_FINITE_ROTATION_AXIS
protected static final int FIELD_FINITE_ROTATION_AXISThe field index for finiteRotationAxis- See Also:
-
FIELD_FORCES
protected static final int FIELD_FORCESThe field index for forces- See Also:
-
FIELD_GEOMETRY
protected static final int FIELD_GEOMETRYThe field index for geometry- See Also:
-
FIELD_INERTIA
protected static final int FIELD_INERTIAThe field index for inertia- See Also:
-
FIELD_LINEAR_DAMPING_FACTOR
protected static final int FIELD_LINEAR_DAMPING_FACTORThe field index for linearDampingFactor- See Also:
-
FIELD_LINEAR_VELOCITY
protected static final int FIELD_LINEAR_VELOCITYThe field index for linearVelocity- See Also:
-
FIELD_MASS
protected static final int FIELD_MASSThe field index for mass- See Also:
-
FIELD_MASS_DENSITY_MODEL
protected static final int FIELD_MASS_DENSITY_MODELThe field index for massDensityModel- See Also:
-
FIELD_ORIENTATION
protected static final int FIELD_ORIENTATIONThe field index for orientation- See Also:
-
FIELD_POSITION
protected static final int FIELD_POSITIONThe field index for position- See Also:
-
FIELD_TORQUES
protected static final int FIELD_TORQUESThe field index for torques- See Also:
-
FIELD_USE_FINITE_ROTATION
protected static final int FIELD_USE_FINITE_ROTATIONThe field index for useFiniteRotation- See Also:
-
FIELD_USE_GLOBAL_GRAVITY
protected static final int FIELD_USE_GLOBAL_GRAVITYThe field index for useGlobalGravity- See Also:
-
LAST_BODY_INDEX
protected static final int LAST_BODY_INDEXLast index used by this rigid body node- See Also:
-
MASS_TYPE_PROTO_MSG
Message for when the proto for mass density is not a primitive- See Also:
-
MASS_PROTO_MSG
Message for when the node in setValue() is not a primitive- See Also:
-
MASS_NODE_MSG
Message for when the node in setValue() is not a primitive- See Also:
-
MASS_TYPE_MSG
Message for when the proto for mass density is not a primitive- See Also:
-
GEOM_NODE_MSG
- See Also:
-
GEOM_PROTO_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_MASS_MSG
When the mass value is non-positive, provide this value- See Also:
-
vfAngularDampingFactor
protected float vfAngularDampingFactorThe value of the angularDampingFactor field -
vfAngularVelocity
protected float[] vfAngularVelocityThe value of the angularVelocity field -
vfAutoDamp
protected boolean vfAutoDampThe value of the autoDamp field -
vfAutoDisable
protected boolean vfAutoDisableThe value of the autoDisable field -
vfCenterOfMass
protected float[] vfCenterOfMassThe value of the centerOfMass field -
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 -
vfFiniteRotationAxis
protected float[] vfFiniteRotationAxisThe value of the finiteRotationAxis field -
vfForces
protected float[] vfForcesThe value of the forces field -
numForces
protected int numForcesThe number of valid values in vfForces -
vfGeometry
The value of the geometry field -
numGeometry
protected int numGeometryThe number of valid values in vfGeometry -
vfInertia
protected float[] vfInertiaThe value of the inertia matrix field -
numInertia
protected int numInertiaThe number of valid values in the inertia matrix -
vfLinearDampingFactor
protected float vfLinearDampingFactorThe value of the linearDampingFactor field -
vfLinearVelocity
protected float[] vfLinearVelocityThe value of the linearVelocity field -
vfMass
protected float vfMassThe value of the mass field -
vfMassDensityModel
The value of the massDensityModel field -
pMassDensityModel
The proto version of vfMassDensityModel -
vfOrientation
protected float[] vfOrientationThe value of the orientation field -
vfPosition
protected float[] vfPositionThe value of the position field -
vfTorques
protected float[] vfTorquesThe value of the torques field -
numTorques
protected int numTorquesThe number of valid values in vfTorques -
vfUseFiniteRotation
protected boolean vfUseFiniteRotationThe value of the useFiniteRotation field -
vfUseGlobalGravity
protected boolean vfUseGlobalGravityThe value of the useGlobalGravity field
-
-
Constructor Details
-
BaseRigidBody
public BaseRigidBody()Construct a new default RigidBody node object. -
BaseRigidBody
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
-
setODEWorld
public void setODEWorld(org.odejava.World wld) Set the parent world that this odeBody belongs to. A null value clears the world and indicates the physics model is no longer in use.- Specified by:
setODEWorldin interfaceVRMLRigidBodyNodeType- Parameters:
wld- The new world instance to use or null
-
getODEBody
public org.odejava.Body getODEBody()Get the ODE object that represents the odeBody to evaluate.- Specified by:
getODEBodyin interfaceVRMLRigidBodyNodeType- Returns:
- The odeBody object representing this node
-
updateODEFromNode
public void updateODEFromNode()Update any pre-evaluation values for the body. For example, forces applied to the body need to be reset every frame as ODE will zero out force and torque values after every frame.- Specified by:
updateODEFromNodein interfaceVRMLRigidBodyNodeType
-
updateNodeFromODE
public void updateNodeFromODE()Update the local fields after the physics model has been evaluated. For example the position and orientation are most likely to have changed, so these should be read back from ODE and updated in the local fields.- Specified by:
updateNodeFromODEin interfaceVRMLRigidBodyNodeType
-
numGeometry
public int numGeometry()Get the number of valid geometry that this odeBody has as sub objects.- Specified by:
numGeometryin interfaceVRMLRigidBodyNodeType- Returns:
- A number greater than or equal to zero
-
getGeometry
Get the geometry list, provides a live reference not a copy. The number of valid values is available from numGeometry();- Specified by:
getGeometryin interfaceVRMLRigidBodyNodeType- Returns:
- An array of VRMLNodeTypes
-
setGeometry
Set the collection of geometry nodes that this odeBody should use to render the main scene transformation. If passed a zero for numValid this method will remove all current values.Geometry is allowed to be one of the grouping nodes or a shape node type. However, if you provide something like a LOD or Switch, don't expect anything to actually work correctly.
- Specified by:
setGeometryin interfaceVRMLRigidBodyNodeType- Parameters:
geometry- Array of new geometry 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
-
getMassDensityModel
Fetch the reference to the node that represents the mass density model.- Specified by:
getMassDensityModelin interfaceVRMLRigidBodyNodeType- Returns:
- The reference to the node defining the mass model
-
setMassDensityModel
Set the node that should be used to represent the mass density model. Setting a value of null will clear the current model in use and return the system to a spherical model.The valid odeBody nodes are Sphere, Box and Cone.
- Specified by:
setMassDensityModelin interfaceVRMLRigidBodyNodeType- Parameters:
geom- The new instance to use or null- Throws:
InvalidFieldValueException- This was not a valid node type
-
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
-
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 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:
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, 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:
setValuein interfaceVRMLNodeType- Overrides:
setValuein 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:
setValuein interfaceVRMLNodeType- Overrides:
setValuein 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, 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:
setValuein interfaceVRMLNodeType- Overrides:
setValuein 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:
setValuein interfaceVRMLNodeType- Overrides:
setValuein 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:
setValuein interfaceVRMLNodeType- Overrides:
setValuein 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
-
addGeometry
protected void addGeometry(VRMLNodeType node) throws InvalidFieldValueException, InvalidFieldAccessException Add a geometry node to the list for this body during setup. If this is not during setup, bitch loudly.- Parameters:
node- The potential node to check on- Throws:
InvalidFieldValueException- The node was not geometryInvalidFieldAccessException
-