Add physics queries for convex meshes
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "Physics.h"
|
||||
#include "Utilities.h"
|
||||
#include "CollisionData.h"
|
||||
#include "Actors/PhysicsColliderActor.h"
|
||||
#include <ThirdParty/PhysX/PxScene.h>
|
||||
#include <ThirdParty/PhysX/PxQueryFiltering.h>
|
||||
@@ -403,6 +404,57 @@ bool Physics::CapsuleCastAll(const Vector3& center, const float radius, const fl
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Physics::ConvexCast(const Vector3& center, const CollisionData* convexMesh, const Vector3& scale, const Vector3& direction, const Quaternion& rotation, const float maxDistance, uint32 layerMask, bool hitTriggers)
|
||||
{
|
||||
CHECK_RETURN(convexMesh && convexMesh->GetOptions().Type == CollisionDataType::ConvexMesh, false)
|
||||
|
||||
// Prepare data
|
||||
SCENE_QUERY_SETUP_SWEEP_1();
|
||||
const PxTransform pose(C2P(center), C2P(rotation));
|
||||
const PxConvexMeshGeometry geometry(convexMesh->GetConvex(), PxMeshScale(C2P(scale)));
|
||||
|
||||
// Perform sweep test
|
||||
return GetScene()->sweep(geometry, pose, C2P(direction), maxDistance, buffer, hitFlags, filterData, GetQueryFilterCallback());
|
||||
}
|
||||
|
||||
bool Physics::ConvexCast(const Vector3& center, const CollisionData* convexMesh, const Vector3& scale, const Vector3& direction, RayCastHit& hitInfo, const Quaternion& rotation, const float maxDistance, uint32 layerMask, bool hitTriggers)
|
||||
{
|
||||
CHECK_RETURN(convexMesh && convexMesh->GetOptions().Type == CollisionDataType::ConvexMesh, false)
|
||||
|
||||
// Prepare data
|
||||
SCENE_QUERY_SETUP_SWEEP_1();
|
||||
const PxTransform pose(C2P(center), C2P(rotation));
|
||||
const PxConvexMeshGeometry geometry(convexMesh->GetConvex(), PxMeshScale(C2P(scale)));
|
||||
|
||||
// Perform sweep test
|
||||
if (!GetScene()->sweep(geometry, pose, C2P(direction), maxDistance, buffer, hitFlags, filterData, GetQueryFilterCallback()))
|
||||
return false;
|
||||
|
||||
// Collect results
|
||||
SCENE_QUERY_COLLECT_SINGLE();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Physics::ConvexCastAll(const Vector3& center, const CollisionData* convexMesh, const Vector3& scale, const Vector3& direction, Array<RayCastHit>& results, const Quaternion& rotation, const float maxDistance, uint32 layerMask, bool hitTriggers)
|
||||
{
|
||||
CHECK_RETURN(convexMesh && convexMesh->GetOptions().Type == CollisionDataType::ConvexMesh, false)
|
||||
|
||||
// Prepare data
|
||||
SCENE_QUERY_SETUP_SWEEP();
|
||||
const PxTransform pose(C2P(center), C2P(rotation));
|
||||
const PxConvexMeshGeometry geometry(convexMesh->GetConvex(), PxMeshScale(C2P(scale)));
|
||||
|
||||
// Perform sweep test
|
||||
if (!GetScene()->sweep(geometry, pose, C2P(direction), maxDistance, buffer, hitFlags, filterData, GetQueryFilterCallback()))
|
||||
return false;
|
||||
|
||||
// Collect results
|
||||
SCENE_QUERY_COLLECT_ALL();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Physics::CheckBox(const Vector3& center, const Vector3& halfExtents, const Quaternion& rotation, uint32 layerMask, bool hitTriggers)
|
||||
{
|
||||
// Prepare data
|
||||
@@ -436,6 +488,19 @@ bool Physics::CheckCapsule(const Vector3& center, const float radius, const floa
|
||||
return GetScene()->overlap(geometry, pose, buffer, filterData, GetQueryFilterCallback());
|
||||
}
|
||||
|
||||
bool Physics::CheckConvex(const Vector3& center, const CollisionData* convexMesh, const Vector3& scale, const Quaternion& rotation, uint32 layerMask, bool hitTriggers)
|
||||
{
|
||||
CHECK_RETURN(convexMesh && convexMesh->GetOptions().Type == CollisionDataType::ConvexMesh, false)
|
||||
|
||||
// Prepare data
|
||||
SCENE_QUERY_SETUP_OVERLAP_1();
|
||||
const PxTransform pose(C2P(center), C2P(rotation));
|
||||
const PxConvexMeshGeometry geometry(convexMesh->GetConvex(), PxMeshScale(C2P(scale)));
|
||||
|
||||
// Perform overlap test
|
||||
return GetScene()->overlap(geometry, pose, buffer, filterData, GetQueryFilterCallback());
|
||||
}
|
||||
|
||||
bool Physics::OverlapBox(const Vector3& center, const Vector3& halfExtents, Array<Collider*>& results, const Quaternion& rotation, uint32 layerMask, bool hitTriggers)
|
||||
{
|
||||
// Prepare data
|
||||
@@ -487,6 +552,25 @@ bool Physics::OverlapCapsule(const Vector3& center, const float radius, const fl
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Physics::OverlapConvex(const Vector3& center, const CollisionData* convexMesh, const Vector3& scale, Array<Collider*>& results, const Quaternion& rotation, uint32 layerMask, bool hitTriggers)
|
||||
{
|
||||
CHECK_RETURN(convexMesh && convexMesh->GetOptions().Type == CollisionDataType::ConvexMesh, false)
|
||||
|
||||
// Prepare data
|
||||
SCENE_QUERY_SETUP_OVERLAP();
|
||||
const PxTransform pose(C2P(center), C2P(rotation));
|
||||
const PxConvexMeshGeometry geometry(convexMesh->GetConvex(), PxMeshScale(C2P(scale)));
|
||||
|
||||
// Perform overlap test
|
||||
if (!GetScene()->overlap(geometry, pose, buffer, filterData, GetQueryFilterCallback()))
|
||||
return false;
|
||||
|
||||
// Collect results
|
||||
SCENE_QUERY_COLLECT_OVERLAP_COLLIDER();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Physics::OverlapBox(const Vector3& center, const Vector3& halfExtents, Array<PhysicsColliderActor*>& results, const Quaternion& rotation, uint32 layerMask, bool hitTriggers)
|
||||
{
|
||||
// Prepare data
|
||||
@@ -537,3 +621,22 @@ bool Physics::OverlapCapsule(const Vector3& center, const float radius, const fl
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Physics::OverlapConvex(const Vector3& center, const CollisionData* convexMesh, const Vector3& scale, Array<PhysicsColliderActor*>& results, const Quaternion& rotation, uint32 layerMask, bool hitTriggers)
|
||||
{
|
||||
CHECK_RETURN(convexMesh && convexMesh->GetOptions().Type == CollisionDataType::ConvexMesh, false)
|
||||
|
||||
// Prepare data
|
||||
SCENE_QUERY_SETUP_OVERLAP();
|
||||
const PxTransform pose(C2P(center), C2P(rotation));
|
||||
const PxConvexMeshGeometry geometry(convexMesh->GetConvex(), PxMeshScale(C2P(scale)));
|
||||
|
||||
// Perform overlap test
|
||||
if (!GetScene()->overlap(geometry, pose, buffer, filterData, GetQueryFilterCallback()))
|
||||
return false;
|
||||
|
||||
// Collect results
|
||||
SCENE_QUERY_COLLECT_OVERLAP();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
class PhysicsColliderActor;
|
||||
class Joint;
|
||||
class Collider;
|
||||
class CollisionData;
|
||||
|
||||
/// <summary>
|
||||
/// Raycast hit result data.
|
||||
@@ -271,10 +272,10 @@ public:
|
||||
/// <summary>
|
||||
/// Performs a sweep test against objects in the scene using a capsule geometry.
|
||||
/// </summary>
|
||||
/// <param name="center">The box center.</param>
|
||||
/// <param name="center">The capsule center.</param>
|
||||
/// <param name="radius">The radius of the capsule.</param>
|
||||
/// <param name="height">The height of the capsule, excluding the top and bottom spheres.</param>
|
||||
/// <param name="direction">The normalized direction in which cast a box.</param>
|
||||
/// <param name="direction">The normalized direction in which cast a capsule.</param>
|
||||
/// <param name="rotation">The capsule rotation.</param>
|
||||
/// <param name="maxDistance">The maximum distance the ray should check for collisions.</param>
|
||||
/// <param name="layerMask">The layer mask used to filter the results.</param>
|
||||
@@ -285,10 +286,10 @@ public:
|
||||
/// <summary>
|
||||
/// Performs a sweep test against objects in the scene using a capsule geometry.
|
||||
/// </summary>
|
||||
/// <param name="center">The box center.</param>
|
||||
/// <param name="center">The capsule center.</param>
|
||||
/// <param name="radius">The radius of the capsule.</param>
|
||||
/// <param name="height">The height of the capsule, excluding the top and bottom spheres.</param>
|
||||
/// <param name="direction">The normalized direction in which cast a box.</param>
|
||||
/// <param name="direction">The normalized direction in which cast a capsule.</param>
|
||||
/// <param name="hitInfo">The result hit information. Valid only when method returns true.</param>
|
||||
/// <param name="rotation">The capsule rotation.</param>
|
||||
/// <param name="maxDistance">The maximum distance the ray should check for collisions.</param>
|
||||
@@ -300,10 +301,10 @@ public:
|
||||
/// <summary>
|
||||
/// Performs a sweep test against objects in the scene using a capsule geometry.
|
||||
/// </summary>
|
||||
/// <param name="center">The box center.</param>
|
||||
/// <param name="center">The capsule center.</param>
|
||||
/// <param name="radius">The radius of the capsule.</param>
|
||||
/// <param name="height">The height of the capsule, excluding the top and bottom spheres.</param>
|
||||
/// <param name="direction">The normalized direction in which cast a box.</param>
|
||||
/// <param name="direction">The normalized direction in which cast a capsule.</param>
|
||||
/// <param name="results">The result hits. Valid only when method returns true.</param>
|
||||
/// <param name="rotation">The capsule rotation.</param>
|
||||
/// <param name="maxDistance">The maximum distance the ray should check for collisions.</param>
|
||||
@@ -312,6 +313,50 @@ public:
|
||||
/// <returns>True if capsule hits an matching object, otherwise false.</returns>
|
||||
API_FUNCTION() static bool CapsuleCastAll(const Vector3& center, float radius, float height, const Vector3& direction, API_PARAM(Out) Array<RayCastHit, HeapAllocation>& results, const Quaternion& rotation = Quaternion::Identity, float maxDistance = MAX_float, uint32 layerMask = MAX_uint32, bool hitTriggers = true);
|
||||
|
||||
/// <summary>
|
||||
/// Performs a sweep test against objects in the scene using a convex mesh.
|
||||
/// </summary>
|
||||
/// <param name="center">The convex mesh center.</param>
|
||||
/// <param name="convexMesh">Collision data of the convex mesh.</param>
|
||||
/// <param name="scale">The scale of the convex mesh.</param>
|
||||
/// <param name="direction">The normalized direction in which cast a convex mesh.</param>
|
||||
/// <param name="rotation">The convex mesh rotation.</param>
|
||||
/// <param name="maxDistance">The maximum distance the ray should check for collisions.</param>
|
||||
/// <param name="layerMask">The layer mask used to filter the results.</param>
|
||||
/// <param name="hitTriggers">If set to <c>true</c> triggers will be hit, otherwise will skip them.</param>
|
||||
/// <returns>True if convex mesh hits an matching object, otherwise false.</returns>
|
||||
API_FUNCTION() static bool ConvexCast(const Vector3& center, const CollisionData* convexMesh, const Vector3& scale, const Vector3& direction, const Quaternion& rotation = Quaternion::Identity, float maxDistance = MAX_float, uint32 layerMask = MAX_uint32, bool hitTriggers = true);
|
||||
|
||||
/// <summary>
|
||||
/// Performs a sweep test against objects in the scene using a convex mesh.
|
||||
/// </summary>
|
||||
/// <param name="center">The convex mesh center.</param>
|
||||
/// <param name="convexMesh">Collision data of the convex mesh.</param>
|
||||
/// <param name="scale">The scale of the convex mesh.</param>
|
||||
/// <param name="direction">The normalized direction in which cast a convex mesh.</param>
|
||||
/// <param name="hitInfo">The result hit information. Valid only when method returns true.</param>
|
||||
/// <param name="rotation">The convex mesh rotation.</param>
|
||||
/// <param name="maxDistance">The maximum distance the ray should check for collisions.</param>
|
||||
/// <param name="layerMask">The layer mask used to filter the results.</param>
|
||||
/// <param name="hitTriggers">If set to <c>true</c> triggers will be hit, otherwise will skip them.</param>
|
||||
/// <returns>True if convex mesh hits an matching object, otherwise false.</returns>
|
||||
API_FUNCTION() static bool ConvexCast(const Vector3& center, const CollisionData* convexMesh, const Vector3& scale, const Vector3& direction, API_PARAM(Out) RayCastHit& hitInfo, const Quaternion& rotation = Quaternion::Identity, float maxDistance = MAX_float, uint32 layerMask = MAX_uint32, bool hitTriggers = true);
|
||||
|
||||
/// <summary>
|
||||
/// Performs a sweep test against objects in the scene using a convex mesh.
|
||||
/// </summary>
|
||||
/// <param name="center">The convex mesh center.</param>
|
||||
/// <param name="convexMesh">Collision data of the convex mesh.</param>
|
||||
/// <param name="scale">The scale of the convex mesh.</param>
|
||||
/// <param name="direction">The normalized direction in which cast a convex mesh.</param>
|
||||
/// <param name="results">The result hits. Valid only when method returns true.</param>
|
||||
/// <param name="rotation">The convex mesh rotation.</param>
|
||||
/// <param name="maxDistance">The maximum distance the ray should check for collisions.</param>
|
||||
/// <param name="layerMask">The layer mask used to filter the results.</param>
|
||||
/// <param name="hitTriggers">If set to <c>true</c> triggers will be hit, otherwise will skip them.</param>
|
||||
/// <returns>True if convex mesh hits an matching object, otherwise false.</returns>
|
||||
API_FUNCTION() static bool ConvexCastAll(const Vector3& center, const CollisionData* convexMesh, const Vector3& scale, const Vector3& direction, API_PARAM(Out) Array<RayCastHit, HeapAllocation>& results, const Quaternion& rotation = Quaternion::Identity, float maxDistance = MAX_float, uint32 layerMask = MAX_uint32, bool hitTriggers = true);
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether the given box overlaps with other colliders or not.
|
||||
/// </summary>
|
||||
@@ -345,6 +390,18 @@ public:
|
||||
/// <returns>True if capsule overlaps any matching object, otherwise false.</returns>
|
||||
API_FUNCTION() static bool CheckCapsule(const Vector3& center, float radius, float height, const Quaternion& rotation = Quaternion::Identity, uint32 layerMask = MAX_uint32, bool hitTriggers = true);
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether the given convex mesh overlaps with other colliders or not.
|
||||
/// </summary>
|
||||
/// <param name="center">The convex mesh center.</param>
|
||||
/// <param name="convexMesh">Collision data of the convex mesh.</param>
|
||||
/// <param name="scale">The scale of the convex mesh.</param>
|
||||
/// <param name="rotation">The convex mesh rotation.</param>
|
||||
/// <param name="layerMask">The layer mask used to filter the results.</param>
|
||||
/// <param name="hitTriggers">If set to <c>true</c> triggers will be hit, otherwise will skip them.</param>
|
||||
/// <returns>True if convex mesh overlaps any matching object, otherwise false.</returns>
|
||||
API_FUNCTION() static bool CheckConvex(const Vector3& center, const CollisionData* convexMesh, const Vector3& scale, const Quaternion& rotation = Quaternion::Identity, uint32 layerMask = MAX_uint32, bool hitTriggers = true);
|
||||
|
||||
/// <summary>
|
||||
/// Finds all colliders touching or inside of the given box.
|
||||
/// </summary>
|
||||
@@ -369,18 +426,31 @@ public:
|
||||
API_FUNCTION() static bool OverlapSphere(const Vector3& center, float radius, API_PARAM(Out) Array<Collider*, HeapAllocation>& results, uint32 layerMask = MAX_uint32, bool hitTriggers = true);
|
||||
|
||||
/// <summary>
|
||||
/// Finds all colliders touching or inside of the given sphere.
|
||||
/// Finds all colliders touching or inside of the given capsule.
|
||||
/// </summary>
|
||||
/// <param name="center">The sphere center.</param>
|
||||
/// <param name="center">The capsule center.</param>
|
||||
/// <param name="radius">The radius of the capsule.</param>
|
||||
/// <param name="height">The height of the capsule, excluding the top and bottom spheres.</param>
|
||||
/// <param name="results">The result colliders that overlap with the given sphere. Valid only when method returns true.</param>
|
||||
/// <param name="results">The result colliders that overlap with the given capsule. Valid only when method returns true.</param>
|
||||
/// <param name="rotation">The capsule rotation.</param>
|
||||
/// <param name="layerMask">The layer mask used to filter the results.</param>
|
||||
/// <param name="hitTriggers">If set to <c>true</c> triggers will be hit, otherwise will skip them.</param>
|
||||
/// <returns>True if capsule overlaps any matching object, otherwise false.</returns>
|
||||
API_FUNCTION() static bool OverlapCapsule(const Vector3& center, float radius, float height, API_PARAM(Out) Array<Collider*, HeapAllocation>& results, const Quaternion& rotation = Quaternion::Identity, uint32 layerMask = MAX_uint32, bool hitTriggers = true);
|
||||
|
||||
/// <summary>
|
||||
/// Finds all colliders touching or inside of the given convex mesh.
|
||||
/// </summary>
|
||||
/// <param name="center">The convex mesh center.</param>
|
||||
/// <param name="convexMesh">Collision data of the convex mesh.</param>
|
||||
/// <param name="scale">The scale of the convex mesh.</param>
|
||||
/// <param name="results">The result colliders that overlap with the given convex mesh. Valid only when method returns true.</param>
|
||||
/// <param name="rotation">The convex mesh rotation.</param>
|
||||
/// <param name="layerMask">The layer mask used to filter the results.</param>
|
||||
/// <param name="hitTriggers">If set to <c>true</c> triggers will be hit, otherwise will skip them.</param>
|
||||
/// <returns>True if convex mesh overlaps any matching object, otherwise false.</returns>
|
||||
API_FUNCTION() static bool OverlapConvex(const Vector3& center, const CollisionData* convexMesh, const Vector3& scale, API_PARAM(Out) Array<Collider*, HeapAllocation>& results, const Quaternion& rotation = Quaternion::Identity, uint32 layerMask = MAX_uint32, bool hitTriggers = true);
|
||||
|
||||
/// <summary>
|
||||
/// Finds all colliders touching or inside of the given box.
|
||||
/// </summary>
|
||||
@@ -405,18 +475,31 @@ public:
|
||||
API_FUNCTION() static bool OverlapSphere(const Vector3& center, float radius, API_PARAM(Out) Array<PhysicsColliderActor*, HeapAllocation>& results, uint32 layerMask = MAX_uint32, bool hitTriggers = true);
|
||||
|
||||
/// <summary>
|
||||
/// Finds all colliders touching or inside of the given sphere.
|
||||
/// Finds all colliders touching or inside of the given capsule.
|
||||
/// </summary>
|
||||
/// <param name="center">The capsule center.</param>
|
||||
/// <param name="radius">The radius of the capsule.</param>
|
||||
/// <param name="height">The height of the capsule, excluding the top and bottom spheres.</param>
|
||||
/// <param name="results">The result colliders that overlap with the given sphere. Valid only when method returns true.</param>
|
||||
/// <param name="results">The result colliders that overlap with the given capsule. Valid only when method returns true.</param>
|
||||
/// <param name="rotation">The capsule rotation.</param>
|
||||
/// <param name="layerMask">The layer mask used to filter the results.</param>
|
||||
/// <param name="hitTriggers">If set to <c>true</c> triggers will be hit, otherwise will skip them.</param>
|
||||
/// <returns>True if capsule overlaps any matching object, otherwise false.</returns>
|
||||
API_FUNCTION() static bool OverlapCapsule(const Vector3& center, float radius, float height, API_PARAM(Out) Array<PhysicsColliderActor*, HeapAllocation>& results, const Quaternion& rotation = Quaternion::Identity, uint32 layerMask = MAX_uint32, bool hitTriggers = true);
|
||||
|
||||
/// <summary>
|
||||
/// Finds all colliders touching or inside of the given convex mesh.
|
||||
/// </summary>
|
||||
/// <param name="center">The convex mesh center.</param>
|
||||
/// <param name="convexMesh">Collision data of the convex mesh.</param>
|
||||
/// <param name="scale">The scale of the convex mesh.</param>
|
||||
/// <param name="results">The result colliders that overlap with the given convex mesh. Valid only when method returns true.</param>
|
||||
/// <param name="rotation">The convex mesh rotation.</param>
|
||||
/// <param name="layerMask">The layer mask used to filter the results.</param>
|
||||
/// <param name="hitTriggers">If set to <c>true</c> triggers will be hit, otherwise will skip them.</param>
|
||||
/// <returns>True if convex mesh overlaps any matching object, otherwise false.</returns>
|
||||
API_FUNCTION() static bool OverlapConvex(const Vector3& center, const CollisionData* convexMesh, const Vector3& scale, API_PARAM(Out) Array<PhysicsColliderActor*, HeapAllocation>& results, const Quaternion& rotation = Quaternion::Identity, uint32 layerMask = MAX_uint32, bool hitTriggers = true);
|
||||
|
||||
public:
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user