bazaarvoice / jolt

JSON to JSON transformation library written in Java.
Apache License 2.0
1.54k stars 328 forks source link

Problem with CollideSphere - picks random entity from time to time #1158

Open seltee opened 1 year ago

seltee commented 1 year ago

Will start from the code

AllHitCollisionCollector<CollideShapeBodyCollector> ioCollector;
        mBroadPhase->CollideSphere(
            Vec3(p.x * SIZE_MULTIPLIER, p.y * SIZE_MULTIPLIER, p.z * SIZE_MULTIPLIER),
            radius * SIZE_MULTIPLIER, ioCollector);

        if (ioCollector.mHits.size())
        {
            printf(
                "DLL HIT\n%f %f %f(%f %f %f), r %f(%f):\n",
                p.x * SIZE_MULTIPLIER,
                p.y * SIZE_MULTIPLIER,
                p.z * SIZE_MULTIPLIER,
                p.x,
                p.y,
                p.z,
                radius * SIZE_MULTIPLIER,
                radius);

            for (auto item = ioCollector.mHits.begin(); item != ioCollector.mHits.end(); ++item)
            {
                BodyLockRead lock(pSystem->GetBodyLockInterface(), *item);
                if (lock.Succeeded())
                {
                    const Body &body = lock.GetBody();
                    auto vec3pos = body.GetPosition();
                    printf(
                        "B %f %f %f(%f %f %f)\n",
                        vec3pos.GetX(),
                        vec3pos.GetY(),
                        vec3pos.GetZ(),
                        vec3pos.GetX() / SIZE_MULTIPLIER,
                        vec3pos.GetY() / SIZE_MULTIPLIER,
                        vec3pos.GetZ() / SIZE_MULTIPLIER);

                    float radius_sq = Square(radius * SIZE_MULTIPLIER);
                    const AABox &bounds = body.GetWorldSpaceBounds();
                    printf("R %f <= %f\n",
                           bounds.GetSqDistanceTo(Vec3(p.x * SIZE_MULTIPLIER, p.y * SIZE_MULTIPLIER, p.z * SIZE_MULTIPLIER)),
                           radius_sq);

                    list.push_back((Actor *)body.GetUserData());
                    lock.ReleaseLock();
                }
            }
            printf("END\n");
        }

This part:

float radius_sq = Square(radius * SIZE_MULTIPLIER);
                    const AABox &bounds = body.GetWorldSpaceBounds();
                    printf("R %f <= %f\n",
                           bounds.GetSqDistanceTo(Vec3(p.x * SIZE_MULTIPLIER, p.y * SIZE_MULTIPLIER, p.z * SIZE_MULTIPLIER)),
                           radius_sq);

Is the most interesting because sometimes Jolt takes bodies with following data: DLL HIT 1.898927 0.850766 0.000000(94.946350 42.538319 0.000000), r 0.240000(12.000000): B 1.870254 11.413527 0.000011(93.512695 570.676392 0.000529) R 99.256607 <= 0.057600 END For some reason body is taken with distance is 99, when double radius is 0.057600 In D:\arts\gamedev\JoltPhysics\Jolt\Physics\Collision\BroadPhase\BroadPhaseBruteForce.cpp it has the following check if (bounds.GetSqDistanceTo(inCenter) <= radius_sq) how is possible it passes?

Problem happens not all the time. Most of the time after some time after physicsSystem->GetBodyInterface().RemoveBody(body->GetID()); happened