00001 /* 00002 * PROPRIETARY INFORMATION. This software is proprietary to 00003 * Side Effects Software Inc., and is not to be reproduced, 00004 * transmitted, or disclosed in any way without written permission. 00005 * 00006 * Produced by: 00007 * Side Effects Software Inc. 00008 * 477 Richmond Street West, Suite 1001 00009 * Toronto, Ontario 00010 * Canada M5V 3E7 00011 * 416-504-9876 00012 */ 00013 00014 #ifndef __SIM_Collider_h__ 00015 #define __SIM_Collider_h__ 00016 00017 #include "SIM_API.h" 00018 #include "SIM_DataUtils.h" 00019 #include "SIM_OptionsUser.h" 00020 00021 class SIM_Impacts; 00022 class SIM_Object; 00023 class SIM_ObjectArray; 00024 00025 /// This is an abstract base class for all colliders. 00026 /// A collider is any class that takes a pair of objects and generated 00027 /// information about how those two objects intersect. See the 00028 /// SIM_Object::getCollider() function for a description of how a 00029 /// solver should determine the right SIM_Collider class to use for 00030 /// a given pair of objects. 00031 class SIM_API SIM_Collider : public SIM_Data, 00032 public SIM_OptionsUser 00033 { 00034 public: 00035 /// Specifies whether the object and affector need to be reversed to 00036 /// perform collision detection. This flag is useful for colliders that 00037 /// make assumptions about the makeup of the object and affector are 00038 /// in the call to collideObjectsSubclass(). For example, the 00039 /// point collider (SIM_ColliderPoint) always treats the object as 00040 /// a particle system, using ray casting to follow the trajectory of 00041 /// each particle. But suppose an RBD Solver has a particle system 00042 /// as an affector object. The RBD Solver would find that the best 00043 /// collider to use is a point collider. Rather than requiring that 00044 /// the RBD Solver then somehow discover that the particle object must 00045 /// always be sent as the "object" parameter, the collider can have 00046 /// the reverse object roles flag turned on. Then when the RBD Solver 00047 /// calls the collider with the RBD object first and the particle object 00048 /// second, the collider itself will reverse the objects before passing 00049 /// them on to collideObjectSubclass(). 00050 GETSET_DATA_FUNCS_B(SIM_NAME_REVERSEOBJECTROLES, ReverseObjectRoles); 00051 00052 /// Defines the possible affector types when doing collision detection. 00053 typedef enum { 00054 SIM_IMPACTAPPLY_NONE, /// Don't do any collision detection. 00055 SIM_IMPACTAPPLY_ONEWAY, /// Object A gets Impacts from object B. 00056 SIM_IMPACTAPPLY_MUTUAL, /// Object A and B both get Impacts. 00057 SIM_IMPACTAPPLY_FEEDBACK /// Object A gets Impacts, B gets Feedback. 00058 } SIM_ImpactApplyType; 00059 00060 /// Perform the collision detection for a pair of objects. 00061 /// This function calls the collideObjectsSubclass() function. 00062 /// This also attempts to do collision response. 00063 bool collideObjects(SIM_Engine &engine, 00064 SIM_Object &object, 00065 SIM_Object &affector, 00066 const SIM_Time &starttime, 00067 const SIM_Time &endtime, 00068 SIM_ImpactApplyType impactapplytype, 00069 int impactflags) const; 00070 00071 protected: 00072 /// The SIM_Collider constructor. 00073 explicit SIM_Collider(const SIM_DataFactory *factory); 00074 /// The SIM_Collider destructor. 00075 virtual ~SIM_Collider(); 00076 00077 /// Finds or creates the impact data on the affector that is appropriate 00078 /// for the given affector type. It also takes into account the value 00079 /// of the ReverseObjectRoles flag. 00080 SIM_Impacts *getObjectImpactData(SIM_Object &object, 00081 SIM_ImpactApplyType impactapplytype) const; 00082 00083 /// Finds or creates the impact data on the affector that is appropriate 00084 /// for the given affector type. It also takes into account the value 00085 /// of the ReverseObjectRoles flag. 00086 SIM_Impacts *getAffectorImpactData(SIM_Object &affector, 00087 SIM_ImpactApplyType impactapplytype) const; 00088 00089 /// Returns true if the collideObjects function should always be 00090 /// called with the affector object interpolated to the endtime. 00091 /// This function just calls getAffectorInterpolatedToEndTimeSubclass(). 00092 bool getAffectorInterpolatedToEndTime() const; 00093 00094 /// Override this method to implement your custom collision detection. 00095 /// This function can access any data on the main object or affector 00096 /// object. It can also add any extra data structures it needs to the 00097 /// object for efficiency (rather than recalculating the extra data 00098 /// each time this function is called). 00099 virtual bool collideObjectsSubclass(SIM_Engine &engine, 00100 SIM_Object &object, 00101 SIM_Object &affector, 00102 const SIM_Time &starttime, 00103 const SIM_Time &endtime, 00104 SIM_ImpactApplyType impactapplytype, 00105 int impactflags) const; 00106 00107 /// Returns true if the collideObjects function should always be 00108 /// called with the affector object interpolated to the endtime. 00109 /// The default implementation returns true. 00110 virtual bool getAffectorInterpolatedToEndTimeSubclass() const; 00111 00112 private: 00113 DECLARE_STANDARD_GETCASTTOTYPE(); 00114 DECLARE_CLASSNAME(SIM_Collider, SIM_Data); 00115 }; 00116 00117 #endif 00118
1.5.9