SpuContactManifoldCollisionAlgorithm.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. Bullet Continuous Collision Detection and Physics Library
  3. Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com
  4. This software is provided 'as-is', without any express or implied warranty.
  5. In no event will the authors be held liable for any damages arising from the use of this software.
  6. Permission is granted to anyone to use this software for any purpose,
  7. including commercial applications, and to alter it and redistribute it freely,
  8. subject to the following restrictions:
  9. 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.
  10. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
  11. 3. This notice may not be removed or altered from any source distribution.
  12. */
  13. #ifndef BT_SPU_CONTACTMANIFOLD_COLLISION_ALGORITHM_H
  14. #define BT_SPU_CONTACTMANIFOLD_COLLISION_ALGORITHM_H
  15. #include "bullet/BulletCollision//BroadphaseCollision/btCollisionAlgorithm.h"
  16. #include "bullet/BulletCollision//BroadphaseCollision/btBroadphaseProxy.h"
  17. #include "bullet/BulletCollision//CollisionDispatch/btCollisionCreateFunc.h"
  18. #include "bullet/BulletCollision//BroadphaseCollision/btDispatcher.h"
  19. #include "bullet/LinearMath/btTransformUtil.h"
  20. #include "bullet/BulletCollision//CollisionDispatch/btCollisionObjectWrapper.h"
  21. class btPersistentManifold;
  22. //#define USE_SEPDISTANCE_UTIL 1
  23. /// SpuContactManifoldCollisionAlgorithm provides contact manifold and should be processed on SPU.
  24. ATTRIBUTE_ALIGNED16(class) SpuContactManifoldCollisionAlgorithm : public btCollisionAlgorithm
  25. {
  26. btVector3 m_shapeDimensions0;
  27. btVector3 m_shapeDimensions1;
  28. btPersistentManifold* m_manifoldPtr;
  29. int m_shapeType0;
  30. int m_shapeType1;
  31. float m_collisionMargin0;
  32. float m_collisionMargin1;
  33. const btCollisionObject* m_collisionObject0;
  34. const btCollisionObject* m_collisionObject1;
  35. public:
  36. virtual void processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
  37. virtual btScalar calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
  38. SpuContactManifoldCollisionAlgorithm(const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObject* body0,const btCollisionObject* body1);
  39. #ifdef USE_SEPDISTANCE_UTIL
  40. btConvexSeparatingDistanceUtil m_sepDistance;
  41. #endif //USE_SEPDISTANCE_UTIL
  42. virtual ~SpuContactManifoldCollisionAlgorithm();
  43. virtual void getAllContactManifolds(btManifoldArray& manifoldArray)
  44. {
  45. if (m_manifoldPtr)
  46. manifoldArray.push_back(m_manifoldPtr);
  47. }
  48. btPersistentManifold* getContactManifoldPtr()
  49. {
  50. return m_manifoldPtr;
  51. }
  52. const btCollisionObject* getCollisionObject0()
  53. {
  54. return m_collisionObject0;
  55. }
  56. const btCollisionObject* getCollisionObject1()
  57. {
  58. return m_collisionObject1;
  59. }
  60. int getShapeType0() const
  61. {
  62. return m_shapeType0;
  63. }
  64. int getShapeType1() const
  65. {
  66. return m_shapeType1;
  67. }
  68. float getCollisionMargin0() const
  69. {
  70. return m_collisionMargin0;
  71. }
  72. float getCollisionMargin1() const
  73. {
  74. return m_collisionMargin1;
  75. }
  76. const btVector3& getShapeDimensions0() const
  77. {
  78. return m_shapeDimensions0;
  79. }
  80. const btVector3& getShapeDimensions1() const
  81. {
  82. return m_shapeDimensions1;
  83. }
  84. struct CreateFunc :public btCollisionAlgorithmCreateFunc
  85. {
  86. virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
  87. {
  88. void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(SpuContactManifoldCollisionAlgorithm));
  89. return new(mem) SpuContactManifoldCollisionAlgorithm(ci,body0Wrap->getCollisionObject(),body1Wrap->getCollisionObject());
  90. }
  91. };
  92. };
  93. #endif //BT_SPU_CONTACTMANIFOLD_COLLISION_ALGORITHM_H