Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect sweep hit distance #610

Open
fkorsa opened this issue Oct 24, 2022 · 0 comments
Open

Incorrect sweep hit distance #610

fkorsa opened this issue Oct 24, 2022 · 0 comments

Comments

@fkorsa
Copy link

fkorsa commented Oct 24, 2022

I'm using PhysX 4.1.2.29882248.

When calling PxScene::sweep, the returned distance in PxSweepBuffer::distance seems to be systematically off by a small amount. That amount is deterministic, it seems to be related to the size of the objects at play.

I'm passing PxHitFlag::eDEFAULT and a null inflation (the default value for the parameter). I have also tried setting contactOffset on all shapes to be 1e-10, but it did not change the result.

Here is an example. Take a scene with two cubes, whose centers are located at (0, 10, 0) and (0, 15, 0). The two cubes have the same dimensions: between (-1, -1, -1) and (1, 1, 1), that is to say cubes centered on the origin and with a side length of 2.

I'm sweeping the cube at (0, 15, 0) downwards, with the direction (0, -1, 0). I would thus expect a hit distance of exactly 3.

However, the distance returned by PhysX is 2.9975. Consistently. It's not dramatically off, but since it's very consistent across scenes and parameters, I wonder if there is something to be done about it to be more precise.

The code looks like that:

const PxQueryFilterData filter( PxQueryFlag::eSTATIC );
bool has_hit = scene->sweep( convex_mesh, shape_pose, direction, max_distance, hit, PxHitFlag::eDEFAULT, filter );
if ( has_hit ) {
    max_distance = hit.getAnyHit( 0 ).distance;
}

The input to the sweep method is a dynamic convex mesh, while the rest of the scene is composed of static triangle meshes.

When running the code above with the two cubes, the only contact is in (0, 11, 0.5). Could it possibly explain the distance?

The doc does say that it should be between the centers that the distance is computed:
image

And the numbers don't match anyway. I'm just asking in case there's a lead to follow there.

I have seen in PhysX's source code a parameter that could potentially explain that offset, though the numbers do not exactly match: SQ_PRUNER_INFLATION. It seems no matter the inflation parameter, there is a fixed amount of inflation being applied to the extents of the object. Could that be the source of the offset?

Note: PxHitFlag::ePRECISE_SWEEP did not help. It does not change the resulting distance.

Do you know if there is something to be done about that offset, in order to get more precise sweep results?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant