// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
#pragma once
#include "Engine/Core/Math/Vector3.h"
class PhysicsColliderActor;
///
/// Contains a contact point data for the collision location.
///
API_STRUCT() struct FLAXENGINE_API ContactPoint
{
DECLARE_SCRIPTING_TYPE_MINIMAL(ContactPoint);
///
/// The contact point location in the world space.
///
API_FIELD() Vector3 Point;
///
/// The separation value (negative implies penetration).
///
API_FIELD() float Separation;
///
/// The contact normal.
///
API_FIELD() Vector3 Normal;
};
template<>
struct TIsPODType
{
enum { Value = true };
};
// The maximum amount of the contact points to be stored within a single collision data (higher amount will be skipped).
#define COLLISION_NAX_CONTACT_POINTS 8
///
/// Contains a collision information passed to the OnCollisionEnter/OnCollisionExit events.
///
API_STRUCT() struct FLAXENGINE_API Collision
{
DECLARE_SCRIPTING_TYPE_MINIMAL(Collision);
///
/// The first collider (this instance).
///
API_FIELD() PhysicsColliderActor* ThisActor;
///
/// The second collider (other instance).
///
API_FIELD() PhysicsColliderActor* OtherActor;
///
/// The total impulse applied to this contact pair to resolve the collision.
///
///
/// The total impulse is obtained by summing up impulses applied at all contact points in this collision pair.
///
API_FIELD() Vector3 Impulse;
///
/// The linear velocity of the first colliding object (this instance).
///
API_FIELD() Vector3 ThisVelocity;
///
/// The linear velocity of the second colliding object (other instance).
///
API_FIELD() Vector3 OtherVelocity;
///
/// The amount of valid contact points (less or equal to COLLISION_NAX_CONTACT_POINTS).
///
API_FIELD() int32 ContactsCount;
///
/// The contacts locations.
///
API_FIELD(Private, NoArray) ContactPoint Contacts[COLLISION_NAX_CONTACT_POINTS];
public:
///
/// Gets the relative linear velocity of the two colliding objects.
///
///
/// Can be used to detect stronger collisions.
///
Vector3 GetRelativeVelocity() const
{
return ThisVelocity - OtherVelocity;
}
///
/// Swaps the colliding objects (swaps A with B).
///
void SwapObjects()
{
Swap(ThisActor, OtherActor);
Swap(ThisVelocity, OtherVelocity);
}
};