godot_ray_world_algorithm.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*************************************************************************/
  2. /* godot_ray_world_algorithm.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 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. #ifndef GODOT_RAY_WORLD_ALGORITHM_H
  31. #define GODOT_RAY_WORLD_ALGORITHM_H
  32. #include <BulletCollision/CollisionDispatch/btActivatingCollisionAlgorithm.h>
  33. #include <BulletCollision/CollisionDispatch/btCollisionCreateFunc.h>
  34. #include <BulletCollision/CollisionDispatch/btCollisionDispatcher.h>
  35. /**
  36. @author AndreaCatania
  37. */
  38. class btDiscreteDynamicsWorld;
  39. class GodotRayWorldAlgorithm : public btActivatingCollisionAlgorithm {
  40. const btDiscreteDynamicsWorld *m_world;
  41. btPersistentManifold *m_manifoldPtr;
  42. bool m_ownManifold;
  43. bool m_isSwapped;
  44. public:
  45. GodotRayWorldAlgorithm(const btDiscreteDynamicsWorld *world, btPersistentManifold *mf, const btCollisionAlgorithmConstructionInfo &ci, const btCollisionObjectWrapper *body0Wrap, const btCollisionObjectWrapper *body1Wrap, bool isSwapped);
  46. virtual ~GodotRayWorldAlgorithm();
  47. virtual void processCollision(const btCollisionObjectWrapper *body0Wrap, const btCollisionObjectWrapper *body1Wrap, const btDispatcherInfo &dispatchInfo, btManifoldResult *resultOut);
  48. virtual btScalar calculateTimeOfImpact(btCollisionObject *body0, btCollisionObject *body1, const btDispatcherInfo &dispatchInfo, btManifoldResult *resultOut);
  49. virtual void getAllContactManifolds(btManifoldArray &manifoldArray) {
  50. ///should we use m_ownManifold to avoid adding duplicates?
  51. if (m_manifoldPtr && m_ownManifold)
  52. manifoldArray.push_back(m_manifoldPtr);
  53. }
  54. struct CreateFunc : public btCollisionAlgorithmCreateFunc {
  55. const btDiscreteDynamicsWorld *m_world;
  56. CreateFunc(const btDiscreteDynamicsWorld *world);
  57. virtual btCollisionAlgorithm *CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo &ci, const btCollisionObjectWrapper *body0Wrap, const btCollisionObjectWrapper *body1Wrap) {
  58. void *mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(GodotRayWorldAlgorithm));
  59. return new (mem) GodotRayWorldAlgorithm(m_world, ci.m_manifold, ci, body0Wrap, body1Wrap, false);
  60. }
  61. };
  62. struct SwappedCreateFunc : public btCollisionAlgorithmCreateFunc {
  63. const btDiscreteDynamicsWorld *m_world;
  64. SwappedCreateFunc(const btDiscreteDynamicsWorld *world);
  65. virtual btCollisionAlgorithm *CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo &ci, const btCollisionObjectWrapper *body0Wrap, const btCollisionObjectWrapper *body1Wrap) {
  66. void *mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(GodotRayWorldAlgorithm));
  67. return new (mem) GodotRayWorldAlgorithm(m_world, ci.m_manifold, ci, body0Wrap, body1Wrap, true);
  68. }
  69. };
  70. };
  71. #endif // GODOT_RAY_WORLD_ALGORITHM_H