HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SIM_Impacts Class Reference

#include <SIM_Impacts.h>

+ Inheritance diagram for SIM_Impacts:

Public Member Functions

int getNumImpacts () const
 Get the number of contacts. More...
 
const UT_Vector3getPosition (int index) const
 
const UT_Vector3getNormal (int index) const
 
fpreal getImpulse (int index) const
 Get the collision impulse. More...
 
void setImpulse (int index, fpreal impulse)
 Set the collision impulse. More...
 
void removeLastImpact ()
 Remove the last impact. More...
 
int getFlags (int index) const
 Get flags associated with the impact. More...
 
GA_Index getPointNumber (int index) const
 
int getPrimitiveNumber (int index) const
 
fpreal getPrimitiveU (int index) const
 Get the u coordinate of the primitive where the impact occurred. More...
 
fpreal getPrimitiveV (int index) const
 Get the v coordinate of the primitive where the impact occurred. More...
 
fpreal getPrimitiveW (int index) const
 Get the w coordinate of the primitive where the impact occurred. More...
 
int getOtherObjId (int index) const
 Get the unique id of the other object involved in a contact. More...
 
int getOtherObjPointNumber (int index) const
 
int getOtherObjPrimitiveNumber (int index) const
 
fpreal getOtherObjPrimitiveU (int index) const
 
fpreal getOtherObjPrimitiveV (int index) const
 
fpreal getOtherObjPrimitiveW (int index) const
 
SIM_Time getTime (int index) const
 Get the estimated time of the collision. More...
 
void addPositionImpact (const UT_Vector3 &pos, const UT_Vector3 &normal, fpreal impulse, int otherobjid, int otherobjptnum, int otherobjprimnum, fpreal otherobjprimu, fpreal otherobjprimv, fpreal otherobjprimw, const SIM_Time &time, int flags)
 This function adds a new impact at a position in space. More...
 
void addPointImpact (const UT_Vector3 &pos, const UT_Vector3 &normal, fpreal impulse, int ptnum, int otherobjid, int otherobjptnum, int otherobjprimnum, fpreal otherobjprimu, fpreal otherobjprimv, fpreal otherobjprimw, const SIM_Time &time, int flags)
 
void addPrimitiveImpact (const UT_Vector3 &pos, const UT_Vector3 &normal, fpreal impulse, int primnum, fpreal primu, fpreal primv, fpreal primw, int otherobjid, int otherobjptnum, int otherobjprimnum, fpreal otherobjprimu, fpreal otherobjprimv, fpreal otherobjprimw, const SIM_Time &time, int flags)
 
void mergeImpacts (const SIM_Impacts &src)
 Merge the impacts from another SIM_Impacts data into this one. More...
 
void mergeImpactsInTimeRange (const SIM_Impacts &src, const SIM_Time &startTime, const SIM_Time &endTime)
 
void keepOnlyImpactsForAffectors (const SIM_ObjectArray &affectors, int thisobjectid, int startindex)
 
- Public Member Functions inherited from SIM_Data
const UT_StringHoldergetDataType () const
 
void initialize (const SIM_SubdataBehavior &subdatabehavior)
 
void makeEqual (const SIM_Data *source, const SIM_SubdataBehavior &subdatabehavior)
 
void setParameters (const SIM_Options &parms)
 
void interpolate (const SIM_Data *source1, const SIM_Data *source2, fpreal interp)
 
int64 getMemorySize () const
 
bool getIsAlternateRepresentation () const
 
bool saveToFile (const char *filename, UT_CompressionType compressionType) const
 
bool saveToStream (std::ostream &os, UT_CompressionType compressionType) const
 
void appendFullDataPath (const SIM_Data *subdata, bool useobjectid, UT_String &datapath) const
 
bool loadFromFile (const char *filename)
 
bool loadFromStream (UT_IStream &is, bool skiptype=false)
 
bool getIsOfType (const UT_StringRef &datatype) const
 
const voidgetConstPointerToType (const UT_StringRef &datatype) const
 
voidgetPointerToType (const UT_StringRef &datatype)
 
int getNumSubData () const
 Get the number of sub-data items attached to this data. More...
 
const UT_StringHoldergetSubDataName (int index) const
 Get the name of the sub-data at a particular index location. More...
 
int getSubDataIndex (const SIM_Data *subdata) const
 
bool buildSubDataPath (const SIM_Data *subdata, UT_String &pathto) const
 
const SIM_QuerygetQueryObject () const
 
SIM_OptionsgetUserOptions ()
 
const SIM_OptionsgetConstUserOptions () const
 
long getGuideParmVersion () const
 
void addGuideDep (DEP_MicroNode &src) const
 
virtual bool getGuideGeometryList (const SIM_RootData &root, const char *datapath, const SIM_Time &t, UT_Array< GU_ConstDetailHandle > &detailArray, UT_Array< UT_DMatrix4 > &xformArray) const
 
GU_ConstDetailHandle getGuideGeometry (const SIM_RootData &root, const char *datapath, UT_DMatrix4 &xform, const SIM_Time &t) const
 
void buildGuideOptions (SIM_Options &options, const SIM_Time &time) const
 
SIM_DatagetSubData (int index)
 
const SIM_DatagetConstSubData (int index) const
 
SIM_DatagetNamedSubData (const char *dataname)
 
const SIM_DatagetConstNamedSubData (const char *dataname) const
 
void filterSubData (SIM_DataArray &ncdp, UT_StringArray *names, const SIM_DataFilter &ncfilter, const char *startfrom, const SIM_DataFilter &recursefilter)
 
void filterConstSubData (SIM_ConstDataArray &dp, UT_StringArray *names, const SIM_DataFilter &filter, const char *startfrom, const SIM_DataFilter &recurseFilter) const
 
SIM_DatagetNthSubData (UT_String *name, const SIM_DataFilter &filter, int n, const char *startfrom, const SIM_DataFilter &recurseFilter)
 
const SIM_DatagetNthConstSubData (UT_String *name, const SIM_DataFilter &filter, int n, const char *startfrom, const SIM_DataFilter &recurseFilter) const
 
void forEachSubData (SIM_EachDataCallback &cb, const SIM_DataFilter &filter, const char *startfrom, const SIM_DataFilter &recurseFilter)
 
void forEachConstSubData (SIM_EachDataCallback &cb, const SIM_DataFilter &filter, const char *startfrom, const SIM_DataFilter &recurseFilter) const
 
SIM_DatacreateNamedSubData (const char *dataname, const char *datatype, int creationflags, UT_String *newdatanameptr=NULL)
 
SIM_DatagetOrCreateAlternateRepresentation (const char *dataname, const char *datatype) const
 
void interpolateSubData (const SIM_Data &source1, const SIM_Data &source2, fpreal interp, const SIM_DataFilter &interpdata, const SIM_DataFilter &recurse)
 
void setNamedSubData (const char *dataname, const SIM_Data *data, int setflags)
 
void createUniqueSubDataName (const SIM_Data *subdata, UT_String &dataname) const
 
void removeNamedSubData (const char *dataname)
 Remove some existing sub-data by name. More...
 
void removeSubData (int index)
 Remove some existing sub-data by index. More...
 
void moveNamedSubData (const char *oldname, const char *newname)
 
const UT_GuidgetUniqueId () const
 
long getReferenceCount () const
 
int getCreatorId () const
 Get the ID of the node that created this data. More...
 
OP_NodegetCreatorNode () const
 Use the creator ID to look up the OP_Node that created this data. More...
 
OP_NodegetOwnerNetwork () const
 Look up the owner node of our engine to get the DOP Network pointer. More...
 
const SIM_EnginegetEngine () const
 Get the engine that created us (from our data factory). More...
 
int getCreatorIndex () const
 Get the output index of the creator node that generated this data. More...
 
const SIM_TimegetCreationTime () const
 Get the creation time for this data. More...
 
bool getIsSelected () const
 Get the selected flag for this data. More...
 
void setIsSelected (bool selected) const
 
bool getSelectionRepresentsObject () const
 
void copyCreationInfoFrom (const SIM_Data *source)
 
OP_NodegetNodePathsRelativeTo () const
 
OP_NodegetOPNode (const char *path, bool addinterest) const
 Given a path relative to our creator node, return an OBJ_Node. More...
 
OBJ_NodegetOBJNode (const char *path, bool addinterest) const
 Given a path relative to our creator node, return an OBJ_Node. More...
 
SOP_NodegetSOPNode (const char *path, bool addinterest) const
 Given a path relative to our creator node, return a SOP_Node. More...
 
DOP_NodegetDOPNode (const char *path, bool addinterest) const
 Given a path relative to our creator node, return a DOP_Node. More...
 
COP2_NodegetCOP2Node (const char *path, bool addinterest) const
 Given a path relative to our creator node, return a COP2_Node. More...
 
CHOP_NodegetCHOPNode (const char *path, bool addinterest) const
 Given a path relative to our creator node, return a CHOP_Node. More...
 
void addOPInterest (OP_Node *node) const
 Adds an interest in the specified node to our engine's owner node. More...
 
void addError (const SIM_RootData *root, int errorcode, const char *errorparm, UT_ErrorSeverity severity) const
 Adds an error to our SIM_Engine. More...
 
void makeMemberDataUnique ()
 
virtual void makeMemberDataUniqueSubclass ()
 

Static Public Member Functions

static UT_Vector3 getRequiredImpulse (const UT_Vector3 &worldspacepos, const UT_Vector3 &nml, const SIM_Object *obja, GA_Index ptnuma, bool objainfinitemass, const SIM_Object *objb, GA_Index ptnumb, bool objbinfinitemass, fpreal bounce, fpreal friction, fpreal dynamicfrictionmultiplier, fpreal bounceforward, bool usesdfvelocitya=false, bool usepointvelocitya=true, bool usesdfvelocityb=false, bool usepointvelocityb=true)
 
static UT_Vector3 getRequiredImpulse (const UT_DMatrix3 &Ka, const UT_Vector3 &vela, const UT_Vector3 &worldspacepos, const UT_Vector3 &nml, const SIM_Object *objb, GA_Index ptnumb, bool objbinfinitemass, fpreal bounce, fpreal friction, fpreal dynamicfrictionmultiplier, fpreal bounceforward, bool usesdfvelocityb=false, bool usepointvelocityb=true)
 
static UT_Vector3 getRequiredImpulse (const UT_Vector3 &desiredrelvel, const UT_DMatrix3 &Ka, const UT_Vector3 &vela, const UT_DMatrix3 &Kb, const UT_Vector3 &velb, const UT_Vector3 &worldspacepos, const UT_Vector3 &nml, fpreal friction, fpreal dynamicfrictionmultiplier, fpreal bounceforward)
 
static void splitImpulse (const UT_Vector3 &impulse, const UT_Vector3 &normal, fpreal &normalImpulseLength, UT_Vector3 &tangentImpulse)
 Split an impulse into normal and tangential (friction) components. More...
 
- Static Public Member Functions inherited from SIM_Data
static bool getDataTypeFromFile (const char *filename, UT_String &datatype)
 
static bool getDataTypeFromStream (UT_IStream &is, UT_String &datatype)
 
static const voidcastConstPointerToType (const SIM_Data *data, const UT_StringRef &datatype)
 
static voidcastPointerToType (SIM_Data *data, const UT_StringRef &datatype)
 

Protected Member Functions

 SIM_Impacts (const SIM_DataFactory *factory)
 The SIM_Impacts constructor. More...
 
 ~SIM_Impacts () override
 The SIM_Impacts destructor. More...
 
void initializeSubclass () override
 Clears out all contact information. More...
 
void makeEqualSubclass (const SIM_Data *source) override
 Copies the contact information from another SIM_Impacts. More...
 
void saveSubclass (std::ostream &os) const override
 Saves the contact information to a stream. More...
 
bool loadSubclass (UT_IStream &is) override
 Loads contact information from a stream. More...
 
int64 getMemorySizeSubclass () const override
 Returns the total memory used by this object. More...
 
SIM_QuerycreateQueryObjectSubclass () const override
 Creates a SIM_QueryArrays object to treat impact as a record. More...
 
void resizeArrays (int numimpacts)
 
void removeImpact (int index)
 
- Protected Member Functions inherited from SIM_Data
 SIM_Data (const SIM_DataFactory *factory)
 
virtual ~SIM_Data ()
 
void handleModification (int code=-1)
 
void setNeedsToRecalculateMemorySize () const
 
void deleteQueryObjectIfNotBuilding () const
 Deletes the query object for this data, if there is one. More...
 
void deleteGuideObjectIfNotBuilding () const
 Delete the guide geometry for this data, if it exists. More...
 
void initAlternateRepresentation () const
 
void setNeedsInitialization (bool needsinit) const
 Flags an alternate representation subdata as requiring initialization. More...
 
bool getNeedsInitialization () const
 Tests whether an alternate representation requires initialization. More...
 
bool saveOptionPacket (std::ostream &os, const char *name, const SIM_Options *opts) const
 
bool loadOptionPacket (UT_IStream &is, const char *name, SIM_Options *opts) const
 
bool getIsDoingSimplifiedSaveLoad () const
 
void initializeFromParmDefaults ()
 
void setSelectionRepresentsObject (bool representsobject)
 
virtual void setNeedsInitializationSubclass (bool needsinit) const
 
virtual void saveIOSubclass (std::ostream &os, SIM_DataThreadedIO *io) const
 
virtual bool loadIOSubclass (UT_IStream &is, SIM_DataThreadedIO *io)
 
virtual long getGuideParmVersionSubclass () const
 
virtual SIM_GuidecreateGuideObjectSubclass () const
 
virtual void buildGuideGeometrySubclass (const SIM_RootData &root, const SIM_Options &options, const GU_DetailHandle &gdh, UT_DMatrix4 *xform, const SIM_Time &t) const
 
virtual void setParametersSubclass (const SIM_Options &parms)
 
virtual void setNamedSubDataSubclass (const char *dataname, const SIM_Data *data)
 
virtual void removeNamedSubDataSubclass (const char *dataname)
 
virtual void interpolateSubclass (const SIM_Data *source1, const SIM_Data *source2, fpreal interp)
 
virtual void handleModificationSubclass (int code)
 
virtual bool getIsAlternateRepresentationSubclass () const
 
virtual void initAlternateRepresentationSubclass (const SIM_Data &)
 
virtual voidgetCastToType (const UT_StringRef &datatype) const
 
virtual const UT_StringHoldergetDataTypeSubclass () const
 
const SIM_DatagetAlternateRepresentationOf () const
 

Additional Inherited Members

- Static Protected Member Functions inherited from SIM_Data
static const PRM_TemplategetEmptyTemplateList ()
 
static const SIM_DopDescriptiongetEmptyDopDescription ()
 A DOP description that says not to create an automatic DOP. More...
 
static void getDataTypeSuperclasses (UT_StringArray &)
 

Detailed Description

This class defines a SIM_Data subclass for holding collision information. Each contact is represented by a position in simulation space, a normal to the collision surface, the ids of the objects involved in the contact, and the strength of the impact impulse. Optionally, a friction impulse can also be included with the impact.

Remember your basic physics and the definition of "impulse": I = F * dt = m * dv

Definition at line 85 of file SIM_Impacts.h.

Constructor & Destructor Documentation

SIM_Impacts::SIM_Impacts ( const SIM_DataFactory factory)
explicitprotected

The SIM_Impacts constructor.

SIM_Impacts::~SIM_Impacts ( )
overrideprotected

The SIM_Impacts destructor.

Member Function Documentation

void SIM_Impacts::addPointImpact ( const UT_Vector3 pos,
const UT_Vector3 normal,
fpreal  impulse,
int  ptnum,
int  otherobjid,
int  otherobjptnum,
int  otherobjprimnum,
fpreal  otherobjprimu,
fpreal  otherobjprimv,
fpreal  otherobjprimw,
const SIM_Time time,
int  flags 
)

This function adds a new impact at a position in space and associates it with a particular point.

void SIM_Impacts::addPositionImpact ( const UT_Vector3 pos,
const UT_Vector3 normal,
fpreal  impulse,
int  otherobjid,
int  otherobjptnum,
int  otherobjprimnum,
fpreal  otherobjprimu,
fpreal  otherobjprimv,
fpreal  otherobjprimw,
const SIM_Time time,
int  flags 
)

This function adds a new impact at a position in space.

void SIM_Impacts::addPrimitiveImpact ( const UT_Vector3 pos,
const UT_Vector3 normal,
fpreal  impulse,
int  primnum,
fpreal  primu,
fpreal  primv,
fpreal  primw,
int  otherobjid,
int  otherobjptnum,
int  otherobjprimnum,
fpreal  otherobjprimu,
fpreal  otherobjprimv,
fpreal  otherobjprimw,
const SIM_Time time,
int  flags 
)

This function adds a new impact at a position in space and associates it with a particular primitive and UV coordinate.

SIM_Query* SIM_Impacts::createQueryObjectSubclass ( ) const
overrideprotectedvirtual

Creates a SIM_QueryArrays object to treat impact as a record.

Reimplemented from SIM_Data.

int SIM_Impacts::getFlags ( int  index) const

Get flags associated with the impact.

fpreal SIM_Impacts::getImpulse ( int  index) const

Get the collision impulse.

int64 SIM_Impacts::getMemorySizeSubclass ( ) const
overrideprotectedvirtual

Returns the total memory used by this object.

Reimplemented from SIM_Data.

const UT_Vector3& SIM_Impacts::getNormal ( int  index) const

Get the normal for a particular contact, pointing away from the first object. This value generally represents the normal of the surface at the point of contact. This value is used to determine the direction of the impact force at this contact point.

int SIM_Impacts::getNumImpacts ( ) const

Get the number of contacts.

int SIM_Impacts::getOtherObjId ( int  index) const

Get the unique id of the other object involved in a contact.

int SIM_Impacts::getOtherObjPointNumber ( int  index) const

Get the point number on the other object involved in the collision. This function may return -1 if the point number is unknown.

int SIM_Impacts::getOtherObjPrimitiveNumber ( int  index) const

Get the primitive number on the other object involved in the collision. This function may return -1 if the primitive number is unknown.

fpreal SIM_Impacts::getOtherObjPrimitiveU ( int  index) const

Get the u coordinate of the primitive where the impact occurred on the other object.

fpreal SIM_Impacts::getOtherObjPrimitiveV ( int  index) const

Get the v coordinate of the primitive where the impact occurred on the other object.

fpreal SIM_Impacts::getOtherObjPrimitiveW ( int  index) const

Get the w coordinate of the primitive where the impact occurred on the other object.

GA_Index SIM_Impacts::getPointNumber ( int  index) const

Get the point number involved in the collision. This function may return -1 if the point number is unknown.

const UT_Vector3& SIM_Impacts::getPosition ( int  index) const

Get the position for a particular contact. The position is stored in simulation space.

int SIM_Impacts::getPrimitiveNumber ( int  index) const

Get the primitive number involved in the collision. This function may return -1 if the primitive number is unknown.

fpreal SIM_Impacts::getPrimitiveU ( int  index) const

Get the u coordinate of the primitive where the impact occurred.

fpreal SIM_Impacts::getPrimitiveV ( int  index) const

Get the v coordinate of the primitive where the impact occurred.

fpreal SIM_Impacts::getPrimitiveW ( int  index) const

Get the w coordinate of the primitive where the impact occurred.

static UT_Vector3 SIM_Impacts::getRequiredImpulse ( const UT_Vector3 worldspacepos,
const UT_Vector3 nml,
const SIM_Object obja,
GA_Index  ptnuma,
bool  objainfinitemass,
const SIM_Object objb,
GA_Index  ptnumb,
bool  objbinfinitemass,
fpreal  bounce,
fpreal  friction,
fpreal  dynamicfrictionmultiplier,
fpreal  bounceforward,
bool  usesdfvelocitya = false,
bool  usepointvelocitya = true,
bool  usesdfvelocityb = false,
bool  usepointvelocityb = true 
)
static

Calculates the impulses that should be applied on objects a and b. The resulting velocity of the specified points on the two objects after applying the impulse should be (-relvel * bounce). Either or both of obja and objb can be null in which case the mass of those objects is considered to be infinite. The ptnum values can be -1 if the world space position should be used to fetch the impulse mass matrix. The dynamicfrictionmultiplier is multiplied by the friction value to get the dynamic friction value. The returned impulse should be applied equally to both objects. Note that the returned impulse may have a normal different than nml. The normal of the returned impulse should be used, as the impact normal, not the original nml. Otherwise the impulse magnitude will be wrong. Also, the output normal properly accounts for friction. However, the returned normal direction will be in the same hemisphere as the passed in normal, so it can be used directly as the impact normal for object a (the passed in normal is the normal on objb).

static UT_Vector3 SIM_Impacts::getRequiredImpulse ( const UT_DMatrix3 Ka,
const UT_Vector3 vela,
const UT_Vector3 worldspacepos,
const UT_Vector3 nml,
const SIM_Object objb,
GA_Index  ptnumb,
bool  objbinfinitemass,
fpreal  bounce,
fpreal  friction,
fpreal  dynamicfrictionmultiplier,
fpreal  bounceforward,
bool  usesdfvelocityb = false,
bool  usepointvelocityb = true 
)
static
static UT_Vector3 SIM_Impacts::getRequiredImpulse ( const UT_Vector3 desiredrelvel,
const UT_DMatrix3 Ka,
const UT_Vector3 vela,
const UT_DMatrix3 Kb,
const UT_Vector3 velb,
const UT_Vector3 worldspacepos,
const UT_Vector3 nml,
fpreal  friction,
fpreal  dynamicfrictionmultiplier,
fpreal  bounceforward 
)
static
SIM_Time SIM_Impacts::getTime ( int  index) const

Get the estimated time of the collision.

void SIM_Impacts::initializeSubclass ( )
overrideprotectedvirtual

Clears out all contact information.

Reimplemented from SIM_Data.

void SIM_Impacts::keepOnlyImpactsForAffectors ( const SIM_ObjectArray affectors,
int  thisobjectid,
int  startindex 
)

This is a very special-purpose function used by SIM_Engine. It removes any impacts that are self-impacts or that involve other objects that are not in the supplied object array. It starts the search for removal at the supplied index. This is used to eliminate impact data during feedback iteration so that we don't end up multiply applying impacts on non-feedback objects.

bool SIM_Impacts::loadSubclass ( UT_IStream is)
overrideprotectedvirtual

Loads contact information from a stream.

Reimplemented from SIM_Data.

void SIM_Impacts::makeEqualSubclass ( const SIM_Data source)
overrideprotectedvirtual

Copies the contact information from another SIM_Impacts.

Reimplemented from SIM_Data.

void SIM_Impacts::mergeImpacts ( const SIM_Impacts src)

Merge the impacts from another SIM_Impacts data into this one.

void SIM_Impacts::mergeImpactsInTimeRange ( const SIM_Impacts src,
const SIM_Time startTime,
const SIM_Time endTime 
)

Merge only the impacts in the given time range. This is useful for feedback and substepping: it allows merging of feedback impacts from the fullstep end object to a substep object.

void SIM_Impacts::removeImpact ( int  index)
protected

Remove a impact! O(n) operation. This is protected because the use of this method is discouraged.

void SIM_Impacts::removeLastImpact ( )

Remove the last impact.

void SIM_Impacts::resizeArrays ( int  numimpacts)
protected

Helper method for the loadSubclass method to resize all of our member variable arrays.

void SIM_Impacts::saveSubclass ( std::ostream &  os) const
overrideprotectedvirtual

Saves the contact information to a stream.

Reimplemented from SIM_Data.

void SIM_Impacts::setImpulse ( int  index,
fpreal  impulse 
)

Set the collision impulse.

static void SIM_Impacts::splitImpulse ( const UT_Vector3 impulse,
const UT_Vector3 normal,
fpreal normalImpulseLength,
UT_Vector3 tangentImpulse 
)
static

Split an impulse into normal and tangential (friction) components.


The documentation for this class was generated from the following file: