SpuContactManifoldCollisionAlgorithm.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 "BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h"
  16. #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
  17. #include "BulletCollision/CollisionDispatch/btCollisionCreateFunc.h"
  18. #include "BulletCollision/BroadphaseCollision/btDispatcher.h"
  19. #include "LinearMath/btTransformUtil.h"
  20. class btPersistentManifold;
  21. //#define USE_SEPDISTANCE_UTIL 1
  22. /// SpuContactManifoldCollisionAlgorithm provides contact manifold and should be processed on SPU.
  23. ATTRIBUTE_ALIGNED16(class) SpuContactManifoldCollisionAlgorithm : public btCollisionAlgorithm
  24. {
  25. btVector3 m_shapeDimensions0;
  26. btVector3 m_shapeDimensions1;
  27. btPersistentManifold* m_manifoldPtr;
  28. int m_shapeType0;
  29. int m_shapeType1;
  30. float m_collisionMargin0;
  31. float m_collisionMargin1;
  32. btCollisionObject* m_collisionObject0;
  33. btCollisionObject* m_collisionObject1;
  34. public:
  35. virtual void processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
  36. virtual btScalar calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
  37. SpuContactManifoldCollisionAlgorithm(const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* body0,btCollisionObject* body1);
  38. #ifdef USE_SEPDISTANCE_UTIL
  39. btConvexSeparatingDistanceUtil m_sepDistance;
  40. #endif //USE_SEPDISTANCE_UTIL
  41. virtual ~SpuContactManifoldCollisionAlgorithm();
  42. virtual void getAllContactManifolds(btManifoldArray& manifoldArray)
  43. {
  44. if (m_manifoldPtr)
  45. manifoldArray.push_back(m_manifoldPtr);
  46. }
  47. btPersistentManifold* getContactManifoldPtr()
  48. {
  49. return m_manifoldPtr;
  50. }
  51. btCollisionObject* getCollisionObject0()
  52. {
  53. return m_collisionObject0;
  54. }
  55. btCollisionObject* getCollisionObject1()
  56. {
  57. return m_collisionObject1;
  58. }
  59. int getShapeType0() const
  60. {
  61. return m_shapeType0;
  62. }
  63. int getShapeType1() const
  64. {
  65. return m_shapeType1;
  66. }
  67. float getCollisionMargin0() const
  68. {
  69. return m_collisionMargin0;
  70. }
  71. float getCollisionMargin1() const
  72. {
  73. return m_collisionMargin1;
  74. }
  75. const btVector3& getShapeDimensions0() const
  76. {
  77. return m_shapeDimensions0;
  78. }
  79. const btVector3& getShapeDimensions1() const
  80. {
  81. return m_shapeDimensions1;
  82. }
  83. struct CreateFunc :public btCollisionAlgorithmCreateFunc
  84. {
  85. virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1)
  86. {
  87. void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(SpuContactManifoldCollisionAlgorithm));
  88. return new(mem) SpuContactManifoldCollisionAlgorithm(ci,body0,body1);
  89. }
  90. };
  91. };
  92. #endif //BT_SPU_CONTACTMANIFOLD_COLLISION_ALGORITHM_H