btRaycastCallback.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. Bullet Continuous Collision Detection and Physics Library
  3. Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
  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_RAYCAST_TRI_CALLBACK_H
  14. #define BT_RAYCAST_TRI_CALLBACK_H
  15. #include "BulletCollision/CollisionShapes/btTriangleCallback.h"
  16. #include "LinearMath/btTransform.h"
  17. struct btBroadphaseProxy;
  18. class btConvexShape;
  19. class btTriangleRaycastCallback : public btTriangleCallback
  20. {
  21. public:
  22. //input
  23. btVector3 m_from;
  24. btVector3 m_to;
  25. //@BP Mod - allow backface filtering and unflipped normals
  26. enum EFlags
  27. {
  28. kF_None = 0,
  29. kF_FilterBackfaces = 1 << 0,
  30. kF_KeepUnflippedNormal = 1 << 1, // Prevents returned face normal getting flipped when a ray hits a back-facing triangle
  31. ///SubSimplexConvexCastRaytest is the default, even if kF_None is set.
  32. kF_UseSubSimplexConvexCastRaytest = 1 << 2, // Uses an approximate but faster ray versus convex intersection algorithm
  33. kF_UseGjkConvexCastRaytest = 1 << 3,
  34. kF_DisableHeightfieldAccelerator = 1 << 4, //don't use the heightfield raycast accelerator. See https://github.com/bulletphysics/bullet3/pull/2062
  35. kF_Terminator = 0xFFFFFFFF
  36. };
  37. unsigned int m_flags;
  38. btScalar m_hitFraction;
  39. btTriangleRaycastCallback(const btVector3& from, const btVector3& to, unsigned int flags = 0);
  40. virtual void processTriangle(btVector3* triangle, int partId, int triangleIndex);
  41. virtual btScalar reportHit(const btVector3& hitNormalLocal, btScalar hitFraction, int partId, int triangleIndex) = 0;
  42. };
  43. class btTriangleConvexcastCallback : public btTriangleCallback
  44. {
  45. public:
  46. const btConvexShape* m_convexShape;
  47. btTransform m_convexShapeFrom;
  48. btTransform m_convexShapeTo;
  49. btTransform m_triangleToWorld;
  50. btScalar m_hitFraction;
  51. btScalar m_triangleCollisionMargin;
  52. btScalar m_allowedPenetration;
  53. btTriangleConvexcastCallback(const btConvexShape* convexShape, const btTransform& convexShapeFrom, const btTransform& convexShapeTo, const btTransform& triangleToWorld, const btScalar triangleCollisionMargin);
  54. virtual void processTriangle(btVector3* triangle, int partId, int triangleIndex);
  55. virtual btScalar reportHit(const btVector3& hitNormalLocal, const btVector3& hitPointLocal, btScalar hitFraction, int partId, int triangleIndex) = 0;
  56. };
  57. #endif //BT_RAYCAST_TRI_CALLBACK_H