How to get the world position of a constraint

Post Reply
BobSmith77
Posts: 2
Joined: Mon Aug 28, 2017 10:36 pm

How to get the world position of a constraint

Post by BobSmith77 »

Can anyone tell me how to get the world position of a constraint(a btConeTwistConstraint specifically).

I've looked around and can't seem to find a way to do this.

I know the Debug renderer has access to them so I searched through that and had no luck.
So I looked some more and saw that the debug renderer is passed as an argument to the Constraint Solver so I looked there also, to no avail.

I also looked through btConeTwistConstraint and btTypedConstraint but the closest thing I found was under the solve method of btConeTwistConstraint and I can't get the right coordinates from that.

I have a bad feeling that I'm just looking at this wrong, So, If someone could tell me what I'm doing wrong and possibly provide some code I would appreciate it.

If you need more information please ask me. I will be glad to provide it to you so this problem can be solved.
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: How to get the world position of a constraint

Post by drleviathan »

What do you mean by the "world position" of a btConeTwistConstraint? You mean the world position of the "pivot" between the two constrained objects?

If you examine the implementation of btConeTwistConstraint::buildJacobian() you'll see this code:

Code: Select all

            btVector3 pivotAInW = m_rbA.getCenterOfMassTransform()*m_rbAFrame.getOrigin();
            btVector3 pivotBInW = m_rbB.getCenterOfMassTransform()*m_rbBFrame.getOrigin();
            btVector3 relPos = pivotBInW - pivotAInW;

            btVector3 normal[3];
            if (relPos.length2() > SIMD_EPSILON)
            {
                normal[0] = relPos.normalized();
            }
            else
            {
                normal[0].setValue(btScalar(1.0),0,0);
            }
It appears to be computing two pivot positions in the world frame, one relative to objectA and another relative to objectB. When the distance between the two pivot positions is small it can't normalize the relative position so it assumes it is along the x-axis (but the relative position has nearly zero length anyway so it doesn't matter). Of course, the constraint solver would try to move the two objects such that both pivot positions are as close as possible.

I think the math you are looking for is there where the pivot's position is computed both ways. You probably want to calculate both and then compute their average which would be the midpoint between them.
BobSmith77
Posts: 2
Joined: Mon Aug 28, 2017 10:36 pm

Re: How to get the world position of a constraint

Post by BobSmith77 »

drleviathan wrote: If you examine the implementation of btConeTwistConstraint::buildJacobian() you'll see this code:

Code: Select all

            btVector3 pivotAInW = m_rbA.getCenterOfMassTransform()*m_rbAFrame.getOrigin();
            btVector3 pivotBInW = m_rbB.getCenterOfMassTransform()*m_rbBFrame.getOrigin();
            btVector3 relPos = pivotBInW - pivotAInW;

            btVector3 normal[3];
            if (relPos.length2() > SIMD_EPSILON)
            {
                normal[0] = relPos.normalized();
            }
            else
            {
                normal[0].setValue(btScalar(1.0),0,0);
            }
It appears to be computing two pivot positions in the world frame, one relative to objectA and another relative to objectB. When the distance between the two pivot positions is small it can't normalize the relative position so it assumes it is along the x-axis (but the relative position has nearly zero length anyway so it doesn't matter). Of course, the constraint solver would try to move the two objects such that both pivot positions are as close as possible.

I think the math you are looking for is there where the pivot's position is computed both ways. You probably want to calculate both and then compute their average which would be the midpoint between them.
Thank you for helping me out. This problem has been bugging me for a while now.
Post Reply