From ac0cf0140480ea3c6e57c544ef73795aa4143a2a Mon Sep 17 00:00:00 2001 From: Ruan Lucas <79365912+RuanLucasGD@users.noreply.github.com> Date: Sat, 3 Jun 2023 13:25:29 -0400 Subject: [PATCH 1/3] add simple linecast to physics --- Source/Engine/Physics/Physics.cpp | 12 ++++++++++++ Source/Engine/Physics/Physics.h | 10 ++++++++++ Source/Engine/Physics/PhysicsScene.h | 10 ++++++++++ 3 files changed, 32 insertions(+) diff --git a/Source/Engine/Physics/Physics.cpp b/Source/Engine/Physics/Physics.cpp index 0a0178622..80f17873d 100644 --- a/Source/Engine/Physics/Physics.cpp +++ b/Source/Engine/Physics/Physics.cpp @@ -218,6 +218,11 @@ void Physics::FlushRequests() PhysicsBackend::FlushRequests(); } +bool Physics::LineCast(const Vector3& start, const Vector3& end, uint32 layerMask, bool hitTriggers) +{ + return DefaultScene->LineCast(start, end, layerMask, hitTriggers); +} + bool Physics::RayCast(const Vector3& origin, const Vector3& direction, const float maxDistance, uint32 layerMask, bool hitTriggers) { return DefaultScene->RayCast(origin, direction, maxDistance, layerMask, hitTriggers); @@ -450,6 +455,13 @@ void PhysicsScene::CollectResults() _isDuringSimulation = false; } +bool PhysicsScene::LineCast(const Vector3& start, const Vector3& end, uint32 layerMask, bool hitTriggers) +{ + float distanceToEnd = Vector3::Distance(start, end); + Vector3 directionToEnd = (end - start).GetNormalized(); + return PhysicsBackend::RayCast(_scene, start, directionToEnd, distanceToEnd, layerMask, hitTriggers); +} + bool PhysicsScene::RayCast(const Vector3& origin, const Vector3& direction, const float maxDistance, uint32 layerMask, bool hitTriggers) { return PhysicsBackend::RayCast(_scene, origin, direction, maxDistance, layerMask, hitTriggers); diff --git a/Source/Engine/Physics/Physics.h b/Source/Engine/Physics/Physics.h index 62344e082..592f3c651 100644 --- a/Source/Engine/Physics/Physics.h +++ b/Source/Engine/Physics/Physics.h @@ -95,6 +95,16 @@ public: API_FUNCTION() static void FlushRequests(); public: + /// + /// Performs a line between two points in the scene. + /// + /// The start position of the line. + /// The end position of the line. + /// The layer mask used to filter the results. + /// If set to true triggers will be hit, otherwise will skip them. + /// True if ray hits an matching object, otherwise false. + API_FUNCTION() static bool LineCast(const Vector3& start, const Vector3& end, uint32 layerMask = MAX_uint32, bool hitTriggers = true); + /// /// Performs a raycast against objects in the scene. /// diff --git a/Source/Engine/Physics/PhysicsScene.h b/Source/Engine/Physics/PhysicsScene.h index 6b5ab41ab..946c35661 100644 --- a/Source/Engine/Physics/PhysicsScene.h +++ b/Source/Engine/Physics/PhysicsScene.h @@ -126,6 +126,16 @@ public: API_FUNCTION() void CollectResults(); public: + + /// + /// Performs a line between two points in the scene. + /// + /// The start position of the line. + /// The end position of the line. + /// The layer mask used to filter the results. + /// If set to true triggers will be hit, otherwise will skip them. + /// True if ray hits an matching object, otherwise false. + API_FUNCTION() bool LineCast(const Vector3& start, const Vector3& end, uint32 layerMask = MAX_uint32, bool hitOnTriggers = true); /// /// Performs a raycast against objects in the scene. /// From eda4def35ba302908b72ee3f2f6abe0e91556a76 Mon Sep 17 00:00:00 2001 From: Ruan Lucas <79365912+RuanLucasGD@users.noreply.github.com> Date: Sat, 3 Jun 2023 13:39:10 -0400 Subject: [PATCH 2/3] add linecast with hit info --- Source/Engine/Physics/Physics.cpp | 12 ++++++++++++ Source/Engine/Physics/Physics.h | 11 +++++++++++ Source/Engine/Physics/PhysicsScene.h | 12 ++++++++++++ 3 files changed, 35 insertions(+) diff --git a/Source/Engine/Physics/Physics.cpp b/Source/Engine/Physics/Physics.cpp index 80f17873d..6b3889e99 100644 --- a/Source/Engine/Physics/Physics.cpp +++ b/Source/Engine/Physics/Physics.cpp @@ -223,6 +223,11 @@ bool Physics::LineCast(const Vector3& start, const Vector3& end, uint32 layerMas return DefaultScene->LineCast(start, end, layerMask, hitTriggers); } +bool Physics::LineCast(const Vector3& start, const Vector3& end, API_PARAM(Out)RayCastHit& hitInfo, uint32 layerMask, bool hitTriggers) +{ + return DefaultScene->LineCast(start, end, hitInfo, layerMask, hitTriggers); +} + bool Physics::RayCast(const Vector3& origin, const Vector3& direction, const float maxDistance, uint32 layerMask, bool hitTriggers) { return DefaultScene->RayCast(origin, direction, maxDistance, layerMask, hitTriggers); @@ -462,6 +467,13 @@ bool PhysicsScene::LineCast(const Vector3& start, const Vector3& end, uint32 lay return PhysicsBackend::RayCast(_scene, start, directionToEnd, distanceToEnd, layerMask, hitTriggers); } +bool PhysicsScene::LineCast(const Vector3& start, const Vector3& end, API_PARAM(Out)RayCastHit& hitInfo, uint32 layerMask, bool hitTriggers) +{ + float distanceToEnd = Vector3::Distance(start, end); + Vector3 directionToEnd = (end - start).GetNormalized(); + return PhysicsBackend::RayCast(_scene, start, directionToEnd, hitInfo, distanceToEnd, layerMask, hitTriggers); +} + bool PhysicsScene::RayCast(const Vector3& origin, const Vector3& direction, const float maxDistance, uint32 layerMask, bool hitTriggers) { return PhysicsBackend::RayCast(_scene, origin, direction, maxDistance, layerMask, hitTriggers); diff --git a/Source/Engine/Physics/Physics.h b/Source/Engine/Physics/Physics.h index 592f3c651..9fede6222 100644 --- a/Source/Engine/Physics/Physics.h +++ b/Source/Engine/Physics/Physics.h @@ -105,6 +105,17 @@ public: /// True if ray hits an matching object, otherwise false. API_FUNCTION() static bool LineCast(const Vector3& start, const Vector3& end, uint32 layerMask = MAX_uint32, bool hitTriggers = true); + /// + /// Performs a line between two points in the scene. + /// + /// The start position of the line. + /// The end position of the line. + /// The result hit information. Valid only when method returns true. + /// The layer mask used to filter the results. + /// If set to true triggers will be hit, otherwise will skip them. + /// True if ray hits an matching object, otherwise false. + API_FUNCTION() static bool LineCast(const Vector3& start, const Vector3& end, API_PARAM(Out) RayCastHit& hitInfo, uint32 layerMask = MAX_uint32, bool hitTriggers = true); + /// /// Performs a raycast against objects in the scene. /// diff --git a/Source/Engine/Physics/PhysicsScene.h b/Source/Engine/Physics/PhysicsScene.h index 946c35661..3bd98e9c0 100644 --- a/Source/Engine/Physics/PhysicsScene.h +++ b/Source/Engine/Physics/PhysicsScene.h @@ -136,6 +136,18 @@ public: /// If set to true triggers will be hit, otherwise will skip them. /// True if ray hits an matching object, otherwise false. API_FUNCTION() bool LineCast(const Vector3& start, const Vector3& end, uint32 layerMask = MAX_uint32, bool hitOnTriggers = true); + + /// + /// Performs a line between two points in the scene. + /// + /// The start position of the line. + /// The end position of the line. + /// The result hit information. Valid only when method returns true. + /// The layer mask used to filter the results. + /// If set to true triggers will be hit, otherwise will skip them. + /// True if ray hits an matching object, otherwise false. + API_FUNCTION() bool LineCast(const Vector3& start, const Vector3& end, API_PARAM(Out) RayCastHit& hitInfo, uint32 layerMask = MAX_uint32, bool hitOnTriggers = true); + /// /// Performs a raycast against objects in the scene. /// From e32f4d5f8c74585ade62958f5c87185b36da9ede Mon Sep 17 00:00:00 2001 From: Ruan Lucas <79365912+RuanLucasGD@users.noreply.github.com> Date: Sat, 3 Jun 2023 13:52:50 -0400 Subject: [PATCH 3/3] add LineCastAll --- Source/Engine/Physics/Physics.cpp | 12 ++++++++++++ Source/Engine/Physics/Physics.h | 11 +++++++++++ Source/Engine/Physics/PhysicsScene.h | 11 +++++++++++ 3 files changed, 34 insertions(+) diff --git a/Source/Engine/Physics/Physics.cpp b/Source/Engine/Physics/Physics.cpp index 6b3889e99..9c6879c79 100644 --- a/Source/Engine/Physics/Physics.cpp +++ b/Source/Engine/Physics/Physics.cpp @@ -228,6 +228,11 @@ bool Physics::LineCast(const Vector3& start, const Vector3& end, API_PARAM(Out)R return DefaultScene->LineCast(start, end, hitInfo, layerMask, hitTriggers); } +bool Physics::LineCastAll(const Vector3& start, const Vector3& end, API_PARAM(Out)Array& results, uint32 layerMask, bool hitTriggers) +{ + return DefaultScene->LineCastAll(start, end, results, layerMask, hitTriggers); +} + bool Physics::RayCast(const Vector3& origin, const Vector3& direction, const float maxDistance, uint32 layerMask, bool hitTriggers) { return DefaultScene->RayCast(origin, direction, maxDistance, layerMask, hitTriggers); @@ -474,6 +479,13 @@ bool PhysicsScene::LineCast(const Vector3& start, const Vector3& end, API_PARAM( return PhysicsBackend::RayCast(_scene, start, directionToEnd, hitInfo, distanceToEnd, layerMask, hitTriggers); } +bool PhysicsScene::LineCastAll(const Vector3& start, const Vector3& end, API_PARAM(Out)Array& results, uint32 layerMask, bool hitTriggers) +{ + float distanceToEnd = Vector3::Distance(start, end); + Vector3 directionToEnd = (end - start).GetNormalized(); + return PhysicsBackend::RayCastAll(_scene, start, directionToEnd, results, distanceToEnd, layerMask, hitTriggers); +} + bool PhysicsScene::RayCast(const Vector3& origin, const Vector3& direction, const float maxDistance, uint32 layerMask, bool hitTriggers) { return PhysicsBackend::RayCast(_scene, origin, direction, maxDistance, layerMask, hitTriggers); diff --git a/Source/Engine/Physics/Physics.h b/Source/Engine/Physics/Physics.h index 9fede6222..3e7bff8d9 100644 --- a/Source/Engine/Physics/Physics.h +++ b/Source/Engine/Physics/Physics.h @@ -116,6 +116,17 @@ public: /// True if ray hits an matching object, otherwise false. API_FUNCTION() static bool LineCast(const Vector3& start, const Vector3& end, API_PARAM(Out) RayCastHit& hitInfo, uint32 layerMask = MAX_uint32, bool hitTriggers = true); + // + /// Performs a line between two points in the scene, returns all hitpoints infos. + /// + /// The origin of the ray. + /// The normalized direction of the ray. + /// The result hits. Valid only when method returns true. + /// The layer mask used to filter the results. + /// If set to true triggers will be hit, otherwise will skip them. + /// True if ray hits an matching object, otherwise false. + API_FUNCTION() static bool LineCastAll(const Vector3& start, const Vector3& end, API_PARAM(Out) Array& results, uint32 layerMask = MAX_uint32, bool hitTriggers = true); + /// /// Performs a raycast against objects in the scene. /// diff --git a/Source/Engine/Physics/PhysicsScene.h b/Source/Engine/Physics/PhysicsScene.h index 3bd98e9c0..683261eb8 100644 --- a/Source/Engine/Physics/PhysicsScene.h +++ b/Source/Engine/Physics/PhysicsScene.h @@ -148,6 +148,17 @@ public: /// True if ray hits an matching object, otherwise false. API_FUNCTION() bool LineCast(const Vector3& start, const Vector3& end, API_PARAM(Out) RayCastHit& hitInfo, uint32 layerMask = MAX_uint32, bool hitOnTriggers = true); + // + /// Performs a line between two points in the scene, returns all hitpoints infos. + /// + /// The origin of the ray. + /// The normalized direction of the ray. + /// The result hits. Valid only when method returns true. + /// The layer mask used to filter the results. + /// If set to true triggers will be hit, otherwise will skip them. + /// True if ray hits an matching object, otherwise false. + API_FUNCTION() bool LineCastAll(const Vector3& start, const Vector3& end, API_PARAM(Out) Array& results, uint32 layerMask = MAX_uint32, bool hitTriggers = true); + /// /// Performs a raycast against objects in the scene. ///