btConvexCast.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. Bullet Continuous Collision Detection and Physics Library
  3. Copyright (c) 2003-2006 Erwin Coumans https://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_CONVEX_CAST_H
  14. #define BT_CONVEX_CAST_H
  15. #include "LinearMath/btTransform.h"
  16. #include "LinearMath/btVector3.h"
  17. #include "LinearMath/btScalar.h"
  18. class btMinkowskiSumShape;
  19. #include "LinearMath/btIDebugDraw.h"
  20. #ifdef BT_USE_DOUBLE_PRECISION
  21. #define MAX_CONVEX_CAST_ITERATIONS 64
  22. #define MAX_CONVEX_CAST_EPSILON (SIMD_EPSILON * 10)
  23. #else
  24. #define MAX_CONVEX_CAST_ITERATIONS 32
  25. #define MAX_CONVEX_CAST_EPSILON btScalar(0.0001)
  26. #endif
  27. ///Typically the conservative advancement reaches solution in a few iterations, clip it to 32 for degenerate cases.
  28. ///See discussion about this here https://bulletphysics.orgphpBB2/viewtopic.php?t=565
  29. //will need to digg deeper to make the algorithm more robust
  30. //since, a large epsilon can cause an early termination with false
  31. //positive results (ray intersections that shouldn't be there)
  32. /// btConvexCast is an interface for Casting
  33. class btConvexCast
  34. {
  35. public:
  36. virtual ~btConvexCast();
  37. ///RayResult stores the closest result
  38. /// alternatively, add a callback method to decide about closest/all results
  39. struct CastResult
  40. {
  41. //virtual bool addRayResult(const btVector3& normal,btScalar fraction) = 0;
  42. virtual void DebugDraw(btScalar fraction) { (void)fraction; }
  43. virtual void drawCoordSystem(const btTransform& trans) { (void)trans; }
  44. virtual void reportFailure(int errNo, int numIterations)
  45. {
  46. (void)errNo;
  47. (void)numIterations;
  48. }
  49. CastResult()
  50. : m_fraction(btScalar(BT_LARGE_FLOAT)),
  51. m_debugDrawer(0),
  52. m_allowedPenetration(btScalar(0)),
  53. m_subSimplexCastMaxIterations(MAX_CONVEX_CAST_ITERATIONS),
  54. m_subSimplexCastEpsilon(MAX_CONVEX_CAST_EPSILON)
  55. {
  56. }
  57. virtual ~CastResult(){};
  58. btTransform m_hitTransformA;
  59. btTransform m_hitTransformB;
  60. btVector3 m_normal;
  61. btVector3 m_hitPoint;
  62. btScalar m_fraction; //input and output
  63. btIDebugDraw* m_debugDrawer;
  64. btScalar m_allowedPenetration;
  65. int m_subSimplexCastMaxIterations;
  66. btScalar m_subSimplexCastEpsilon;
  67. };
  68. /// cast a convex against another convex object
  69. virtual bool calcTimeOfImpact(
  70. const btTransform& fromA,
  71. const btTransform& toA,
  72. const btTransform& fromB,
  73. const btTransform& toB,
  74. CastResult& result) = 0;
  75. };
  76. #endif //BT_CONVEX_CAST_H