I have some objects in the physics simulation and i want to know the local coordinates of these objects ?
How can i do that ?
How to convert from world coordinate
-
- Posts: 74
- Joined: Sun Jul 08, 2012 11:32 am
Re: How to convert from world coordinate
Converting from world to local just involves multiplying the world transform matrix of the object by the inverse to get the identity matrix.
Normally you want to transform a different object B into the local frame of object A, which just involves multiplying B's world transform matrix by A's inverse world transform matrix, meaning that A will now be at the origin and B's position will be relative to this origin
Normally you want to transform a different object B into the local frame of object A, which just involves multiplying B's world transform matrix by A's inverse world transform matrix, meaning that A will now be at the origin and B's position will be relative to this origin
-
- Posts: 6
- Joined: Wed Feb 20, 2013 6:14 am
Re: How to convert from world coordinate
Thanks ,
basically i want to create a joint between two legs for my robot.
and i am using the hinge constraint. and this class requires the local coordinates of the legs to be joined.
I do not know who to get the local coordinated now.
can just provide a piece of codes that do this ?
thank
you
basically i want to create a joint between two legs for my robot.
and i am using the hinge constraint. and this class requires the local coordinates of the legs to be joined.
I do not know who to get the local coordinated now.
can just provide a piece of codes that do this ?
thank
you
-
- Posts: 74
- Joined: Sun Jul 08, 2012 11:32 am
Re: How to convert from world coordinate
For my hinge joint, I have one anchor given in world coords and a world hinge axis.
From the world anchor, you build two local anchors as follows for each body
Basically these are vectors ra and rb (of the relative position) in local coords of each body. Perhaps you can paste some code or show your approach
From the world anchor, you build two local anchors as follows for each body
Code: Select all
wt1T.transposeOf(m_pRigidBody1->m_matWorldTransform);
wt2T.transposeOf(m_pRigidBody2->m_matWorldTransform);
m_vLocalAnchor1 = (vAnchor - m_pRigidBody1->m_vPosition)*wt1T;
m_vLocalAnchor2 = (vAnchor - m_pRigidBody2->m_vPosition)*wt2T;
-
- Posts: 2
- Joined: Wed Oct 02, 2013 10:10 am
Re: How to convert from world coordinate
I am sorry for reviving this thread but I am completely lost and already wasted countless hours on this simple function.
So I know I have to provide the HingeConstraint constructor with local coordinates for axis and anchor point. So I wanted to create two little helper functions to translate a vector from world to local and to translate a point from world to local (since both of them are needed for the axis and the anchor).
What I came up with so far is this:
Which should be equivalent to c0der's suggestion:
I basically wasted two complete days of my life on this so please release me from my pain

So I know I have to provide the HingeConstraint constructor with local coordinates for axis and anchor point. So I wanted to create two little helper functions to translate a vector from world to local and to translate a point from world to local (since both of them are needed for the axis and the anchor).
What I came up with so far is this:
Code: Select all
btVector3 pointWorldToLocal(int bodyIndex, btVector3 point)
{
btVector3 localPoint;
btTransform xform = arrayOfBtRigBodies[bodyIndex]->getCenterOfMassTransform();
// The local coordinates should be [(worldCoords - localOrigin) * inverse(localRotation)] or am I wrong?
localPoint = (point - xform.getOrigin()) * xform.getBasis().inverse();
return localPoint;
}
btVector3 axisWorldToLocal(int bodyIndex, btVector3 axis)
{
btTransform xform = arrayOfBtRigBodies[bodyIndex]->getCenterOfMassTransform();
// This works quite well but only if I do not inverse the result of getBasis()... ?
btVector3 localAxis = axis * xform.getBasis();
return localAxis;
}
But when I run it, the axis is translated from world to local correctly while pointWorldToLocal produces strange results.wt1T.transposeOf(arrayOfBtRigBodies[bodyIndex]->m_matWorldTransform);
m_vLocalAnchor1 = (point - arrayOfBtRigBodies[bodyIndex]->m_vPosition)*wt1T;
return m_vLocalAnchor1
I basically wasted two complete days of my life on this so please release me from my pain


-
- Posts: 2
- Joined: Wed Oct 02, 2013 10:10 am
Re: How to convert from world coordinate
Alright folks,
after I froze my project for a week I finally found the solution for my coordinate translation problem today. Might be trivial for most of you but for those who are stuck like I was, this is my final function:
yes guys it's that easy. Don't know why it took me so long to understand how getCenterOfMassTransform can be used to translate points. Maybe it's not in the manual or I completely overlooked it. Hope this helps someone else.
Best
after I froze my project for a week I finally found the solution for my coordinate translation problem today. Might be trivial for most of you but for those who are stuck like I was, this is my final function:
Code: Select all
btVector3 RagdollDemo::pointWorldToLocal(int bodyIndex, btVector3 worldPoint)
{
return body[bodyIndex]->getCenterOfMassTransform().inverse()(worldPoint);
}
Best
-
- Posts: 1
- Joined: Thu Dec 26, 2013 8:18 am
Re: How to convert from world coordinate
Shogun! Thank you! Saved me countless hours and actually clarified these concepts.