Giter Site home page Giter Site logo

Comments (1)

JoeRosselli avatar JoeRosselli commented on May 27, 2024

Hi, I'm looking into this again and I'm still seeing lots of significant issues with height maps in 0.10.0.

For reference, I'm using a right handed coordinate system with positive Y upwards, positive X rightwards, positive Z out of the screen.

I've widdled it down to a minimum repro that seems to highlight some issues. I'm creating an extremely simple height map shape that's flat with 4 data points, and then raycasting downwards through it, from high up, from two positions:

struct HitReceiver : public reactphysics3d::RaycastCallback
{
    reactphysics3d::decimal notifyRaycastHit(const reactphysics3d::RaycastInfo& raycastInfo) override
    {
        std::cout << "Raycast Hit: " << raycastInfo.worldPoint.x << "," << raycastInfo.worldPoint.y << "," << raycastInfo.worldPoint.z << std::endl;
        return 1.0f;
    }
};

void Physics::CreateTestBody()
{
    auto* pBody = m_pPhysicsWorld->createRigidBody(reactphysics3d::Transform());
    pBody->setType(reactphysics3d::BodyType::STATIC);
    pBody->setIsDebugEnabled(true);

    std::vector<double> data {
        5.0, 5.0, 5.0, 5.0
    };

    std::vector<reactphysics3d::Message> heightFieldMessages;

    auto* pHeightField = m_physicsCommon.createHeightField(
        2,
        2,
        data.data(),
        reactphysics3d::HeightField::HeightDataType::HEIGHT_DOUBLE_TYPE,
        heightFieldMessages
    );

    auto* pCollisionShape = m_physicsCommon.createHeightFieldShape(
        pHeightField,
        reactphysics3d::Vector3(1.0f, 1.0f, 1.0f)
    );

    pBody->addCollider(pCollisionShape, reactphysics3d::Transform());

    const auto ray1 = reactphysics3d::Ray(reactphysics3d::Vector3(0.0f, 100.0f, 0.0f),
                                          reactphysics3d::Vector3(0.0f, -100.0f, 0.0f));

    const auto ray2 = reactphysics3d::Ray(reactphysics3d::Vector3(2.0f, 100.0f, 2.0f),
                                          reactphysics3d::Vector3(2.0f, -100.0f, 2.0f));

    HitReceiver raycastReceiver{};
    m_pPhysicsWorld->raycast(ray1, &raycastReceiver);
    m_pPhysicsWorld->raycast(ray2, &raycastReceiver);
}

The output from the above code is:

Raycast Hit: 0,0,0

The first ray hits and the second doesn't. As the height map shape in this example is a 2x2 grid with no scaling, I think this is correct; it's 1 unit wide, so the first raycast that's centered at {0,y,0} would hit it, and the other that's centered at {2,y,2} would miss it.

Now, where the issue I was originally reporting seems to come from can be seen by changing the scaling field in createHeightFieldShape from {1.0f, 1.0f, 1.0f} to, say, {10.0f, 1.0f, 10.0f}. In this case, the height map should be the same height, just 10 times longer in the X and Z directions.

In that case, the output from the above code is:

Raycast Hit: 0,0,0
Raycast Hit: 0.2,0,0.2

This seems obviously broken. The second ray is shooting straight downwards from {2, 100, 2), yet the collision with the shape is reported as {0.2, 0, 0.2} when I'd expect {2, 0, 2}. You see similar errors, worse than this, depending on the height map data and where you're raycasting.

If I turn on debug render output, the height map shape looks correct in being 10 times longer in the x and z axes. I can drop bodies on it and collisions work fine. However, as shown above, if I raycast down into it, it starts giving weird, incorrect, values.


As another test, if I keep all the code the same but replace the collision shape from a height map shape to a box shape:

auto* pCollisionShape = m_physicsCommon.createBoxShape(reactphysics3d::Vector3(1,5,1));

Then I get:

Raycast Hit: 0,5,0

Which seems fine, and if I extend the x/z dimensions by 10 units:

auto* pCollisionShape = m_physicsCommon.createBoxShape(reactphysics3d::Vector3(10,5,10));

I get:

Raycast Hit: 0,5,0
Raycast Hit: 2,5,2

Which also seems fine.

The problem seems to specifically revolve around specifying non-identity values for the scaling factor when creating a height field shape.

--

I'm also potentially seeing some weird behavior with how rp3d positions height map collision shapes. Naively, I'd assume that if the height data values were 5,5,5,5, and the shape was placed at the origin with no other transforms, then hits with it would be reported as being at a Y position of 5, not 0. I know that in 0.9.0 it vertically centered the shape around its position with regards to its vertical height, so maybe that's where it's coming from but I'm suspicious that something is broken here too. But I need the above issue solved before I can investigate down this line more. Now that axis is no longer a parameter when creating height field shapes, does it just always internally assume Y axis?

from reactphysics3d.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.