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 
95  union
96  {
99  };
100 
103 
106 
109 
112 
115 
116  virtual bool checkCollideWithOverride(const btCollisionObject* /* co */) const
117  {
118  return true;
119  }
120 
121 public:
122 
124 
126  {
127  CF_STATIC_OBJECT= 1,
128  CF_KINEMATIC_OBJECT= 2,
129  CF_NO_CONTACT_RESPONSE = 4,
130  CF_CUSTOM_MATERIAL_CALLBACK = 8,//this allows per-triangle material (friction/restitution)
131  CF_CHARACTER_OBJECT = 16,
132  CF_DISABLE_VISUALIZE_OBJECT = 32, //disable debug drawing
133  CF_DISABLE_SPU_COLLISION_PROCESSING = 64//disable parallel/SPU processing
134  };
135 
137  {
138  CO_COLLISION_OBJECT =1,
139  CO_RIGID_BODY=2,
142  CO_GHOST_OBJECT=4,
143  CO_SOFT_BODY=8,
144  CO_HF_FLUID=16,
145  CO_USER_TYPE=32,
146  CO_FEATHERSTONE_LINK=64
147  };
148 
150  {
151  CF_ANISOTROPIC_FRICTION_DISABLED=0,
152  CF_ANISOTROPIC_FRICTION = 1,
153  CF_ANISOTROPIC_ROLLING_FRICTION = 2
154  };
155 
156  SIMD_FORCE_INLINE bool mergesSimulationIslands() const
157  {
159  return ((m_collisionFlags & (CF_STATIC_OBJECT | CF_KINEMATIC_OBJECT | CF_NO_CONTACT_RESPONSE) )==0);
160  }
161 
162  const btVector3& getAnisotropicFriction() const
163  {
164  return m_anisotropicFriction;
165  }
166  void setAnisotropicFriction(const btVector3& anisotropicFriction, int frictionMode = CF_ANISOTROPIC_FRICTION)
167  {
168  m_anisotropicFriction = anisotropicFriction;
169  bool isUnity = (anisotropicFriction[0]!=1.f) || (anisotropicFriction[1]!=1.f) || (anisotropicFriction[2]!=1.f);
170  m_hasAnisotropicFriction = isUnity?frictionMode : 0;
171  }
172  bool hasAnisotropicFriction(int frictionMode = CF_ANISOTROPIC_FRICTION) const
173  {
174  return (m_hasAnisotropicFriction&frictionMode)!=0;
175  }
176 
179  void setContactProcessingThreshold( btScalar contactProcessingThreshold)
180  {
181  m_contactProcessingThreshold = contactProcessingThreshold;
182  }
183  btScalar getContactProcessingThreshold() const
184  {
185  return m_contactProcessingThreshold;
186  }
187 
189  return (m_collisionFlags & CF_STATIC_OBJECT) != 0;
190  }
191 
192  SIMD_FORCE_INLINE bool isKinematicObject() const
193  {
194  return (m_collisionFlags & CF_KINEMATIC_OBJECT) != 0;
195  }
196 
197  SIMD_FORCE_INLINE bool isStaticOrKinematicObject() const
198  {
199  return (m_collisionFlags & (CF_KINEMATIC_OBJECT | CF_STATIC_OBJECT)) != 0 ;
200  }
201 
203  return (m_collisionFlags & CF_NO_CONTACT_RESPONSE)==0;
204  }
205 
206 
208 
209  virtual ~btCollisionObject();
210 
211  virtual void setCollisionShape(btCollisionShape* collisionShape)
212  {
213  m_updateRevision++;
214  m_collisionShape = collisionShape;
215  m_rootCollisionShape = collisionShape;
216  }
217 
218  SIMD_FORCE_INLINE const btCollisionShape* getCollisionShape() const
219  {
220  return m_collisionShape;
221  }
222 
223  SIMD_FORCE_INLINE btCollisionShape* getCollisionShape()
224  {
225  return m_collisionShape;
226  }
227 
228 
229 
230 
231 
234  void* internalGetExtensionPointer() const
235  {
236  return m_extensionPointer;
237  }
240  void internalSetExtensionPointer(void* pointer)
241  {
242  m_extensionPointer = pointer;
243  }
244 
245  SIMD_FORCE_INLINE int getActivationState() const { return m_activationState1;}
246 
247  void setActivationState(int newState) const;
248 
249  void setDeactivationTime(btScalar time)
250  {
251  m_deactivationTime = time;
252  }
253  btScalar getDeactivationTime() const
254  {
255  return m_deactivationTime;
256  }
257 
258  void forceActivationState(int newState) const;
259 
260  void activate(bool forceActivation = false) const;
261 
262  SIMD_FORCE_INLINE bool isActive() const
263  {
264  return ((getActivationState() != ISLAND_SLEEPING) && (getActivationState() != DISABLE_SIMULATION));
265  }
266 
267  void setRestitution(btScalar rest)
268  {
269  m_updateRevision++;
270  m_restitution = rest;
271  }
272  btScalar getRestitution() const
273  {
274  return m_restitution;
275  }
276  void setFriction(btScalar frict)
277  {
278  m_updateRevision++;
279  m_friction = frict;
280  }
282  {
283  return m_friction;
284  }
285 
286  void setRollingFriction(btScalar frict)
287  {
288  m_updateRevision++;
289  m_rollingFriction = frict;
290  }
291  btScalar getRollingFriction() const
292  {
293  return m_rollingFriction;
294  }
295 
296 
298  int getInternalType() const
299  {
300  return m_internalType;
301  }
302 
303  btTransform& getWorldTransform()
304  {
305  return m_worldTransform;
306  }
307 
308  const btTransform& getWorldTransform() const
309  {
310  return m_worldTransform;
311  }
312 
313  void setWorldTransform(const btTransform& worldTrans)
314  {
315  m_updateRevision++;
316  m_worldTransform = worldTrans;
317  }
318 
319 
320  SIMD_FORCE_INLINE btBroadphaseProxy* getBroadphaseHandle()
321  {
322  return m_broadphaseHandle;
323  }
324 
325  SIMD_FORCE_INLINE const btBroadphaseProxy* getBroadphaseHandle() const
326  {
327  return m_broadphaseHandle;
328  }
329 
330  void setBroadphaseHandle(btBroadphaseProxy* handle)
331  {
332  m_broadphaseHandle = handle;
333  }
334 
335 
336  const btTransform& getInterpolationWorldTransform() const
337  {
338  return m_interpolationWorldTransform;
339  }
340 
341  btTransform& getInterpolationWorldTransform()
342  {
343  return m_interpolationWorldTransform;
344  }
345 
346  void setInterpolationWorldTransform(const btTransform& trans)
347  {
348  m_updateRevision++;
349  m_interpolationWorldTransform = trans;
350  }
351 
352  void setInterpolationLinearVelocity(const btVector3& linvel)
353  {
354  m_updateRevision++;
355  m_interpolationLinearVelocity = linvel;
356  }
357 
358  void setInterpolationAngularVelocity(const btVector3& angvel)
359  {
360  m_updateRevision++;
361  m_interpolationAngularVelocity = angvel;
362  }
363 
364  const btVector3& getInterpolationLinearVelocity() const
365  {
366  return m_interpolationLinearVelocity;
367  }
368 
369  const btVector3& getInterpolationAngularVelocity() const
370  {
371  return m_interpolationAngularVelocity;
372  }
373 
374  SIMD_FORCE_INLINE int getIslandTag() const
375  {
376  return m_islandTag1;
377  }
378 
379  void setIslandTag(int tag)
380  {
381  m_islandTag1 = tag;
382  }
383 
384  SIMD_FORCE_INLINE int getCompanionId() const
385  {
386  return m_companionId;
387  }
388 
389  void setCompanionId(int id)
390  {
391  m_companionId = id;
392  }
393 
394  SIMD_FORCE_INLINE btScalar getHitFraction() const
395  {
396  return m_hitFraction;
397  }
398 
399  void setHitFraction(btScalar hitFraction)
400  {
401  m_hitFraction = hitFraction;
402  }
403 
404 
405  SIMD_FORCE_INLINE int getCollisionFlags() const
406  {
407  return m_collisionFlags;
408  }
409 
410  void setCollisionFlags(int flags)
411  {
412  m_collisionFlags = flags;
413  }
414 
416  btScalar getCcdSweptSphereRadius() const
417  {
418  return m_ccdSweptSphereRadius;
419  }
420 
422  void setCcdSweptSphereRadius(btScalar radius)
423  {
424  m_ccdSweptSphereRadius = radius;
425  }
426 
427  btScalar getCcdMotionThreshold() const
428  {
429  return m_ccdMotionThreshold;
430  }
431 
432  btScalar getCcdSquareMotionThreshold() const
433  {
434  return m_ccdMotionThreshold*m_ccdMotionThreshold;
435  }
436 
437 
438 
440  void setCcdMotionThreshold(btScalar ccdMotionThreshold)
441  {
442  m_ccdMotionThreshold = ccdMotionThreshold;
443  }
444 
446  void* getUserPointer() const
447  {
448  return m_userObjectPointer;
449  }
450 
451  int getUserIndex() const
452  {
453  return m_userIndex;
454  }
456  void setUserPointer(void* userPointer)
457  {
458  m_userObjectPointer = userPointer;
459  }
460 
462  void setUserIndex(int index)
463  {
464  m_userIndex = index;
465  }
466 
467  int getUpdateRevisionInternal() const
468  {
469  return m_updateRevision;
470  }
471 
472 
473  inline bool checkCollideWith(const btCollisionObject* co) const
474  {
475  if (m_checkCollideWith)
476  return checkCollideWithOverride(co);
477 
478  return true;
479  }
480 
481  virtual int calculateSerializeBufferSize() const;
482 
484  virtual const char* serialize(void* dataBuffer, class btSerializer* serializer) const;
485 
486  virtual void serializeSingleObject(class btSerializer* serializer) const;
487 
488 };
489 
492 {
496  char *m_name;
497 
505  double m_friction;
508  double m_hitFraction;
511 
519 
520  char m_padding[4];
521 };
522 
525 {
529  char *m_name;
530 
538  float m_friction;
540 
545 
553  char m_padding[4];
554 };
555 
556 
557 
559 {
560  return sizeof(btCollisionObjectData);
561 }
562 
563 
564 
565 #endif //BT_COLLISION_OBJECT_H