Comments (2)
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)
- mBaseAllocator.release pure virtual method called causing SIGABRT HOT 4
- A ton of compiler errors when trying to compile with Make. HOT 1
- RigidBody::raycast gives incorrect result in raycastInfo for body with multiple colliders + solution HOT 1
- Objects going though each other HOT 1
- Set Collider Transform assumes that mBody is a RigidBody HOT 2
- How to get axis angles? HOT 4
- CollisionDetectionSystem::createContacts() assert crash HOT 2
- Transform::getOpenGLMatrix not including rotation HOT 2
- void PhysicsWorld::createIslands() dirty contactPairIndex crash HOT 4
- Will it work for Android? HOT 2
- testbed build error with glDisableVertexAttribArray HOT 1
- Build failing - Missing include in configuration.h HOT 3
- Assertion failed in OverlappingPairs, version release 0.10.0 HOT 5
- Destroying an empty physics world leads to assertion failure (after upgrading to 0.10.0) HOT 2
- Child somewhat-static collision shape HOT 1
- Ticking different objects at different rates HOT 1
- v0.10.0: Assertion Failed in NarrowPhaseInfoBatch::addContactPoint() HOT 2
- Why is the collision not happening how I think it should? HOT 3
- 0.10.0 - createConvexMeshShape example provided in manual doesn't work HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from reactphysics3d.