btConeShape.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. Bullet Continuous Collision Detection and Physics Library
  3. Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org
  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_CONE_MINKOWSKI_H
  14. #define BT_CONE_MINKOWSKI_H
  15. #include "btConvexInternalShape.h"
  16. #include "bullet/BulletCollision//BroadphaseCollision/btBroadphaseProxy.h" // for the types
  17. ///The btConeShape implements a cone shape primitive, centered around the origin and aligned with the Y axis. The btConeShapeX is aligned around the X axis and btConeShapeZ around the Z axis.
  18. ATTRIBUTE_ALIGNED16(class) btConeShape : public btConvexInternalShape
  19. {
  20. btScalar m_sinAngle;
  21. btScalar m_radius;
  22. btScalar m_height;
  23. int m_coneIndices[3];
  24. btVector3 coneLocalSupport(const btVector3& v) const;
  25. public:
  26. BT_DECLARE_ALIGNED_ALLOCATOR();
  27. btConeShape (btScalar radius,btScalar height);
  28. virtual btVector3 localGetSupportingVertex(const btVector3& vec) const;
  29. virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec) const;
  30. virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const;
  31. btScalar getRadius() const { return m_radius;}
  32. btScalar getHeight() const { return m_height;}
  33. virtual void calculateLocalInertia(btScalar mass,btVector3& inertia) const
  34. {
  35. btTransform identity;
  36. identity.setIdentity();
  37. btVector3 aabbMin,aabbMax;
  38. getAabb(identity,aabbMin,aabbMax);
  39. btVector3 halfExtents = (aabbMax-aabbMin)*btScalar(0.5);
  40. btScalar margin = getMargin();
  41. btScalar lx=btScalar(2.)*(halfExtents.x()+margin);
  42. btScalar ly=btScalar(2.)*(halfExtents.y()+margin);
  43. btScalar lz=btScalar(2.)*(halfExtents.z()+margin);
  44. const btScalar x2 = lx*lx;
  45. const btScalar y2 = ly*ly;
  46. const btScalar z2 = lz*lz;
  47. const btScalar scaledmass = mass * btScalar(0.08333333);
  48. inertia = scaledmass * (btVector3(y2+z2,x2+z2,x2+y2));
  49. // inertia.x() = scaledmass * (y2+z2);
  50. // inertia.y() = scaledmass * (x2+z2);
  51. // inertia.z() = scaledmass * (x2+y2);
  52. }
  53. virtual const char* getName()const
  54. {
  55. return "Cone";
  56. }
  57. ///choose upAxis index
  58. void setConeUpIndex(int upIndex);
  59. int getConeUpIndex() const
  60. {
  61. return m_coneIndices[1];
  62. }
  63. virtual btVector3 getAnisotropicRollingFrictionDirection() const
  64. {
  65. return btVector3 (0,1,0);
  66. }
  67. virtual void setLocalScaling(const btVector3& scaling);
  68. virtual int calculateSerializeBufferSize() const;
  69. ///fills the dataBuffer and returns the struct name (and 0 on failure)
  70. virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const;
  71. };
  72. ///btConeShape implements a Cone shape, around the X axis
  73. class btConeShapeX : public btConeShape
  74. {
  75. public:
  76. btConeShapeX(btScalar radius,btScalar height);
  77. virtual btVector3 getAnisotropicRollingFrictionDirection() const
  78. {
  79. return btVector3 (1,0,0);
  80. }
  81. //debugging
  82. virtual const char* getName()const
  83. {
  84. return "ConeX";
  85. }
  86. };
  87. ///btConeShapeZ implements a Cone shape, around the Z axis
  88. class btConeShapeZ : public btConeShape
  89. {
  90. public:
  91. btConeShapeZ(btScalar radius,btScalar height);
  92. virtual btVector3 getAnisotropicRollingFrictionDirection() const
  93. {
  94. return btVector3 (0,0,1);
  95. }
  96. //debugging
  97. virtual const char* getName()const
  98. {
  99. return "ConeZ";
  100. }
  101. };
  102. ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
  103. struct btConeShapeData
  104. {
  105. btConvexInternalShapeData m_convexInternalShapeData;
  106. int m_upIndex;
  107. char m_padding[4];
  108. };
  109. SIMD_FORCE_INLINE int btConeShape::calculateSerializeBufferSize() const
  110. {
  111. return sizeof(btConeShapeData);
  112. }
  113. ///fills the dataBuffer and returns the struct name (and 0 on failure)
  114. SIMD_FORCE_INLINE const char* btConeShape::serialize(void* dataBuffer, btSerializer* serializer) const
  115. {
  116. btConeShapeData* shapeData = (btConeShapeData*) dataBuffer;
  117. btConvexInternalShape::serialize(&shapeData->m_convexInternalShapeData,serializer);
  118. shapeData->m_upIndex = m_coneIndices[1];
  119. return "btConeShapeData";
  120. }
  121. #endif //BT_CONE_MINKOWSKI_H