Path: blob/master/thirdparty/jolt_physics/Jolt/Physics/Collision/NarrowPhaseQuery.h
9912 views
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)1// SPDX-FileCopyrightText: 2021 Jorrit Rouwe2// SPDX-License-Identifier: MIT34#pragma once56#include <Jolt/Physics/Body/BodyFilter.h>7#include <Jolt/Physics/Body/BodyLock.h>8#include <Jolt/Physics/Body/BodyLockInterface.h>9#include <Jolt/Physics/Collision/ShapeFilter.h>10#include <Jolt/Physics/Collision/BroadPhase/BroadPhaseQuery.h>11#include <Jolt/Physics/Collision/BackFaceMode.h>1213JPH_NAMESPACE_BEGIN1415class Shape;16class CollideShapeSettings;17class RayCastResult;1819/// Class that provides an interface for doing precise collision detection against the broad and then the narrow phase.20/// Unlike a BroadPhaseQuery, the NarrowPhaseQuery will test against shapes and will return collision information against triangles, spheres etc.21class JPH_EXPORT NarrowPhaseQuery : public NonCopyable22{23public:24/// Initialize the interface (should only be called by PhysicsSystem)25void Init(BodyLockInterface &inBodyLockInterface, BroadPhaseQuery &inBroadPhaseQuery) { mBodyLockInterface = &inBodyLockInterface; mBroadPhaseQuery = &inBroadPhaseQuery; }2627/// Cast a ray and find the closest hit. Returns true if it finds a hit. Hits further than ioHit.mFraction will not be considered and in this case ioHit will remain unmodified (and the function will return false).28/// Convex objects will be treated as solid (meaning if the ray starts inside, you'll get a hit fraction of 0) and back face hits against triangles are returned.29/// If you want the surface normal of the hit use Body::GetWorldSpaceSurfaceNormal(ioHit.mSubShapeID2, inRay.GetPointOnRay(ioHit.mFraction)) on body with ID ioHit.mBodyID.30bool CastRay(const RRayCast &inRay, RayCastResult &ioHit, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter = { }, const ObjectLayerFilter &inObjectLayerFilter = { }, const BodyFilter &inBodyFilter = { }) const;3132/// Cast a ray, allows collecting multiple hits. Note that this version is more flexible but also slightly slower than the CastRay function that returns only a single hit.33/// If you want the surface normal of the hit use Body::GetWorldSpaceSurfaceNormal(collected sub shape ID, inRay.GetPointOnRay(collected fraction)) on body with collected body ID.34void CastRay(const RRayCast &inRay, const RayCastSettings &inRayCastSettings, CastRayCollector &ioCollector, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter = { }, const ObjectLayerFilter &inObjectLayerFilter = { }, const BodyFilter &inBodyFilter = { }, const ShapeFilter &inShapeFilter = { }) const;3536/// Check if inPoint is inside any shapes. For this tests all shapes are treated as if they were solid.37/// For a mesh shape, this test will only provide sensible information if the mesh is a closed manifold.38/// For each shape that collides, ioCollector will receive a hit39void CollidePoint(RVec3Arg inPoint, CollidePointCollector &ioCollector, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter = { }, const ObjectLayerFilter &inObjectLayerFilter = { }, const BodyFilter &inBodyFilter = { }, const ShapeFilter &inShapeFilter = { }) const;4041/// Collide a shape with the system42/// @param inShape Shape to test43/// @param inShapeScale Scale in local space of shape44/// @param inCenterOfMassTransform Center of mass transform for the shape45/// @param inCollideShapeSettings Settings46/// @param inBaseOffset All hit results will be returned relative to this offset, can be zero to get results in world position, but when you're testing far from the origin you get better precision by picking a position that's closer e.g. inCenterOfMassTransform.GetTranslation() since floats are most accurate near the origin47/// @param ioCollector Collector that receives the hits48/// @param inBroadPhaseLayerFilter Filter that filters at broadphase level49/// @param inObjectLayerFilter Filter that filters at layer level50/// @param inBodyFilter Filter that filters at body level51/// @param inShapeFilter Filter that filters at shape level52void CollideShape(const Shape *inShape, Vec3Arg inShapeScale, RMat44Arg inCenterOfMassTransform, const CollideShapeSettings &inCollideShapeSettings, RVec3Arg inBaseOffset, CollideShapeCollector &ioCollector, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter = { }, const ObjectLayerFilter &inObjectLayerFilter = { }, const BodyFilter &inBodyFilter = { }, const ShapeFilter &inShapeFilter = { }) const;5354/// Same as CollideShape, but uses InternalEdgeRemovingCollector to remove internal edges from the collision results (a.k.a. ghost collisions)55void CollideShapeWithInternalEdgeRemoval(const Shape *inShape, Vec3Arg inShapeScale, RMat44Arg inCenterOfMassTransform, const CollideShapeSettings &inCollideShapeSettings, RVec3Arg inBaseOffset, CollideShapeCollector &ioCollector, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter = { }, const ObjectLayerFilter &inObjectLayerFilter = { }, const BodyFilter &inBodyFilter = { }, const ShapeFilter &inShapeFilter = { }) const;5657/// Cast a shape and report any hits to ioCollector58/// @param inShapeCast The shape cast and its position and direction59/// @param inShapeCastSettings Settings for the shape cast60/// @param inBaseOffset All hit results will be returned relative to this offset, can be zero to get results in world position, but when you're testing far from the origin you get better precision by picking a position that's closer e.g. inShapeCast.mCenterOfMassStart.GetTranslation() since floats are most accurate near the origin61/// @param ioCollector Collector that receives the hits62/// @param inBroadPhaseLayerFilter Filter that filters at broadphase level63/// @param inObjectLayerFilter Filter that filters at layer level64/// @param inBodyFilter Filter that filters at body level65/// @param inShapeFilter Filter that filters at shape level66void CastShape(const RShapeCast &inShapeCast, const ShapeCastSettings &inShapeCastSettings, RVec3Arg inBaseOffset, CastShapeCollector &ioCollector, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter = { }, const ObjectLayerFilter &inObjectLayerFilter = { }, const BodyFilter &inBodyFilter = { }, const ShapeFilter &inShapeFilter = { }) const;6768/// Collect all leaf transformed shapes that fall inside world space box inBox69void CollectTransformedShapes(const AABox &inBox, TransformedShapeCollector &ioCollector, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter = { }, const ObjectLayerFilter &inObjectLayerFilter = { }, const BodyFilter &inBodyFilter = { }, const ShapeFilter &inShapeFilter = { }) const;7071private:72BodyLockInterface * mBodyLockInterface = nullptr;73BroadPhaseQuery * mBroadPhaseQuery = nullptr;74};7576JPH_NAMESPACE_END777879