123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565 |
- #ifndef BT_COLLISION_OBJECT_H
- #define BT_COLLISION_OBJECT_H
- #include "bullet/LinearMath/btTransform.h"
- #define ACTIVE_TAG 1
- #define ISLAND_SLEEPING 2
- #define WANTS_DEACTIVATION 3
- #define DISABLE_DEACTIVATION 4
- #define DISABLE_SIMULATION 5
- struct btBroadphaseProxy;
- class btCollisionShape;
- struct btCollisionShapeData;
- #include "bullet/LinearMath/btMotionState.h"
- #include "bullet/LinearMath/btAlignedAllocator.h"
- #include "bullet/LinearMath/btAlignedObjectArray.h"
- typedef btAlignedObjectArray<class btCollisionObject*> btCollisionObjectArray;
- #ifdef BT_USE_DOUBLE_PRECISION
- #define btCollisionObjectData btCollisionObjectDoubleData
- #define btCollisionObjectDataName "btCollisionObjectDoubleData"
- #else
- #define btCollisionObjectData btCollisionObjectFloatData
- #define btCollisionObjectDataName "btCollisionObjectFloatData"
- #endif
- ATTRIBUTE_ALIGNED16(class) btCollisionObject
- {
- protected:
- btTransform m_worldTransform;
-
-
- btTransform m_interpolationWorldTransform;
-
-
- btVector3 m_interpolationLinearVelocity;
- btVector3 m_interpolationAngularVelocity;
-
- btVector3 m_anisotropicFriction;
- int m_hasAnisotropicFriction;
- btScalar m_contactProcessingThreshold;
- btBroadphaseProxy* m_broadphaseHandle;
- btCollisionShape* m_collisionShape;
-
- void* m_extensionPointer;
-
-
-
-
- btCollisionShape* m_rootCollisionShape;
- int m_collisionFlags;
- int m_islandTag1;
- int m_companionId;
- mutable int m_activationState1;
- mutable btScalar m_deactivationTime;
- btScalar m_friction;
- btScalar m_restitution;
- btScalar m_rollingFriction;
-
-
- int m_internalType;
-
- union
- {
- void* m_userObjectPointer;
- int m_userIndex;
- };
-
- btScalar m_hitFraction;
-
-
- btScalar m_ccdSweptSphereRadius;
-
- btScalar m_ccdMotionThreshold;
-
-
- int m_checkCollideWith;
-
- int m_updateRevision;
- virtual bool checkCollideWithOverride(const btCollisionObject* ) const
- {
- return true;
- }
- public:
- BT_DECLARE_ALIGNED_ALLOCATOR();
- enum CollisionFlags
- {
- CF_STATIC_OBJECT= 1,
- CF_KINEMATIC_OBJECT= 2,
- CF_NO_CONTACT_RESPONSE = 4,
- CF_CUSTOM_MATERIAL_CALLBACK = 8,
- CF_CHARACTER_OBJECT = 16,
- CF_DISABLE_VISUALIZE_OBJECT = 32,
- CF_DISABLE_SPU_COLLISION_PROCESSING = 64
- };
- enum CollisionObjectTypes
- {
- CO_COLLISION_OBJECT =1,
- CO_RIGID_BODY=2,
-
-
- CO_GHOST_OBJECT=4,
- CO_SOFT_BODY=8,
- CO_HF_FLUID=16,
- CO_USER_TYPE=32,
- CO_FEATHERSTONE_LINK=64
- };
- enum AnisotropicFrictionFlags
- {
- CF_ANISOTROPIC_FRICTION_DISABLED=0,
- CF_ANISOTROPIC_FRICTION = 1,
- CF_ANISOTROPIC_ROLLING_FRICTION = 2
- };
- SIMD_FORCE_INLINE bool mergesSimulationIslands() const
- {
-
- return ((m_collisionFlags & (CF_STATIC_OBJECT | CF_KINEMATIC_OBJECT | CF_NO_CONTACT_RESPONSE) )==0);
- }
- const btVector3& getAnisotropicFriction() const
- {
- return m_anisotropicFriction;
- }
- void setAnisotropicFriction(const btVector3& anisotropicFriction, int frictionMode = CF_ANISOTROPIC_FRICTION)
- {
- m_anisotropicFriction = anisotropicFriction;
- bool isUnity = (anisotropicFriction[0]!=1.f) || (anisotropicFriction[1]!=1.f) || (anisotropicFriction[2]!=1.f);
- m_hasAnisotropicFriction = isUnity?frictionMode : 0;
- }
- bool hasAnisotropicFriction(int frictionMode = CF_ANISOTROPIC_FRICTION) const
- {
- return (m_hasAnisotropicFriction&frictionMode)!=0;
- }
-
-
- void setContactProcessingThreshold( btScalar contactProcessingThreshold)
- {
- m_contactProcessingThreshold = contactProcessingThreshold;
- }
- btScalar getContactProcessingThreshold() const
- {
- return m_contactProcessingThreshold;
- }
- SIMD_FORCE_INLINE bool isStaticObject() const {
- return (m_collisionFlags & CF_STATIC_OBJECT) != 0;
- }
- SIMD_FORCE_INLINE bool isKinematicObject() const
- {
- return (m_collisionFlags & CF_KINEMATIC_OBJECT) != 0;
- }
- SIMD_FORCE_INLINE bool isStaticOrKinematicObject() const
- {
- return (m_collisionFlags & (CF_KINEMATIC_OBJECT | CF_STATIC_OBJECT)) != 0 ;
- }
- SIMD_FORCE_INLINE bool hasContactResponse() const {
- return (m_collisionFlags & CF_NO_CONTACT_RESPONSE)==0;
- }
-
- btCollisionObject();
- virtual ~btCollisionObject();
- virtual void setCollisionShape(btCollisionShape* collisionShape)
- {
- m_updateRevision++;
- m_collisionShape = collisionShape;
- m_rootCollisionShape = collisionShape;
- }
- SIMD_FORCE_INLINE const btCollisionShape* getCollisionShape() const
- {
- return m_collisionShape;
- }
- SIMD_FORCE_INLINE btCollisionShape* getCollisionShape()
- {
- return m_collisionShape;
- }
-
-
-
-
- void* internalGetExtensionPointer() const
- {
- return m_extensionPointer;
- }
-
-
- void internalSetExtensionPointer(void* pointer)
- {
- m_extensionPointer = pointer;
- }
- SIMD_FORCE_INLINE int getActivationState() const { return m_activationState1;}
-
- void setActivationState(int newState) const;
- void setDeactivationTime(btScalar time)
- {
- m_deactivationTime = time;
- }
- btScalar getDeactivationTime() const
- {
- return m_deactivationTime;
- }
- void forceActivationState(int newState) const;
- void activate(bool forceActivation = false) const;
- SIMD_FORCE_INLINE bool isActive() const
- {
- return ((getActivationState() != ISLAND_SLEEPING) && (getActivationState() != DISABLE_SIMULATION));
- }
- void setRestitution(btScalar rest)
- {
- m_updateRevision++;
- m_restitution = rest;
- }
- btScalar getRestitution() const
- {
- return m_restitution;
- }
- void setFriction(btScalar frict)
- {
- m_updateRevision++;
- m_friction = frict;
- }
- btScalar getFriction() const
- {
- return m_friction;
- }
- void setRollingFriction(btScalar frict)
- {
- m_updateRevision++;
- m_rollingFriction = frict;
- }
- btScalar getRollingFriction() const
- {
- return m_rollingFriction;
- }
-
- int getInternalType() const
- {
- return m_internalType;
- }
- btTransform& getWorldTransform()
- {
- return m_worldTransform;
- }
- const btTransform& getWorldTransform() const
- {
- return m_worldTransform;
- }
- void setWorldTransform(const btTransform& worldTrans)
- {
- m_updateRevision++;
- m_worldTransform = worldTrans;
- }
- SIMD_FORCE_INLINE btBroadphaseProxy* getBroadphaseHandle()
- {
- return m_broadphaseHandle;
- }
- SIMD_FORCE_INLINE const btBroadphaseProxy* getBroadphaseHandle() const
- {
- return m_broadphaseHandle;
- }
- void setBroadphaseHandle(btBroadphaseProxy* handle)
- {
- m_broadphaseHandle = handle;
- }
- const btTransform& getInterpolationWorldTransform() const
- {
- return m_interpolationWorldTransform;
- }
- btTransform& getInterpolationWorldTransform()
- {
- return m_interpolationWorldTransform;
- }
- void setInterpolationWorldTransform(const btTransform& trans)
- {
- m_updateRevision++;
- m_interpolationWorldTransform = trans;
- }
- void setInterpolationLinearVelocity(const btVector3& linvel)
- {
- m_updateRevision++;
- m_interpolationLinearVelocity = linvel;
- }
- void setInterpolationAngularVelocity(const btVector3& angvel)
- {
- m_updateRevision++;
- m_interpolationAngularVelocity = angvel;
- }
- const btVector3& getInterpolationLinearVelocity() const
- {
- return m_interpolationLinearVelocity;
- }
- const btVector3& getInterpolationAngularVelocity() const
- {
- return m_interpolationAngularVelocity;
- }
- SIMD_FORCE_INLINE int getIslandTag() const
- {
- return m_islandTag1;
- }
- void setIslandTag(int tag)
- {
- m_islandTag1 = tag;
- }
- SIMD_FORCE_INLINE int getCompanionId() const
- {
- return m_companionId;
- }
- void setCompanionId(int id)
- {
- m_companionId = id;
- }
- SIMD_FORCE_INLINE btScalar getHitFraction() const
- {
- return m_hitFraction;
- }
- void setHitFraction(btScalar hitFraction)
- {
- m_hitFraction = hitFraction;
- }
-
- SIMD_FORCE_INLINE int getCollisionFlags() const
- {
- return m_collisionFlags;
- }
- void setCollisionFlags(int flags)
- {
- m_collisionFlags = flags;
- }
-
-
- btScalar getCcdSweptSphereRadius() const
- {
- return m_ccdSweptSphereRadius;
- }
-
- void setCcdSweptSphereRadius(btScalar radius)
- {
- m_ccdSweptSphereRadius = radius;
- }
- btScalar getCcdMotionThreshold() const
- {
- return m_ccdMotionThreshold;
- }
- btScalar getCcdSquareMotionThreshold() const
- {
- return m_ccdMotionThreshold*m_ccdMotionThreshold;
- }
-
- void setCcdMotionThreshold(btScalar ccdMotionThreshold)
- {
- m_ccdMotionThreshold = ccdMotionThreshold;
- }
-
- void* getUserPointer() const
- {
- return m_userObjectPointer;
- }
- int getUserIndex() const
- {
- return m_userIndex;
- }
-
- void setUserPointer(void* userPointer)
- {
- m_userObjectPointer = userPointer;
- }
-
- void setUserIndex(int index)
- {
- m_userIndex = index;
- }
- int getUpdateRevisionInternal() const
- {
- return m_updateRevision;
- }
- inline bool checkCollideWith(const btCollisionObject* co) const
- {
- if (m_checkCollideWith)
- return checkCollideWithOverride(co);
- return true;
- }
- virtual int calculateSerializeBufferSize() const;
-
- virtual const char* serialize(void* dataBuffer, class btSerializer* serializer) const;
- virtual void serializeSingleObject(class btSerializer* serializer) const;
- };
- struct btCollisionObjectDoubleData
- {
- void *m_broadphaseHandle;
- void *m_collisionShape;
- btCollisionShapeData *m_rootCollisionShape;
- char *m_name;
- btTransformDoubleData m_worldTransform;
- btTransformDoubleData m_interpolationWorldTransform;
- btVector3DoubleData m_interpolationLinearVelocity;
- btVector3DoubleData m_interpolationAngularVelocity;
- btVector3DoubleData m_anisotropicFriction;
- double m_contactProcessingThreshold;
- double m_deactivationTime;
- double m_friction;
- double m_rollingFriction;
- double m_restitution;
- double m_hitFraction;
- double m_ccdSweptSphereRadius;
- double m_ccdMotionThreshold;
- int m_hasAnisotropicFriction;
- int m_collisionFlags;
- int m_islandTag1;
- int m_companionId;
- int m_activationState1;
- int m_internalType;
- int m_checkCollideWith;
- char m_padding[4];
- };
- struct btCollisionObjectFloatData
- {
- void *m_broadphaseHandle;
- void *m_collisionShape;
- btCollisionShapeData *m_rootCollisionShape;
- char *m_name;
- btTransformFloatData m_worldTransform;
- btTransformFloatData m_interpolationWorldTransform;
- btVector3FloatData m_interpolationLinearVelocity;
- btVector3FloatData m_interpolationAngularVelocity;
- btVector3FloatData m_anisotropicFriction;
- float m_contactProcessingThreshold;
- float m_deactivationTime;
- float m_friction;
- float m_rollingFriction;
- float m_restitution;
- float m_hitFraction;
- float m_ccdSweptSphereRadius;
- float m_ccdMotionThreshold;
- int m_hasAnisotropicFriction;
- int m_collisionFlags;
- int m_islandTag1;
- int m_companionId;
- int m_activationState1;
- int m_internalType;
- int m_checkCollideWith;
- char m_padding[4];
- };
- SIMD_FORCE_INLINE int btCollisionObject::calculateSerializeBufferSize() const
- {
- return sizeof(btCollisionObjectData);
- }
- #endif
|