// Copyright (c) Wojciech Figat. All rights reserved. #pragma once #include "Engine/Level/Actor.h" #include "Engine/Physics/Collisions.h" struct RayCastHit; struct Collision; /// /// A base class for all physical collider actors. /// /// API_CLASS(Abstract) class FLAXENGINE_API PhysicsColliderActor : public Actor { DECLARE_SCENE_OBJECT_ABSTRACT(PhysicsColliderActor); public: /// /// Occurs when a collision start gets registered for this collider (it collides with something). /// API_EVENT() Delegate CollisionEnter; /// /// Occurs when a collision end gets registered for this collider (it ends colliding with something). /// API_EVENT() Delegate CollisionExit; /// /// Occurs when a trigger touching start gets registered for this collider (the other collider enters it and triggers the event). /// API_EVENT() Delegate TriggerEnter; /// /// Occurs when a trigger touching end gets registered for this collider (the other collider enters it and triggers the event). /// API_EVENT() Delegate TriggerExit; public: /// /// Gets the attached rigid body. /// /// The rigid body or null. API_PROPERTY() virtual RigidBody* GetAttachedRigidBody() const = 0; /// /// Performs a raycast against this collider shape. /// /// The origin of the ray. /// The normalized direction of the ray. /// The raycast result hit position distance from the ray origin. Valid only if raycast hits anything. /// The maximum distance the ray should check for collisions. /// True if ray hits an object, otherwise false. API_FUNCTION(Sealed) virtual bool RayCast(const Vector3& origin, const Vector3& direction, API_PARAM(Out) float& resultHitDistance, float maxDistance = MAX_float) const = 0; /// /// Performs a raycast against this collider, returns results in a RaycastHit structure. /// /// The origin of the ray. /// The normalized direction of the ray. /// The result hit information. Valid only when method returns true. /// The maximum distance the ray should check for collisions. /// True if ray hits an object, otherwise false. API_FUNCTION(Sealed) virtual bool RayCast(const Vector3& origin, const Vector3& direction, API_PARAM(Out) RayCastHit& hitInfo, float maxDistance = MAX_float) const = 0; /// /// Gets a point on the collider that is closest to a given location. Can be used to find a hit location or position to apply explosion force or any other special effects. /// /// The position to find the closest point to it. /// The result point on the collider that is closest to the specified location. API_FUNCTION(Sealed) virtual void ClosestPoint(const Vector3& point, API_PARAM(Out) Vector3& result) const = 0; /// /// Checks if a point is inside the collider. /// /// The point to check if is contained by the collider shape (in world-space). /// True if collider shape contains a given point, otherwise false. API_FUNCTION(Sealed) virtual bool ContainsPoint(const Vector3& point) const = 0; public: /// /// Called when a collision start gets registered for this collider (it collides with something). /// /// The collision info. API_FUNCTION() virtual void OnCollisionEnter(const Collision& c); /// /// Called when a collision end gets registered for this collider (it ends colliding with something). /// /// The collision info. API_FUNCTION() virtual void OnCollisionExit(const Collision& c); /// /// Called when a trigger touching start gets registered for this collider (the other collider enters it and triggers the event). /// /// The other collider. API_FUNCTION() virtual void OnTriggerEnter(PhysicsColliderActor* c); /// /// Called when a trigger touching end gets registered for this collider (the other collider enters it and triggers the event). /// /// The other collider. API_FUNCTION() virtual void OnTriggerExit(PhysicsColliderActor* c); };