diff --git a/Source/Engine/Physics/Actors/PhysicsColliderActor.h b/Source/Engine/Physics/Actors/PhysicsColliderActor.h index caea76c79..92693695d 100644 --- a/Source/Engine/Physics/Actors/PhysicsColliderActor.h +++ b/Source/Engine/Physics/Actors/PhysicsColliderActor.h @@ -5,6 +5,7 @@ #include "Engine/Level/Actor.h" #include "Engine/Physics/Collisions.h" +struct RayCastHit; struct Collision; /// @@ -42,6 +43,40 @@ public: /// 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). diff --git a/Source/Engine/Physics/Colliders/Collider.h b/Source/Engine/Physics/Colliders/Collider.h index cbbb7e522..68f5fe346 100644 --- a/Source/Engine/Physics/Colliders/Collider.h +++ b/Source/Engine/Physics/Colliders/Collider.h @@ -84,40 +84,6 @@ public: JsonAssetReference Material; public: - /// - /// 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() bool RayCast(const Vector3& origin, const Vector3& direction, API_PARAM(Out) float& resultHitDistance, float maxDistance = MAX_float) const; - - /// - /// 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() bool RayCast(const Vector3& origin, const Vector3& direction, API_PARAM(Out) RayCastHit& hitInfo, float maxDistance = MAX_float) const; - - /// - /// 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() void ClosestPoint(const Vector3& point, API_PARAM(Out) Vector3& result) const; - - /// - /// 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() bool ContainsPoint(const Vector3& point) const; - /// /// Computes minimum translational distance between two geometry objects. /// Translating the first collider by direction * distance will separate the colliders apart if the function returned true. Otherwise, direction and distance are not defined. @@ -198,6 +164,10 @@ private: public: // [PhysicsColliderActor] RigidBody* GetAttachedRigidBody() const override; + bool RayCast(const Vector3& origin, const Vector3& direction, float& resultHitDistance, float maxDistance = MAX_float) const final; + bool RayCast(const Vector3& origin, const Vector3& direction, RayCastHit& hitInfo, float maxDistance = MAX_float) const final; + void ClosestPoint(const Vector3& point, Vector3& result) const final; + bool ContainsPoint(const Vector3& point) const final; protected: // [PhysicsColliderActor] diff --git a/Source/Engine/Physics/PhysX/PhysicsBackendPhysX.cpp b/Source/Engine/Physics/PhysX/PhysicsBackendPhysX.cpp index cb2f3e736..9d0d2ea16 100644 --- a/Source/Engine/Physics/PhysX/PhysicsBackendPhysX.cpp +++ b/Source/Engine/Physics/PhysX/PhysicsBackendPhysX.cpp @@ -2630,6 +2630,7 @@ bool PhysicsBackend::RayCastShape(void* shape, const Vector3& position, const Qu PxRaycastHit hit; if (PxGeometryQuery::raycast(C2P(origin - sceneOrigin), C2P(direction), shapePhysX->getGeometry(), trans, maxDistance, SCENE_QUERY_FLAGS, 1, &hit) == 0) return false; + hit.shape = shapePhysX; P2C(hit, hitInfo); hitInfo.Point += sceneOrigin; return true; diff --git a/Source/Engine/Physics/PhysX/SimulationEventCallbackPhysX.cpp b/Source/Engine/Physics/PhysX/SimulationEventCallbackPhysX.cpp index fc33b0dfe..62e588771 100644 --- a/Source/Engine/Physics/PhysX/SimulationEventCallbackPhysX.cpp +++ b/Source/Engine/Physics/PhysX/SimulationEventCallbackPhysX.cpp @@ -163,14 +163,11 @@ void SimulationEventCallback::onContact(const PxContactPairHeader& pairHeader, c c.ThisVelocity = c.OtherVelocity = Vector3::Zero; if (hasPostVelocities && j.nextItemSet()) { - ASSERT(j.contactPairIndex == pairIndex); + ASSERT_LOW_LAYER(j.contactPairIndex == pairIndex); if (j.postSolverVelocity) { - const PxVec3 linearVelocityActor0 = j.postSolverVelocity->linearVelocity[0]; - const PxVec3 linearVelocityActor1 = j.postSolverVelocity->linearVelocity[1]; - - c.ThisVelocity = P2C(linearVelocityActor0); - c.OtherVelocity = P2C(linearVelocityActor1); + c.ThisVelocity = P2C(j.postSolverVelocity->linearVelocity[0]); + c.OtherVelocity = P2C(j.postSolverVelocity->linearVelocity[1]); } } diff --git a/Source/Engine/Terrain/Terrain.cpp b/Source/Engine/Terrain/Terrain.cpp index 3f71760c3..497e9bf80 100644 --- a/Source/Engine/Terrain/Terrain.cpp +++ b/Source/Engine/Terrain/Terrain.cpp @@ -185,7 +185,7 @@ bool Terrain::RayCast(const Vector3& origin, const Vector3& direction, RayCastHi return result; } -void Terrain::ClosestPoint(const Vector3& position, Vector3& result) const +void Terrain::ClosestPoint(const Vector3& point, Vector3& result) const { Real minDistance = MAX_Real; Vector3 tmp; @@ -194,8 +194,8 @@ void Terrain::ClosestPoint(const Vector3& position, Vector3& result) const const auto patch = _patches[pathIndex]; if (patch->HasCollision()) { - patch->ClosestPoint(position, tmp); - const auto distance = Vector3::DistanceSquared(position, tmp); + patch->ClosestPoint(point, tmp); + const auto distance = Vector3::DistanceSquared(point, tmp); if (distance < minDistance) { minDistance = distance; @@ -205,6 +205,11 @@ void Terrain::ClosestPoint(const Vector3& position, Vector3& result) const } } +bool Terrain::ContainsPoint(const Vector3& point) const +{ + return false; +} + void Terrain::DrawPatch(const RenderContext& renderContext, const Int2& patchCoord, MaterialBase* material, int32 lodIndex) const { auto patch = GetPatch(patchCoord); diff --git a/Source/Engine/Terrain/Terrain.h b/Source/Engine/Terrain/Terrain.h index aad0e4e1b..dd9dc1926 100644 --- a/Source/Engine/Terrain/Terrain.h +++ b/Source/Engine/Terrain/Terrain.h @@ -367,16 +367,6 @@ public: void RemoveLightmap(); public: - /// - /// Performs a raycast against this terrain collision 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() bool RayCast(const Vector3& origin, const Vector3& direction, float& resultHitDistance, float maxDistance = MAX_float) const; - /// /// Performs a raycast against this terrain collision shape. Returns the hit chunk. /// @@ -399,23 +389,6 @@ public: /// True if ray hits an object, otherwise false. API_FUNCTION() bool RayCast(const Ray& ray, API_PARAM(Out) float& resultHitDistance, API_PARAM(Out) Int2& resultPatchCoord, API_PARAM(Out) Int2& resultChunkCoord, float maxDistance = MAX_float) const; - /// - /// Performs a raycast against terrain collision, 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() bool RayCast(const Vector3& origin, const Vector3& direction, API_PARAM(Out) RayCastHit& hitInfo, float maxDistance = MAX_float) const; - - /// - /// Gets a point on the terrain 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() void ClosestPoint(const Vector3& position, API_PARAM(Out) Vector3& result) const; - /// /// Draws the terrain patch. /// @@ -451,6 +424,10 @@ public: void Serialize(SerializeStream& stream, const void* otherObj) override; void Deserialize(DeserializeStream& stream, ISerializeModifier* modifier) override; RigidBody* GetAttachedRigidBody() const override; + bool RayCast(const Vector3& origin, const Vector3& direction, float& resultHitDistance, float maxDistance = MAX_float) const final; + bool RayCast(const Vector3& origin, const Vector3& direction, RayCastHit& hitInfo, float maxDistance = MAX_float) const final; + void ClosestPoint(const Vector3& point, Vector3& result) const final; + bool ContainsPoint(const Vector3& point) const final; protected: // [PhysicsColliderActor]