BsPhysX.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsPhysXPrerequisites.h"
  5. #include "BsPhysics.h"
  6. #include "BSCollision.h"
  7. #include "PxPhysics.h"
  8. #include "foundation/Px.h"
  9. #include "cooking/PxCooking.h"
  10. namespace BansheeEngine
  11. {
  12. class PhysX : public Physics
  13. {
  14. enum class ContactEventType
  15. {
  16. ContactBegin,
  17. ContactStay,
  18. ContactEnd
  19. };
  20. struct TriggerEvent
  21. {
  22. Collider* trigger;
  23. Collider* other;
  24. ContactEventType type;
  25. };
  26. struct ContactEvent
  27. {
  28. Collider* colliderA;
  29. Collider* colliderB;
  30. ContactEventType type;
  31. Vector<ContactPoint> points; // Note: Not too happy this is heap allocated, use static allocator?
  32. };
  33. public:
  34. PhysX();
  35. ~PhysX();
  36. void update() override;
  37. SPtr<PhysicsMaterial> createMaterial(float staticFriction, float dynamicFriction, float restitution) override;
  38. SPtr<PhysicsMesh> createMesh(const MeshDataPtr& meshData, PhysicsMeshType type) override;
  39. SPtr<Rigidbody> createRigidbody(const HSceneObject& linkedSO) override;
  40. SPtr<BoxCollider> createBoxCollider(const Vector3& extents, const Vector3& position,
  41. const Quaternion& rotation) override;
  42. SPtr<SphereCollider> createSphereCollider(float radius, const Vector3& position, const Quaternion& rotation) override;
  43. SPtr<PlaneCollider> createPlaneCollider(const Vector3& position, const Quaternion& rotation) override;
  44. SPtr<CapsuleCollider> createCapsuleCollider(float radius, float halfHeight, const Vector3& position,
  45. const Quaternion& rotation) override;
  46. void _reportContactEvent(const ContactEvent& event);
  47. void _reportTriggerEvent(const TriggerEvent& event);
  48. physx::PxMaterial* getDefaultMaterial() const { return mDefaultMaterial; }
  49. physx::PxPhysics* getPhysX() const { return mPhysics; }
  50. physx::PxScene* getScene() const { return mScene; }
  51. physx::PxCooking* getCooking() const { return mCooking; }
  52. private:
  53. friend class PhysXEventCallback;
  54. void triggerEvents();
  55. float mSimulationStep = 1.0f/60.0f;
  56. float mLastSimulationTime = 0.0f;
  57. Vector<TriggerEvent> mTriggerEvents;
  58. Vector<ContactEvent> mContactEvents;
  59. physx::PxFoundation* mFoundation = nullptr;
  60. physx::PxPhysics* mPhysics = nullptr;
  61. physx::PxCooking* mCooking = nullptr;
  62. physx::PxScene* mScene = nullptr;
  63. physx::PxMaterial* mDefaultMaterial = nullptr;
  64. };
  65. /** Provides easier access to PhysX. */
  66. PhysX& gPhysX();
  67. }