Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 2732 was 2662, checked in by rgrieder, 16 years ago

Merged presentation branch back to trunk.

  • Property svn:eol-style set to native
File size: 9.7 KB
RevLine 
[1963]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"
[2430]32#include "LinearMath/btAlignedObjectArray.h"
[1963]33
34
[2430]35typedef btAlignedObjectArray<class btCollisionObject*> btCollisionObjectArray;
[1963]36
[2430]37
[1963]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        btBroadphaseProxy*              m_broadphaseHandle;
56        btCollisionShape*               m_collisionShape;
57       
58        ///m_rootCollisionShape is temporarily used to store the original collision shape
59        ///The m_collisionShape might be temporarily replaced by a child collision shape during collision detection purposes
60        ///If it is NULL, the m_collisionShape is not temporarily replaced.
61        btCollisionShape*               m_rootCollisionShape;
62
63        int                             m_collisionFlags;
64
65        int                             m_islandTag1;
66        int                             m_companionId;
67
68        int                             m_activationState1;
69        btScalar                        m_deactivationTime;
70
71        btScalar                m_friction;
72        btScalar                m_restitution;
73
74        ///users can point to their objects, m_userPointer is not used by Bullet, see setUserPointer/getUserPointer
75        void*                   m_userObjectPointer;
76
[2430]77        ///m_internalType is reserved to distinguish Bullet's btCollisionObject, btRigidBody, btSoftBody, btGhostObject etc.
[1963]78        ///do not assign your own m_internalType unless you write a new dynamics object class.
79        int                             m_internalType;
80
81        ///time of impact calculation
82        btScalar                m_hitFraction; 
83       
84        ///Swept sphere radius (0.0 by default), see btConvexConvexAlgorithm::
85        btScalar                m_ccdSweptSphereRadius;
86
87        /// Don't do continuous collision detection if the motion (in one step) is less then m_ccdMotionThreshold
88        btScalar                m_ccdMotionThreshold;
89       
90        /// If some object should have elaborate collision filtering by sub-classes
91        bool                    m_checkCollideWith;
92
93        char    m_pad[7];
94
95        virtual bool    checkCollideWithOverride(btCollisionObject* /* co */)
96        {
97                return true;
98        }
99
100public:
101
102        BT_DECLARE_ALIGNED_ALLOCATOR();
103
104        enum CollisionFlags
105        {
106                CF_STATIC_OBJECT= 1,
107                CF_KINEMATIC_OBJECT= 2,
108                CF_NO_CONTACT_RESPONSE = 4,
[2430]109                CF_CUSTOM_MATERIAL_CALLBACK = 8,//this allows per-triangle material (friction/restitution)
110                CF_CHARACTER_OBJECT = 16
[1963]111        };
112
113        enum    CollisionObjectTypes
114        {
115                CO_COLLISION_OBJECT =1,
116                CO_RIGID_BODY,
[2430]117                CO_SOFT_BODY,
118                ///CO_GHOST_OBJECT keeps track of all objects overlapping its AABB and that pass its collision filter
119                ///It is useful for collision sensors, explosion objects, character controller etc.
120                CO_GHOST_OBJECT
[1963]121        };
122
123        SIMD_FORCE_INLINE bool mergesSimulationIslands() const
124        {
125                ///static objects, kinematic and object without contact response don't merge islands
126                return  ((m_collisionFlags & (CF_STATIC_OBJECT | CF_KINEMATIC_OBJECT | CF_NO_CONTACT_RESPONSE) )==0);
127        }
128
129
130        SIMD_FORCE_INLINE bool          isStaticObject() const {
131                return (m_collisionFlags & CF_STATIC_OBJECT) != 0;
132        }
133
134        SIMD_FORCE_INLINE bool          isKinematicObject() const
135        {
136                return (m_collisionFlags & CF_KINEMATIC_OBJECT) != 0;
137        }
138
139        SIMD_FORCE_INLINE bool          isStaticOrKinematicObject() const
140        {
141                return (m_collisionFlags & (CF_KINEMATIC_OBJECT | CF_STATIC_OBJECT)) != 0 ;
142        }
143
144        SIMD_FORCE_INLINE bool          hasContactResponse() const {
145                return (m_collisionFlags & CF_NO_CONTACT_RESPONSE)==0;
146        }
147
148       
149        btCollisionObject();
150
151        virtual ~btCollisionObject();
152
153        virtual void    setCollisionShape(btCollisionShape* collisionShape)
154        {
155                m_collisionShape = collisionShape;
156                m_rootCollisionShape = collisionShape;
157        }
158
159        SIMD_FORCE_INLINE const btCollisionShape*       getCollisionShape() const
160        {
161                return m_collisionShape;
162        }
163
164        SIMD_FORCE_INLINE btCollisionShape*     getCollisionShape()
165        {
166                return m_collisionShape;
167        }
168
169        SIMD_FORCE_INLINE const btCollisionShape*       getRootCollisionShape() const
170        {
171                return m_rootCollisionShape;
172        }
173
174        SIMD_FORCE_INLINE btCollisionShape*     getRootCollisionShape()
175        {
176                return m_rootCollisionShape;
177        }
178
179        ///Avoid using this internal API call
180        ///internalSetTemporaryCollisionShape is used to temporary replace the actual collision shape by a child collision shape.
181        void    internalSetTemporaryCollisionShape(btCollisionShape* collisionShape)
182        {
183                m_collisionShape = collisionShape;
184        }
185
[2430]186        SIMD_FORCE_INLINE       int     getActivationState() const { return m_activationState1;}
[1963]187       
188        void setActivationState(int newState);
189
190        void    setDeactivationTime(btScalar time)
191        {
192                m_deactivationTime = time;
193        }
194        btScalar        getDeactivationTime() const
195        {
196                return m_deactivationTime;
197        }
198
199        void forceActivationState(int newState);
200
201        void    activate(bool forceActivation = false);
202
[2430]203        SIMD_FORCE_INLINE bool isActive() const
[1963]204        {
205                return ((getActivationState() != ISLAND_SLEEPING) && (getActivationState() != DISABLE_SIMULATION));
206        }
207
208        void    setRestitution(btScalar rest)
209        {
210                m_restitution = rest;
211        }
212        btScalar        getRestitution() const
213        {
214                return m_restitution;
215        }
216        void    setFriction(btScalar frict)
217        {
218                m_friction = frict;
219        }
220        btScalar        getFriction() const
221        {
222                return m_friction;
223        }
224
225        ///reserved for Bullet internal usage
226        int     getInternalType() const
227        {
228                return m_internalType;
229        }
230
231        btTransform&    getWorldTransform()
232        {
233                return m_worldTransform;
234        }
235
236        const btTransform&      getWorldTransform() const
237        {
238                return m_worldTransform;
239        }
240
241        void    setWorldTransform(const btTransform& worldTrans)
242        {
243                m_worldTransform = worldTrans;
244        }
245
246
[2430]247        SIMD_FORCE_INLINE btBroadphaseProxy*    getBroadphaseHandle()
[1963]248        {
249                return m_broadphaseHandle;
250        }
251
[2430]252        SIMD_FORCE_INLINE const btBroadphaseProxy*      getBroadphaseHandle() const
[1963]253        {
254                return m_broadphaseHandle;
255        }
256
257        void    setBroadphaseHandle(btBroadphaseProxy* handle)
258        {
259                m_broadphaseHandle = handle;
260        }
261
262
263        const btTransform&      getInterpolationWorldTransform() const
264        {
265                return m_interpolationWorldTransform;
266        }
267
268        btTransform&    getInterpolationWorldTransform()
269        {
270                return m_interpolationWorldTransform;
271        }
272
273        void    setInterpolationWorldTransform(const btTransform&       trans)
274        {
275                m_interpolationWorldTransform = trans;
276        }
277
278        void    setInterpolationLinearVelocity(const btVector3& linvel)
279        {
280                m_interpolationLinearVelocity = linvel;
281        }
282
283        void    setInterpolationAngularVelocity(const btVector3& angvel)
284        {
285                m_interpolationAngularVelocity = angvel;
286        }
287
288        const btVector3&        getInterpolationLinearVelocity() const
289        {
290                return m_interpolationLinearVelocity;
291        }
292
293        const btVector3&        getInterpolationAngularVelocity() const
294        {
295                return m_interpolationAngularVelocity;
296        }
297
[2430]298        SIMD_FORCE_INLINE int getIslandTag() const
[1963]299        {
300                return  m_islandTag1;
301        }
302
303        void    setIslandTag(int tag)
304        {
305                m_islandTag1 = tag;
306        }
307
[2430]308        SIMD_FORCE_INLINE int getCompanionId() const
[1963]309        {
310                return  m_companionId;
311        }
312
313        void    setCompanionId(int id)
314        {
315                m_companionId = id;
316        }
317
[2430]318        SIMD_FORCE_INLINE btScalar                      getHitFraction() const
[1963]319        {
320                return m_hitFraction; 
321        }
322
323        void    setHitFraction(btScalar hitFraction)
324        {
325                m_hitFraction = hitFraction;
326        }
327
328       
[2430]329        SIMD_FORCE_INLINE int   getCollisionFlags() const
[1963]330        {
331                return m_collisionFlags;
332        }
333
334        void    setCollisionFlags(int flags)
335        {
336                m_collisionFlags = flags;
337        }
338       
339        ///Swept sphere radius (0.0 by default), see btConvexConvexAlgorithm::
340        btScalar                        getCcdSweptSphereRadius() const
341        {
342                return m_ccdSweptSphereRadius;
343        }
344
345        ///Swept sphere radius (0.0 by default), see btConvexConvexAlgorithm::
346        void    setCcdSweptSphereRadius(btScalar radius)
347        {
348                m_ccdSweptSphereRadius = radius;
349        }
350
351        btScalar        getCcdMotionThreshold() const
352        {
353                return m_ccdMotionThreshold;
354        }
355
356        btScalar        getCcdSquareMotionThreshold() const
357        {
358                return m_ccdMotionThreshold*m_ccdMotionThreshold;
359        }
360
361
362
363        /// Don't do continuous collision detection if the motion (in one step) is less then m_ccdMotionThreshold
364        void    setCcdMotionThreshold(btScalar ccdMotionThreshold)
365        {
366                m_ccdMotionThreshold = ccdMotionThreshold*ccdMotionThreshold;
367        }
368
369        ///users can point to their objects, userPointer is not used by Bullet
370        void*   getUserPointer() const
371        {
372                return m_userObjectPointer;
373        }
374       
375        ///users can point to their objects, userPointer is not used by Bullet
376        void    setUserPointer(void* userPointer)
377        {
378                m_userObjectPointer = userPointer;
379        }
380
381
382        inline bool checkCollideWith(btCollisionObject* co)
383        {
384                if (m_checkCollideWith)
385                        return checkCollideWithOverride(co);
386
387                return true;
388        }
389};
390
391#endif //COLLISION_OBJECT_H
Note: See TracBrowser for help on using the repository browser.