include/extensions/PxSceneQueryExt.h

File members: include/extensions/PxSceneQueryExt.h

// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//  * Redistributions of source code must retain the above copyright
//    notice, this list of conditions and the following disclaimer.
//  * Redistributions in binary form must reproduce the above copyright
//    notice, this list of conditions and the following disclaimer in the
//    documentation and/or other materials provided with the distribution.
//  * Neither the name of NVIDIA CORPORATION nor the names of its
//    contributors may be used to endorse or promote products derived
//    from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2023 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.

#ifndef PX_SCENE_QUERY_EXT_H
#define PX_SCENE_QUERY_EXT_H
#include "PxPhysXConfig.h"

#include "PxScene.h"

#if !PX_DOXYGEN
namespace physx
{
#endif

// These types have been deprecated (removed) in PhysX 3.4. We typedef them to the new types here for easy migration from 3.3 to 3.4.
typedef PxQueryHit              PxSceneQueryHit;
typedef PxQueryFilterData       PxSceneQueryFilterData;
typedef PxQueryFilterCallback   PxSceneQueryFilterCallback;
typedef PxQueryCache            PxSceneQueryCache;
typedef PxHitFlag               PxSceneQueryFlag;
typedef PxHitFlags              PxSceneQueryFlags;

class PxSceneQueryExt
{
public:

    static bool raycastAny( const PxScene& scene,
                            const PxVec3& origin, const PxVec3& unitDir, const PxReal distance,
                            PxSceneQueryHit& hit, const PxSceneQueryFilterData& filterData = PxSceneQueryFilterData(),
                            PxSceneQueryFilterCallback* filterCall = NULL, const PxSceneQueryCache* cache = NULL);

    static bool raycastSingle(  const PxScene& scene,
                                const PxVec3& origin, const PxVec3& unitDir, const PxReal distance,
                                PxSceneQueryFlags outputFlags, PxRaycastHit& hit,
                                const PxSceneQueryFilterData& filterData = PxSceneQueryFilterData(),
                                PxSceneQueryFilterCallback* filterCall = NULL, const PxSceneQueryCache* cache = NULL);

    static PxI32 raycastMultiple(   const PxScene& scene,
                                    const PxVec3& origin, const PxVec3& unitDir, const PxReal distance,
                                    PxSceneQueryFlags outputFlags,
                                    PxRaycastHit* hitBuffer, PxU32 hitBufferSize, bool& blockingHit,
                                    const PxSceneQueryFilterData& filterData = PxSceneQueryFilterData(),
                                    PxSceneQueryFilterCallback* filterCall = NULL, const PxSceneQueryCache* cache = NULL);

    static bool sweepAny(   const PxScene& scene,
                            const PxGeometry& geometry, const PxTransform& pose, const PxVec3& unitDir, const PxReal distance,
                            PxSceneQueryFlags queryFlags,
                            PxSceneQueryHit& hit,
                            const PxSceneQueryFilterData& filterData = PxSceneQueryFilterData(),
                            PxSceneQueryFilterCallback* filterCall = NULL,
                            const PxSceneQueryCache* cache = NULL,
                            PxReal inflation = 0.0f);

    static bool sweepSingle(const PxScene& scene,
                            const PxGeometry& geometry, const PxTransform& pose, const PxVec3& unitDir, const PxReal distance,
                            PxSceneQueryFlags outputFlags,
                            PxSweepHit& hit,
                            const PxSceneQueryFilterData& filterData = PxSceneQueryFilterData(),
                            PxSceneQueryFilterCallback* filterCall = NULL,
                            const PxSceneQueryCache* cache = NULL,
                            PxReal inflation=0.0f);

    static PxI32 sweepMultiple( const PxScene& scene,
                                const PxGeometry& geometry, const PxTransform& pose, const PxVec3& unitDir, const PxReal distance,
                                PxSceneQueryFlags outputFlags, PxSweepHit* hitBuffer, PxU32 hitBufferSize, bool& blockingHit,
                                const PxSceneQueryFilterData& filterData = PxSceneQueryFilterData(),
                                PxSceneQueryFilterCallback* filterCall = NULL, const PxSceneQueryCache* cache = NULL,
                                PxReal inflation = 0.0f);

    static PxI32 overlapMultiple(   const PxScene& scene,
                                    const PxGeometry& geometry, const PxTransform& pose,
                                    PxOverlapHit* hitBuffer, PxU32 hitBufferSize,
                                    const PxSceneQueryFilterData& filterData = PxSceneQueryFilterData(),
                                    PxSceneQueryFilterCallback* filterCall = NULL);

    static bool overlapAny( const PxScene& scene,
                            const PxGeometry& geometry, const PxTransform& pose,
                            PxOverlapHit& hit,
                            const PxSceneQueryFilterData& filterData = PxSceneQueryFilterData(),
                            PxSceneQueryFilterCallback* filterCall = NULL);
};

struct PxBatchQueryStatus
{
    enum Enum
    {
        ePENDING = 0,

        eSUCCESS,

        eOVERFLOW
    };

    static PX_FORCE_INLINE Enum getStatus(const PxRaycastBuffer& r)
    {
        return (0xffffffff == r.nbTouches) ? ePENDING : (0xffffffff == r.maxNbTouches ? eOVERFLOW : eSUCCESS);
    }
    static PX_FORCE_INLINE Enum getStatus(const PxSweepBuffer& r)
    {
        return (0xffffffff == r.nbTouches) ? ePENDING : (0xffffffff == r.maxNbTouches ? eOVERFLOW : eSUCCESS);
    }
    static PX_FORCE_INLINE Enum getStatus(const PxOverlapBuffer& r)
    {
        return (0xffffffff == r.nbTouches) ? ePENDING : (0xffffffff == r.maxNbTouches ? eOVERFLOW : eSUCCESS);
    }
};

class PxBatchQueryExt
{
public:

    virtual void release() = 0;

    virtual PxRaycastBuffer* raycast(
        const PxVec3& origin, const PxVec3& unitDir, const PxReal distance,
        const PxU16 maxNbTouches = 0,
        PxHitFlags hitFlags = PxHitFlags(PxHitFlag::eDEFAULT),
        const PxQueryFilterData& filterData = PxQueryFilterData(),
        const PxQueryCache* cache = NULL) = 0;

    virtual PxSweepBuffer* sweep(
        const PxGeometry& geometry, const PxTransform& pose, const PxVec3& unitDir, const PxReal distance,
        const PxU16 maxNbTouches = 0,
        PxHitFlags hitFlags = PxHitFlags(PxHitFlag::eDEFAULT),
        const PxQueryFilterData& filterData = PxQueryFilterData(),
        const PxQueryCache* cache = NULL,
        const PxReal inflation = 0.0f) = 0;

    virtual PxOverlapBuffer* overlap(
        const PxGeometry& geometry, const PxTransform& pose,
        PxU16 maxNbTouches = 0,
        const PxQueryFilterData& filterData = PxQueryFilterData(),
        const PxQueryCache* cache = NULL) = 0;

    virtual void execute() = 0;

protected:

    virtual ~PxBatchQueryExt() {}
};

PxBatchQueryExt* PxCreateBatchQueryExt(
    const PxScene& scene, PxQueryFilterCallback* queryFilterCallback,
    const PxU32 maxNbRaycasts, const PxU32 maxNbRaycastTouches,
    const PxU32 maxNbSweeps, const PxU32 maxNbSweepTouches,
    const PxU32 maxNbOverlaps, const PxU32 maxNbOverlapTouches);

PxBatchQueryExt* PxCreateBatchQueryExt(
    const PxScene& scene, PxQueryFilterCallback* queryFilterCallback,
    PxRaycastBuffer* raycastBuffers, const PxU32 maxNbRaycasts, PxRaycastHit* raycastTouches, const PxU32 maxNbRaycastTouches,
    PxSweepBuffer* sweepBuffers, const PxU32 maxNbSweeps, PxSweepHit* sweepTouches, const PxU32 maxNbSweepTouches,
    PxOverlapBuffer* overlapBuffers, const PxU32 maxNbOverlaps, PxOverlapHit* overlapTouches, const PxU32 maxNbOverlapTouches);

#if !PX_DOXYGEN
} // namespace physx
#endif

#endif