btCollision.h 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _T3D_PHYSICS_BTCOLLISION_H_
  23. #define _T3D_PHYSICS_BTCOLLISION_H_
  24. #ifndef _T3D_PHYSICS_PHYSICSCOLLISION_H_
  25. #include "T3D/physics/physicsCollision.h"
  26. #endif
  27. #ifndef _MMATRIX_H_
  28. #include "math/mMatrix.h"
  29. #endif
  30. #ifndef _TVECTOR_H_
  31. #include "core/util/tVector.h"
  32. #endif
  33. class btCollisionShape;
  34. class btCompoundShape;
  35. class btTriangleMesh;
  36. class BtCollision : public PhysicsCollision
  37. {
  38. protected:
  39. /// The compound if we have more than one collision shape.
  40. btCompoundShape *mCompound;
  41. /// The concrete collision shapes.
  42. Vector<btCollisionShape*> mShapes;
  43. /// The local transform for the collision shape
  44. /// or identity if this is a compound.
  45. MatrixF mLocalXfm;
  46. /// If we have any triangle mesh collision shapes then
  47. /// we need to store the mesh data.
  48. Vector<btTriangleMesh*> mMeshInterfaces;
  49. /// Helper for adding shapes.
  50. void _addShape( btCollisionShape *shape, const MatrixF &localXfm );
  51. public:
  52. BtCollision();
  53. virtual ~BtCollision();
  54. /// Return the Bullet collision shape.
  55. btCollisionShape* getShape();
  56. // The local transform used to offset the collsion
  57. // to its correct graphics position.
  58. const MatrixF& getLocalTransform() const { return mLocalXfm; }
  59. // PhysicsCollision
  60. virtual void addPlane( const PlaneF &plane );
  61. virtual void addBox( const Point3F &halfWidth,
  62. const MatrixF &localXfm );
  63. virtual void addSphere( F32 radius,
  64. const MatrixF &localXfm );
  65. virtual void addCapsule( F32 radius,
  66. F32 height,
  67. const MatrixF &localXfm );
  68. virtual bool addConvex( const Point3F *points,
  69. U32 count,
  70. const MatrixF &localXfm );
  71. virtual bool addTriangleMesh( const Point3F *vert,
  72. U32 vertCount,
  73. const U32 *index,
  74. U32 triCount,
  75. const MatrixF &localXfm );
  76. virtual bool addHeightfield( const U16 *heights,
  77. const bool *holes,
  78. U32 blockSize,
  79. F32 metersPerSample,
  80. const MatrixF &localXfm );
  81. };
  82. #endif // _T3D_PHYSICS_BTCOLLISION_H_