Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/jolt_physics/Jolt/Physics/Collision/NarrowPhaseQuery.h
9912 views
1
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2
// SPDX-FileCopyrightText: 2021 Jorrit Rouwe
3
// SPDX-License-Identifier: MIT
4
5
#pragma once
6
7
#include <Jolt/Physics/Body/BodyFilter.h>
8
#include <Jolt/Physics/Body/BodyLock.h>
9
#include <Jolt/Physics/Body/BodyLockInterface.h>
10
#include <Jolt/Physics/Collision/ShapeFilter.h>
11
#include <Jolt/Physics/Collision/BroadPhase/BroadPhaseQuery.h>
12
#include <Jolt/Physics/Collision/BackFaceMode.h>
13
14
JPH_NAMESPACE_BEGIN
15
16
class Shape;
17
class CollideShapeSettings;
18
class RayCastResult;
19
20
/// Class that provides an interface for doing precise collision detection against the broad and then the narrow phase.
21
/// Unlike a BroadPhaseQuery, the NarrowPhaseQuery will test against shapes and will return collision information against triangles, spheres etc.
22
class JPH_EXPORT NarrowPhaseQuery : public NonCopyable
23
{
24
public:
25
/// Initialize the interface (should only be called by PhysicsSystem)
26
void Init(BodyLockInterface &inBodyLockInterface, BroadPhaseQuery &inBroadPhaseQuery) { mBodyLockInterface = &inBodyLockInterface; mBroadPhaseQuery = &inBroadPhaseQuery; }
27
28
/// 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).
29
/// 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.
30
/// If you want the surface normal of the hit use Body::GetWorldSpaceSurfaceNormal(ioHit.mSubShapeID2, inRay.GetPointOnRay(ioHit.mFraction)) on body with ID ioHit.mBodyID.
31
bool CastRay(const RRayCast &inRay, RayCastResult &ioHit, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter = { }, const ObjectLayerFilter &inObjectLayerFilter = { }, const BodyFilter &inBodyFilter = { }) const;
32
33
/// 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.
34
/// 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.
35
void CastRay(const RRayCast &inRay, const RayCastSettings &inRayCastSettings, CastRayCollector &ioCollector, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter = { }, const ObjectLayerFilter &inObjectLayerFilter = { }, const BodyFilter &inBodyFilter = { }, const ShapeFilter &inShapeFilter = { }) const;
36
37
/// Check if inPoint is inside any shapes. For this tests all shapes are treated as if they were solid.
38
/// For a mesh shape, this test will only provide sensible information if the mesh is a closed manifold.
39
/// For each shape that collides, ioCollector will receive a hit
40
void CollidePoint(RVec3Arg inPoint, CollidePointCollector &ioCollector, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter = { }, const ObjectLayerFilter &inObjectLayerFilter = { }, const BodyFilter &inBodyFilter = { }, const ShapeFilter &inShapeFilter = { }) const;
41
42
/// Collide a shape with the system
43
/// @param inShape Shape to test
44
/// @param inShapeScale Scale in local space of shape
45
/// @param inCenterOfMassTransform Center of mass transform for the shape
46
/// @param inCollideShapeSettings Settings
47
/// @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 origin
48
/// @param ioCollector Collector that receives the hits
49
/// @param inBroadPhaseLayerFilter Filter that filters at broadphase level
50
/// @param inObjectLayerFilter Filter that filters at layer level
51
/// @param inBodyFilter Filter that filters at body level
52
/// @param inShapeFilter Filter that filters at shape level
53
void 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;
54
55
/// Same as CollideShape, but uses InternalEdgeRemovingCollector to remove internal edges from the collision results (a.k.a. ghost collisions)
56
void 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;
57
58
/// Cast a shape and report any hits to ioCollector
59
/// @param inShapeCast The shape cast and its position and direction
60
/// @param inShapeCastSettings Settings for the shape cast
61
/// @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 origin
62
/// @param ioCollector Collector that receives the hits
63
/// @param inBroadPhaseLayerFilter Filter that filters at broadphase level
64
/// @param inObjectLayerFilter Filter that filters at layer level
65
/// @param inBodyFilter Filter that filters at body level
66
/// @param inShapeFilter Filter that filters at shape level
67
void CastShape(const RShapeCast &inShapeCast, const ShapeCastSettings &inShapeCastSettings, RVec3Arg inBaseOffset, CastShapeCollector &ioCollector, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter = { }, const ObjectLayerFilter &inObjectLayerFilter = { }, const BodyFilter &inBodyFilter = { }, const ShapeFilter &inShapeFilter = { }) const;
68
69
/// Collect all leaf transformed shapes that fall inside world space box inBox
70
void CollectTransformedShapes(const AABox &inBox, TransformedShapeCollector &ioCollector, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter = { }, const ObjectLayerFilter &inObjectLayerFilter = { }, const BodyFilter &inBodyFilter = { }, const ShapeFilter &inShapeFilter = { }) const;
71
72
private:
73
BodyLockInterface * mBodyLockInterface = nullptr;
74
BroadPhaseQuery * mBroadPhaseQuery = nullptr;
75
};
76
77
JPH_NAMESPACE_END
78
79