reactphysics3d
reactphysics3d copied to clipboard
the anchor point position of HingeJoint bug
rp3d::Transform t; mBody->addCollisionShape(pShape, t, rp3d::decimal(mass)); //create hingeJoint .... //if( t.getPosition() != rp3d::Vector3::zero()) //{ // the hingeJoint's anchor point position is wrong! I have tested it. // May you fixed the bug? thank you! //}
In the code you posted, at the first line you create a transform with zero position, then you add a collision shape to the body using this transform but you never update the "t" transform. Therefore, this transform will always have zero position for the rest of your code.
Is there some code that you have not posted where you update the "t" transform at some point ? Moreover, you say that the hingeJoint's anchor position is wrong talking about t.getPosition() but why would t.getPosition() be the anchor position ? "t" is a transform representing the initial relative position of your collision shape w.r.t the body. It is not the anchor position.
Maybe you could also post the hinge joint creation code ?
//create static rigid body rp3d::Transform t(rp3d::Vector3(0,0,0), rp3d::Quaternion::identity); rp3d::RigidBody* mStaticBody = m_pWorld->createRigidBody(t); mStaticBody->setType(rp3d::BodyType::STATIC);
//create dynamic rigid body, initial position is Vector3(0,0,0), init Orientation is Quaternion(0,0,0,1) rp3d::RigidBody* mDynBody = m_pWorld->createRigidBody(t); mDynBody->setType(rp3d::BodyType::DYNAMIC); mDynBody->enableGravity(true); //add shapes for dynamic rigid body rp3d::Vector3 halfExtend(0.5,0.5, 0.5); rp3d::BoxShape* pShape = new rp3d::BoxShape(halfExtend); rp3d::Transform relative(rp3d::Vector3(1,0,0), rp3d::Quaternion::identity); rp3d::ProxyShape* proxyShape = mDynBody->addCollisionShape(pShape, relative, rp3d::decimal(50)); //create HingeJoint rp3d::HingeJointInfo jointInfo(mStaticBody, mDynBody, rp3d::Vector3(-1,0,0), rp3d::Vector3(0,0,1)); m_pWorld->createJoint(jointInfo);
The result of HingeJoint simulation is wrong. May you debug the code? thank u.
rp3d::Transform relative(rp3d::Vector3(0,0,0), rp3d::Quaternion::identity);
when relative Transform is identity, HingeJoint simulation is right.
I have used your physics engine doing a project. I write a lot of test demo to test your engine. believe me it is a bug, and in my project, we must use this feature( relative is not identity).
Thanks a lot for your reply. I am not saying it's not a bug, I am just saying that I do not have enough information to reproduce it on my side. This issue title is about a wrong anchor position. In your first message of this issue, you say that you see the issue with the following piece of code:
//if( t.getPosition() != rp3d::Vector3::zero())
//{
// the hingeJoint's anchor point position is wrong! I have tested it.
// May you fixed the bug? thank you!
//}
But in the last code you just posted, this piece of code does not appear. Therefore, what I do not understand is where exactly in your, last posted code, the anchor position is wrong and how to you get the anchor position ?
In your code, you initialize the "t" transform to have zero position and identity quaternion, then you never changed this variable (at least not in the code you posted). Therefore the following condition is never true:
if(t.getPosition() != rp3d::Vector3::zero())
That's what I do not understand. Can you post the code where you update the "t" transform ?
if(t.getPosition() != rp3d::Vector3::zero()). this is not code, just a word I express.( if transform is not identity the bug appear.). so just look at this code.
//create static rigid body rp3d::Transform t(rp3d::Vector3(0,0,0), rp3d::Quaternion::identity); rp3d::RigidBody* mStaticBody = m_pWorld->createRigidBody(t); mStaticBody->setType(rp3d::BodyType::STATIC);
//create dynamic rigid body, initial position is Vector3(0,0,0), init Orientation is Quaternion(0,0,0,1) rp3d::RigidBody* mDynBody = m_pWorld->createRigidBody(t); mDynBody->setType(rp3d::BodyType::DYNAMIC); mDynBody->enableGravity(true); //add shapes for dynamic rigid body rp3d::Vector3 halfExtend(0.5,0.5, 0.5); rp3d::BoxShape* pShape = new rp3d::BoxShape(halfExtend); rp3d::Transform relative(rp3d::Vector3(1,0,0), rp3d::Quaternion::identity); rp3d::ProxyShape* proxyShape = mDynBody->addCollisionShape(pShape, relative, rp3d::decimal(50)); //create HingeJoint rp3d::HingeJointInfo jointInfo(mStaticBody, mDynBody, rp3d::Vector3(-1,0,0), rp3d::Vector3(0,0,1)); m_pWorld->createJoint(jointInfo);
the simulation result in graph, the hinged joint not rot around anchor position, it rot around between anchor position and Dynamic rigidbody.
I am sorry for my English. Just test the code above, I think you may extends your demo cube class to receive the shape transform. and also modify the synchronization code to graph. then it will easy to reappear the bug.