btRayShape.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*************************************************************************/
  2. /* btRayShape.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. /// IMPORTANT The class name and filename was created by following Bullet writing rules for an easy (eventually) porting to bullet
  31. /// This shape is a custom shape that is not present to Bullet physics engine
  32. #ifndef BTRAYSHAPE_H
  33. #define BTRAYSHAPE_H
  34. #include <BulletCollision/CollisionShapes/btConvexInternalShape.h>
  35. /**
  36. @author AndreaCatania
  37. */
  38. /// Ray shape around z axis
  39. ATTRIBUTE_ALIGNED16(class)
  40. btRayShape : public btConvexInternalShape {
  41. btScalar m_length;
  42. bool slipsOnSlope;
  43. /// The default axis is the z
  44. btVector3 m_shapeAxis;
  45. btTransform m_cacheSupportPoint;
  46. btScalar m_cacheScaledLength;
  47. public:
  48. BT_DECLARE_ALIGNED_ALLOCATOR();
  49. btRayShape(btScalar length);
  50. virtual ~btRayShape();
  51. void setLength(btScalar p_length);
  52. btScalar getLength() const { return m_length; }
  53. virtual void setMargin(btScalar margin);
  54. void setSlipsOnSlope(bool p_slipsOnSlope);
  55. bool getSlipsOnSlope() const { return slipsOnSlope; }
  56. const btTransform &getSupportPoint() const { return m_cacheSupportPoint; }
  57. const btScalar &getScaledLength() const { return m_cacheScaledLength; }
  58. virtual btVector3 localGetSupportingVertex(const btVector3 &vec) const;
  59. #ifndef __SPU__
  60. virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3 &vec) const;
  61. #endif //#ifndef __SPU__
  62. virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3 *vectors, btVector3 *supportVerticesOut, int numVectors) const;
  63. ///getAabb returns the axis aligned bounding box in the coordinate frame of the given transform t.
  64. virtual void getAabb(const btTransform &t, btVector3 &aabbMin, btVector3 &aabbMax) const;
  65. #ifndef __SPU__
  66. virtual void calculateLocalInertia(btScalar mass, btVector3 & inertia) const;
  67. virtual const char *getName() const {
  68. return "RayZ";
  69. }
  70. #endif //__SPU__
  71. virtual int getNumPreferredPenetrationDirections() const;
  72. virtual void getPreferredPenetrationDirection(int index, btVector3 &penetrationVector) const;
  73. private:
  74. void reload_cache();
  75. };
  76. #endif // BTRAYSHAPE_H