#ifndef PhysicsSystem_h__ #define PhysicsSystem_h__ #include "System.h" #include "Systems/TransformSystem.h" #include "Components/Transform.h" #include "Components/Physics.h" #include "Components/BoxShape.h" #include "Components/SphereShape.h" #include "Components/Vehicle.h" #include "Components/Input.h" #include "Components/MeshShape.h" #include "Components/HingeConstraint.h" #include "Components/WheelPair.h" #include "Components/TowerSteering.h" #include "Events/TankSteer.h" #include "Events/SetVelocity.h" #include "OBJ.h" // Math and base include #include #include #include #include #include #include #include #include // Dynamics includes #include #include #include #include #include #include #include #include // Visual Debugger includes #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "Physics/VehicleSetup.h" #include #include class MyCollisionResolution: public hkReferencedObject, public hkpContactListener { public: std::unordered_map m_RigidBodies; virtual void contactPointCallback( const hkpContactPointEvent& event ) { EntityID entity1 = m_RigidBodies[event.getBody(0)]; EntityID entity2 = m_RigidBodies[event.getBody(1)]; //LOG_INFO("Entities colliding: %i, %i ", entity1, entity2); } }; namespace Systems { class PhysicsSystem : public System { public: PhysicsSystem(World* world, std::shared_ptr<::EventBroker> eventBroker) : System(world, eventBroker) { } void RegisterComponents(ComponentFactory* cf) override; void Initialize() override; void Update(double dt) override; void UpdateEntity(double dt, EntityID entity, EntityID parent) override; void OnComponentCreated(std::string type, std::shared_ptr component) override; void OnComponentRemoved(std::string type, Component* component) override; void OnEntityCommit(EntityID entity) override; private: double m_Accumulator; hkpWorld* m_PhysicsWorld; // Events EventRelay m_ETankSteer; bool OnTankSteer(const Events::TankSteer &event); EventRelay m_ESetVelocity; bool OnSetVelocity(const Events::SetVelocity &event); void SetUpPhysicsState(EntityID entity, EntityID parent); void TearDownPhysicsState(EntityID entity, EntityID parent); hkVisualDebugger* m_VisualDebugger; void SetupVisualDebugger(hkpPhysicsContext* worlds); void StepVisualDebugger(); static void HK_CALL HavokErrorReport(const char* msg, void*); void SetupPhysics(hkpWorld* physicsWorld); // Converterfunctions glm::vec3 ConvertPosition(const hkVector4 &hkPosition); const hkVector4& ConvertPosition(glm::vec3 glmPosition); glm::quat ConvertRotation(const hkQuaternion &hkRotation); const hkQuaternion& ConvertRotation(glm::quat glmRotation); glm::vec3 ConvertScale(const hkVector4 &hkScale); const hkVector4&ConvertScale(glm::vec3 glmScale); std::unordered_map m_RigidBodies; hkJobThreadPool* m_ThreadPool; hkJobQueue* m_JobQueue; int m_TotalNumThreadsUsed; hkpPhysicsContext* m_Context; std::unordered_map m_Vehicles; std::vector m_Wheels; hkpVehicleInstance* Systems::PhysicsSystem::createVehicle(VehicleSetup& vehicleSetup, hkpRigidBody* chassis); struct ShapeArrayData { ShapeArrayData(EntityID entity, hkpShape* shape) { Entity = entity; Shape = shape; } EntityID Entity; hkpShape* Shape; }; std::unordered_map> m_Shapes; std::unordered_map m_ListShapes; struct ExtendedShapeData { hkpExtendedMeshShape* ExtendedMeshShape; std::vector* Vertices; std::vector* VertexIndices; hkpMoppCode* Code; hkpMoppBvTreeShape* MoppShape; }; std::unordered_map m_ExtendedMeshShapes; MyCollisionResolution* m_collisionResolution; }; } #endif // PhysicsSystem_h__