Bullet Collision Detection & Physics Library
btCollisionObject.h
Go to the documentation of this file.
1 /*
2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
4 
5 This software is provided 'as-is', without any express or implied warranty.
6 In no event will the authors be held liable for any damages arising from the use of this software.
7 Permission is granted to anyone to use this software for any purpose,
8 including commercial applications, and to alter it and redistribute it freely,
9 subject to the following restrictions:
10 
11 1. 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.
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13 3. This notice may not be removed or altered from any source distribution.
14 */
15 
16 #ifndef BT_COLLISION_OBJECT_H
17 #define BT_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 
28 struct btBroadphaseProxy;
29 class btCollisionShape;
34 
36 
37 #ifdef BT_USE_DOUBLE_PRECISION
38 #define btCollisionObjectData btCollisionObjectDoubleData
39 #define btCollisionObjectDataName "btCollisionObjectDoubleData"
40 #else
41 #define btCollisionObjectData btCollisionObjectFloatData
42 #define btCollisionObjectDataName "btCollisionObjectFloatData"
43 #endif
44 
45 
50 {
51 
52 protected:
53 
55 
59  //those two are experimental: just added for bullet time effect, so you can still apply impulses (directly modifying velocities)
60  //without destroying the continuous interpolated motion (which uses this interpolation velocities)
63 
67 
72 
77 
79 
82 
83  mutable int m_activationState1;
85 
89 
93 
96 
99 
102 
105 
108 
109  virtual bool checkCollideWithOverride(const btCollisionObject* /* co */) const
110  {
111  return true;
112  }
113 
114 public:
115 
117 
119  {
120  CF_STATIC_OBJECT= 1,
121  CF_KINEMATIC_OBJECT= 2,
122  CF_NO_CONTACT_RESPONSE = 4,
123  CF_CUSTOM_MATERIAL_CALLBACK = 8,//this allows per-triangle material (friction/restitution)
124  CF_CHARACTER_OBJECT = 16,
125  CF_DISABLE_VISUALIZE_OBJECT = 32, //disable debug drawing
126  CF_DISABLE_SPU_COLLISION_PROCESSING = 64//disable parallel/SPU processing
127  };
128 
130  {
131  CO_COLLISION_OBJECT =1,
132  CO_RIGID_BODY=2,
135  CO_GHOST_OBJECT=4,
136  CO_SOFT_BODY=8,
137  CO_HF_FLUID=16,
138  CO_USER_TYPE=32
139  };
140 
142  {
143  CF_ANISOTROPIC_FRICTION_DISABLED=0,
144  CF_ANISOTROPIC_FRICTION = 1,
145  CF_ANISOTROPIC_ROLLING_FRICTION = 2
146  };
147 
148  SIMD_FORCE_INLINE bool mergesSimulationIslands() const
149  {
151  return ((m_collisionFlags & (CF_STATIC_OBJECT | CF_KINEMATIC_OBJECT | CF_NO_CONTACT_RESPONSE) )==0);
152  }
153 
154  const btVector3& getAnisotropicFriction() const
155  {
156  return m_anisotropicFriction;
157  }
158  void setAnisotropicFriction(const btVector3& anisotropicFriction, int frictionMode = CF_ANISOTROPIC_FRICTION)
159  {
160  m_anisotropicFriction = anisotropicFriction;
161  bool isUnity = (anisotropicFriction[0]!=1.f) || (anisotropicFriction[1]!=1.f) || (anisotropicFriction[2]!=1.f);
162  m_hasAnisotropicFriction = isUnity?frictionMode : 0;
163  }
164  bool hasAnisotropicFriction(int frictionMode = CF_ANISOTROPIC_FRICTION) const
165  {
166  return (m_hasAnisotropicFriction&frictionMode)!=0;
167  }
168 
171  void setContactProcessingThreshold( btScalar contactProcessingThreshold)
172  {
173  m_contactProcessingThreshold = contactProcessingThreshold;
174  }
175  btScalar getContactProcessingThreshold() const
176  {
177  return m_contactProcessingThreshold;
178  }
179 
181  return (m_collisionFlags & CF_STATIC_OBJECT) != 0;
182  }
183 
184  SIMD_FORCE_INLINE bool isKinematicObject() const
185  {
186  return (m_collisionFlags & CF_KINEMATIC_OBJECT) != 0;
187  }
188 
189  SIMD_FORCE_INLINE bool isStaticOrKinematicObject() const
190  {
191  return (m_collisionFlags & (CF_KINEMATIC_OBJECT | CF_STATIC_OBJECT)) != 0 ;
192  }
193 
195  return (m_collisionFlags & CF_NO_CONTACT_RESPONSE)==0;
196  }
197 
198 
200 
201  virtual ~btCollisionObject();
202 
203  virtual void setCollisionShape(btCollisionShape* collisionShape)
204  {
205  m_collisionShape = collisionShape;
206  m_rootCollisionShape = collisionShape;
207  }
208 
209  SIMD_FORCE_INLINE const btCollisionShape* getCollisionShape() const
210  {
211  return m_collisionShape;
212  }
213 
214  SIMD_FORCE_INLINE btCollisionShape* getCollisionShape()
215  {
216  return m_collisionShape;
217  }
218 
219 
220 
221 
222 
225  void* internalGetExtensionPointer() const
226  {
227  return m_extensionPointer;
228  }
231  void internalSetExtensionPointer(void* pointer)
232  {
233  m_extensionPointer = pointer;
234  }
235 
236  SIMD_FORCE_INLINE int getActivationState() const { return m_activationState1;}
237 
238  void setActivationState(int newState) const;
239 
240  void setDeactivationTime(btScalar time)
241  {
242  m_deactivationTime = time;
243  }
244  btScalar getDeactivationTime() const
245  {
246  return m_deactivationTime;
247  }
248 
249  void forceActivationState(int newState) const;
250 
251  void activate(bool forceActivation = false) const;
252 
253  SIMD_FORCE_INLINE bool isActive() const
254  {
255  return ((getActivationState() != ISLAND_SLEEPING) && (getActivationState() != DISABLE_SIMULATION));
256  }
257 
258  void setRestitution(btScalar rest)
259  {
260  m_restitution = rest;
261  }
262  btScalar getRestitution() const
263  {
264  return m_restitution;
265  }
266  void setFriction(btScalar frict)
267  {
268  m_friction = frict;
269  }
271  {
272  return m_friction;
273  }
274 
275  void setRollingFriction(btScalar frict)
276  {
277  m_rollingFriction = frict;
278  }
279  btScalar getRollingFriction() const
280  {
281  return m_rollingFriction;
282  }
283 
284 
286  int getInternalType() const
287  {
288  return m_internalType;
289  }
290 
291  btTransform& getWorldTransform()
292  {
293  return m_worldTransform;
294  }
295 
296  const btTransform& getWorldTransform() const
297  {
298  return m_worldTransform;
299  }
300 
301  void setWorldTransform(const btTransform& worldTrans)
302  {
303  m_worldTransform = worldTrans;
304  }
305 
306 
307  SIMD_FORCE_INLINE btBroadphaseProxy* getBroadphaseHandle()
308  {
309  return m_broadphaseHandle;
310  }
311 
312  SIMD_FORCE_INLINE const btBroadphaseProxy* getBroadphaseHandle() const
313  {
314  return m_broadphaseHandle;
315  }
316 
317  void setBroadphaseHandle(btBroadphaseProxy* handle)
318  {
319  m_broadphaseHandle = handle;
320  }
321 
322 
323  const btTransform& getInterpolationWorldTransform() const
324  {
325  return m_interpolationWorldTransform;
326  }
327 
328  btTransform& getInterpolationWorldTransform()
329  {
330  return m_interpolationWorldTransform;
331  }
332 
333  void setInterpolationWorldTransform(const btTransform& trans)
334  {
335  m_interpolationWorldTransform = trans;
336  }
337 
338  void setInterpolationLinearVelocity(const btVector3& linvel)
339  {
340  m_interpolationLinearVelocity = linvel;
341  }
342 
343  void setInterpolationAngularVelocity(const btVector3& angvel)
344  {
345  m_interpolationAngularVelocity = angvel;
346  }
347 
348  const btVector3& getInterpolationLinearVelocity() const
349  {
350  return m_interpolationLinearVelocity;
351  }
352 
353  const btVector3& getInterpolationAngularVelocity() const
354  {
355  return m_interpolationAngularVelocity;
356  }
357 
358  SIMD_FORCE_INLINE int getIslandTag() const
359  {
360  return m_islandTag1;
361  }
362 
363  void setIslandTag(int tag)
364  {
365  m_islandTag1 = tag;
366  }
367 
368  SIMD_FORCE_INLINE int getCompanionId() const
369  {
370  return m_companionId;
371  }
372 
373  void setCompanionId(int id)
374  {
375  m_companionId = id;
376  }
377 
378  SIMD_FORCE_INLINE btScalar getHitFraction() const
379  {
380  return m_hitFraction;
381  }
382 
383  void setHitFraction(btScalar hitFraction)
384  {
385  m_hitFraction = hitFraction;
386  }
387 
388 
389  SIMD_FORCE_INLINE int getCollisionFlags() const
390  {
391  return m_collisionFlags;
392  }
393 
394  void setCollisionFlags(int flags)
395  {
396  m_collisionFlags = flags;
397  }
398 
400  btScalar getCcdSweptSphereRadius() const
401  {
402  return m_ccdSweptSphereRadius;
403  }
404 
406  void setCcdSweptSphereRadius(btScalar radius)
407  {
408  m_ccdSweptSphereRadius = radius;
409  }
410 
411  btScalar getCcdMotionThreshold() const
412  {
413  return m_ccdMotionThreshold;
414  }
415 
416  btScalar getCcdSquareMotionThreshold() const
417  {
418  return m_ccdMotionThreshold*m_ccdMotionThreshold;
419  }
420 
421 
422 
424  void setCcdMotionThreshold(btScalar ccdMotionThreshold)
425  {
426  m_ccdMotionThreshold = ccdMotionThreshold;
427  }
428 
430  void* getUserPointer() const
431  {
432  return m_userObjectPointer;
433  }
434 
436  void setUserPointer(void* userPointer)
437  {
438  m_userObjectPointer = userPointer;
439  }
440 
441 
442  inline bool checkCollideWith(const btCollisionObject* co) const
443  {
444  if (m_checkCollideWith)
445  return checkCollideWithOverride(co);
446 
447  return true;
448  }
449 
450  virtual int calculateSerializeBufferSize() const;
451 
453  virtual const char* serialize(void* dataBuffer, class btSerializer* serializer) const;
454 
455  virtual void serializeSingleObject(class btSerializer* serializer) const;
456 
457 };
458 
461 {
465  char *m_name;
466 
474  double m_friction;
477  double m_hitFraction;
480 
488 
489  char m_padding[4];
490 };
491 
494 {
498  char *m_name;
499 
507  float m_friction;
509 
514 
522  char m_padding[4];
523 };
524 
525 
526 
528 {
529  return sizeof(btCollisionObjectData);
530 }
531 
532 
533 
534 #endif //BT_COLLISION_OBJECT_H