Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btCollisionObject.h @ 7639

Last change on this file since 7639 was 5781, checked in by rgrieder, 15 years ago

Reverted trunk again. We might want to find a way to delete these revisions again (x3n's changes are still available as diff in the commit mails).

  • Property svn:eol-style set to native
File size: 10.7 KB
Line 
1/*
2Bullet Continuous Collision Detection and Physics Library
3Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
4
5This software is provided 'as-is', without any express or implied warranty.
6In no event will the authors be held liable for any damages arising from the use of this software.
7Permission is granted to anyone to use this software for any purpose,
8including commercial applications, and to alter it and redistribute it freely,
9subject to the following restrictions:
10
111. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
122. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
133. This notice may not be removed or altered from any source distribution.
14*/
15
16#ifndef COLLISION_OBJECT_H
17#define COLLISION_OBJECT_H
18
19#include "LinearMath/btTransform.h"
20
21//island management, m_activationState1
22#define ACTIVE_TAG 1
23#define ISLAND_SLEEPING 2
24#define WANTS_DEACTIVATION 3
25#define DISABLE_DEACTIVATION 4
26#define DISABLE_SIMULATION 5
27
28struct  btBroadphaseProxy;
29class   btCollisionShape;
30#include "LinearMath/btMotionState.h"
31#include "LinearMath/btAlignedAllocator.h"
32#include "LinearMath/btAlignedObjectArray.h"
33
34
35typedef btAlignedObjectArray<class btCollisionObject*> btCollisionObjectArray;
36
37
38/// btCollisionObject can be used to manage collision detection objects.
39/// btCollisionObject maintains all information that is needed for a collision detection: Shape, Transform and AABB proxy.
40/// They can be added to the btCollisionWorld.
41ATTRIBUTE_ALIGNED16(class)      btCollisionObject
42{
43
44protected:
45
46        btTransform     m_worldTransform;
47
48        ///m_interpolationWorldTransform is used for CCD and interpolation
49        ///it can be either previous or future (predicted) transform
50        btTransform     m_interpolationWorldTransform;
51        //those two are experimental: just added for bullet time effect, so you can still apply impulses (directly modifying velocities)
52        //without destroying the continuous interpolated motion (which uses this interpolation velocities)
53        btVector3       m_interpolationLinearVelocity;
54        btVector3       m_interpolationAngularVelocity;
55       
56        btVector3               m_anisotropicFriction;
57        bool                            m_hasAnisotropicFriction;
58        btScalar                m_contactProcessingThreshold;   
59
60        btBroadphaseProxy*              m_broadphaseHandle;
61        btCollisionShape*               m_collisionShape;
62       
63        ///m_rootCollisionShape is temporarily used to store the original collision shape
64        ///The m_collisionShape might be temporarily replaced by a child collision shape during collision detection purposes
65        ///If it is NULL, the m_collisionShape is not temporarily replaced.
66        btCollisionShape*               m_rootCollisionShape;
67
68        int                             m_collisionFlags;
69
70        int                             m_islandTag1;
71        int                             m_companionId;
72
73        int                             m_activationState1;
74        btScalar                        m_deactivationTime;
75
76        btScalar                m_friction;
77        btScalar                m_restitution;
78
79        ///users can point to their objects, m_userPointer is not used by Bullet, see setUserPointer/getUserPointer
80        void*                   m_userObjectPointer;
81
82        ///m_internalType is reserved to distinguish Bullet's btCollisionObject, btRigidBody, btSoftBody, btGhostObject etc.
83        ///do not assign your own m_internalType unless you write a new dynamics object class.
84        int                             m_internalType;
85
86        ///time of impact calculation
87        btScalar                m_hitFraction; 
88       
89        ///Swept sphere radius (0.0 by default), see btConvexConvexAlgorithm::
90        btScalar                m_ccdSweptSphereRadius;
91
92        /// Don't do continuous collision detection if the motion (in one step) is less then m_ccdMotionThreshold
93        btScalar                m_ccdMotionThreshold;
94       
95        /// If some object should have elaborate collision filtering by sub-classes
96        bool                    m_checkCollideWith;
97
98        char    m_pad[7];
99
100        virtual bool    checkCollideWithOverride(btCollisionObject* /* co */)
101        {
102                return true;
103        }
104
105public:
106
107        BT_DECLARE_ALIGNED_ALLOCATOR();
108
109        enum CollisionFlags
110        {
111                CF_STATIC_OBJECT= 1,
112                CF_KINEMATIC_OBJECT= 2,
113                CF_NO_CONTACT_RESPONSE = 4,
114                CF_CUSTOM_MATERIAL_CALLBACK = 8,//this allows per-triangle material (friction/restitution)
115                CF_CHARACTER_OBJECT = 16
116        };
117
118        enum    CollisionObjectTypes
119        {
120                CO_COLLISION_OBJECT =1,
121                CO_RIGID_BODY,
122                ///CO_GHOST_OBJECT keeps track of all objects overlapping its AABB and that pass its collision filter
123                ///It is useful for collision sensors, explosion objects, character controller etc.
124                CO_GHOST_OBJECT,
125                CO_SOFT_BODY,
126                CO_HF_FLUID
127        };
128
129        SIMD_FORCE_INLINE bool mergesSimulationIslands() const
130        {
131                ///static objects, kinematic and object without contact response don't merge islands
132                return  ((m_collisionFlags & (CF_STATIC_OBJECT | CF_KINEMATIC_OBJECT | CF_NO_CONTACT_RESPONSE) )==0);
133        }
134
135        const btVector3& getAnisotropicFriction() const
136        {
137                return m_anisotropicFriction;
138        }
139        void    setAnisotropicFriction(const btVector3& anisotropicFriction)
140        {
141                m_anisotropicFriction = anisotropicFriction;
142                m_hasAnisotropicFriction = (anisotropicFriction[0]!=1.f) || (anisotropicFriction[1]!=1.f) || (anisotropicFriction[2]!=1.f);
143        }
144        bool    hasAnisotropicFriction() const
145        {
146                return m_hasAnisotropicFriction;
147        }
148
149        ///the constraint solver can discard solving contacts, if the distance is above this threshold. 0 by default.
150        ///Note that using contacts with positive distance can improve stability. It increases, however, the chance of colliding with degerate contacts, such as 'interior' triangle edges
151        void    setContactProcessingThreshold( btScalar contactProcessingThreshold)
152        {
153                m_contactProcessingThreshold = contactProcessingThreshold;
154        }
155        btScalar        getContactProcessingThreshold() const
156        {
157                return m_contactProcessingThreshold;
158        }
159
160        SIMD_FORCE_INLINE bool          isStaticObject() const {
161                return (m_collisionFlags & CF_STATIC_OBJECT) != 0;
162        }
163
164        SIMD_FORCE_INLINE bool          isKinematicObject() const
165        {
166                return (m_collisionFlags & CF_KINEMATIC_OBJECT) != 0;
167        }
168
169        SIMD_FORCE_INLINE bool          isStaticOrKinematicObject() const
170        {
171                return (m_collisionFlags & (CF_KINEMATIC_OBJECT | CF_STATIC_OBJECT)) != 0 ;
172        }
173
174        SIMD_FORCE_INLINE bool          hasContactResponse() const {
175                return (m_collisionFlags & CF_NO_CONTACT_RESPONSE)==0;
176        }
177
178       
179        btCollisionObject();
180
181        virtual ~btCollisionObject();
182
183        virtual void    setCollisionShape(btCollisionShape* collisionShape)
184        {
185                m_collisionShape = collisionShape;
186                m_rootCollisionShape = collisionShape;
187        }
188
189        SIMD_FORCE_INLINE const btCollisionShape*       getCollisionShape() const
190        {
191                return m_collisionShape;
192        }
193
194        SIMD_FORCE_INLINE btCollisionShape*     getCollisionShape()
195        {
196                return m_collisionShape;
197        }
198
199        SIMD_FORCE_INLINE const btCollisionShape*       getRootCollisionShape() const
200        {
201                return m_rootCollisionShape;
202        }
203
204        SIMD_FORCE_INLINE btCollisionShape*     getRootCollisionShape()
205        {
206                return m_rootCollisionShape;
207        }
208
209        ///Avoid using this internal API call
210        ///internalSetTemporaryCollisionShape is used to temporary replace the actual collision shape by a child collision shape.
211        void    internalSetTemporaryCollisionShape(btCollisionShape* collisionShape)
212        {
213                m_collisionShape = collisionShape;
214        }
215
216        SIMD_FORCE_INLINE       int     getActivationState() const { return m_activationState1;}
217       
218        void setActivationState(int newState);
219
220        void    setDeactivationTime(btScalar time)
221        {
222                m_deactivationTime = time;
223        }
224        btScalar        getDeactivationTime() const
225        {
226                return m_deactivationTime;
227        }
228
229        void forceActivationState(int newState);
230
231        void    activate(bool forceActivation = false);
232
233        SIMD_FORCE_INLINE bool isActive() const
234        {
235                return ((getActivationState() != ISLAND_SLEEPING) && (getActivationState() != DISABLE_SIMULATION));
236        }
237
238        void    setRestitution(btScalar rest)
239        {
240                m_restitution = rest;
241        }
242        btScalar        getRestitution() const
243        {
244                return m_restitution;
245        }
246        void    setFriction(btScalar frict)
247        {
248                m_friction = frict;
249        }
250        btScalar        getFriction() const
251        {
252                return m_friction;
253        }
254
255        ///reserved for Bullet internal usage
256        int     getInternalType() const
257        {
258                return m_internalType;
259        }
260
261        btTransform&    getWorldTransform()
262        {
263                return m_worldTransform;
264        }
265
266        const btTransform&      getWorldTransform() const
267        {
268                return m_worldTransform;
269        }
270
271        void    setWorldTransform(const btTransform& worldTrans)
272        {
273                m_worldTransform = worldTrans;
274        }
275
276
277        SIMD_FORCE_INLINE btBroadphaseProxy*    getBroadphaseHandle()
278        {
279                return m_broadphaseHandle;
280        }
281
282        SIMD_FORCE_INLINE const btBroadphaseProxy*      getBroadphaseHandle() const
283        {
284                return m_broadphaseHandle;
285        }
286
287        void    setBroadphaseHandle(btBroadphaseProxy* handle)
288        {
289                m_broadphaseHandle = handle;
290        }
291
292
293        const btTransform&      getInterpolationWorldTransform() const
294        {
295                return m_interpolationWorldTransform;
296        }
297
298        btTransform&    getInterpolationWorldTransform()
299        {
300                return m_interpolationWorldTransform;
301        }
302
303        void    setInterpolationWorldTransform(const btTransform&       trans)
304        {
305                m_interpolationWorldTransform = trans;
306        }
307
308        void    setInterpolationLinearVelocity(const btVector3& linvel)
309        {
310                m_interpolationLinearVelocity = linvel;
311        }
312
313        void    setInterpolationAngularVelocity(const btVector3& angvel)
314        {
315                m_interpolationAngularVelocity = angvel;
316        }
317
318        const btVector3&        getInterpolationLinearVelocity() const
319        {
320                return m_interpolationLinearVelocity;
321        }
322
323        const btVector3&        getInterpolationAngularVelocity() const
324        {
325                return m_interpolationAngularVelocity;
326        }
327
328        SIMD_FORCE_INLINE int getIslandTag() const
329        {
330                return  m_islandTag1;
331        }
332
333        void    setIslandTag(int tag)
334        {
335                m_islandTag1 = tag;
336        }
337
338        SIMD_FORCE_INLINE int getCompanionId() const
339        {
340                return  m_companionId;
341        }
342
343        void    setCompanionId(int id)
344        {
345                m_companionId = id;
346        }
347
348        SIMD_FORCE_INLINE btScalar                      getHitFraction() const
349        {
350                return m_hitFraction; 
351        }
352
353        void    setHitFraction(btScalar hitFraction)
354        {
355                m_hitFraction = hitFraction;
356        }
357
358       
359        SIMD_FORCE_INLINE int   getCollisionFlags() const
360        {
361                return m_collisionFlags;
362        }
363
364        void    setCollisionFlags(int flags)
365        {
366                m_collisionFlags = flags;
367        }
368       
369        ///Swept sphere radius (0.0 by default), see btConvexConvexAlgorithm::
370        btScalar                        getCcdSweptSphereRadius() const
371        {
372                return m_ccdSweptSphereRadius;
373        }
374
375        ///Swept sphere radius (0.0 by default), see btConvexConvexAlgorithm::
376        void    setCcdSweptSphereRadius(btScalar radius)
377        {
378                m_ccdSweptSphereRadius = radius;
379        }
380
381        btScalar        getCcdMotionThreshold() const
382        {
383                return m_ccdMotionThreshold;
384        }
385
386        btScalar        getCcdSquareMotionThreshold() const
387        {
388                return m_ccdMotionThreshold*m_ccdMotionThreshold;
389        }
390
391
392
393        /// Don't do continuous collision detection if the motion (in one step) is less then m_ccdMotionThreshold
394        void    setCcdMotionThreshold(btScalar ccdMotionThreshold)
395        {
396                m_ccdMotionThreshold = ccdMotionThreshold*ccdMotionThreshold;
397        }
398
399        ///users can point to their objects, userPointer is not used by Bullet
400        void*   getUserPointer() const
401        {
402                return m_userObjectPointer;
403        }
404       
405        ///users can point to their objects, userPointer is not used by Bullet
406        void    setUserPointer(void* userPointer)
407        {
408                m_userObjectPointer = userPointer;
409        }
410
411
412        inline bool checkCollideWith(btCollisionObject* co)
413        {
414                if (m_checkCollideWith)
415                        return checkCollideWithOverride(co);
416
417                return true;
418        }
419};
420
421#endif //COLLISION_OBJECT_H
Note: See TracBrowser for help on using the repository browser.