CustomLimitBallAndSocket Joint

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

CustomLimitBallAndSocket Joint

Postby Zach Griffin » Sat Feb 14, 2009 3:16 am

I've been using the custom joints for the past month and think I have a fair understanding of them and how they work. I've converted the CustomLimitBallAndSocket Joint to use with OgreNewt which mostly worked except for some rotations that shouldn't happen so I'm guessing there must be something wrong with the conversion. I'm guessing it is to do with the .unrotateVector vector which I don't fully understand. More on that down below.

My main question is with the axes that are constrained. In the ball and socket joint code and the hinge joint, the sdk code doesn't seem to take the orientation of the parent and child bodies into account or the direction of the joint. i.e It always assumes that the hinge axis is along the X axis or in the case of the ball joint that the rotation around X axis is the DOF that is lost. As soon as any rotation of the body happens the X axis would become the Y axis etc. I haven't seen any code that takes the orientation of the body into account. Maybe this is an error in the OgreNewt wrapper or differences in the matrix conversion?

When I converted the hinge code I took the orientation into account and the axis.

Julio's Hinge Code:
Code: Select all
// calculate the position of the pivot point and the Jacobian direction vectors, in global space.
   CalculateGlobalMatrix (m_localMatrix0, m_localMatrix1, matrix0, matrix1);

   // Restrict the movement on the pivot point along all tree orthonormal direction
   NewtonUserJointAddLinearRow (m_joint, &matrix0.m_posit[0], &matrix1.m_posit[0], &matrix0.m_front[0]);
   NewtonUserJointAddLinearRow (m_joint, &matrix0.m_posit[0], &matrix1.m_posit[0], &matrix0.m_up[0]);
   NewtonUserJointAddLinearRow (m_joint, &matrix0.m_posit[0], &matrix1.m_posit[0], &matrix0.m_right[0]);
   // get a point along the pin axis at some reasonable large distance from the pivot
   dVector q0 (matrix0.m_posit + matrix0.m_front.Scale(MIN_JOINT_PIN_LENGTH));
   dVector q1 (matrix1.m_posit + matrix1.m_front.Scale(MIN_JOINT_PIN_LENGTH));

   // two constraints row perpendicular to the pin vector
    NewtonUserJointAddLinearRow (m_joint, &q0[0], &q1[0], &matrix0.m_up[0]);
   NewtonUserJointAddLinearRow (m_joint, &q0[0], &q1[0], &matrix0.m_right[0]);

My Hinge Code:
Code: Select all
localToGlobal( localOrientParent, localPositionParent, globalOrientParent, globalPositionParent, 0 );
   localToGlobal( localOrientChild, localPositionChild, globalOrientChild, globalPositionChild, 1 );

        //Get the direction of the hinge axis
   Vector3 hingeAxisParent (parentNode->localOffsetFromCentre - childNode->localOffsetFromCentre);
   Vector3 hingeAxisChild (hingeAxisParent);
        //Take the orientation of the node into account
   hingeAxisParent = globalOrientParent * hingeAxisParent;
   hingeAxisChild = globalOrientChild * hingeAxisChild;

        //Normalise the vectors (Perpendicular and cross product functions require normalised vectors)

        //Restrict movement of the pivot points
   addLinearRow(globalPositionParent, globalPositionChild, hingeAxisParent);
   addLinearRow(globalPositionParent, globalPositionChild, hingeAxisParent.perpendicular());
   addLinearRow(globalPositionParent, globalPositionChild, hingeAxisParent.crossProduct(hingeAxisParent.perpendicular()));

        //Find another point further along the hinge axis to restrict rotations in other directions
   Vector3 parentHingeLock (globalPositionParent + (hingeAxisParent * MIN_JOINT_PIN_LENGTH));
   Vector3 childHingeLock (globalPositionChild + (hingeAxisChild * MIN_JOINT_PIN_LENGTH));

        //Apply the constraints
   addLinearRow(parentHingeLock, childHingeLock, hingeAxisParent.perpendicular());
   addLinearRow(parentHingeLock, childHingeLock, hingeAxisParent.crossProduct(hingeAxisParent.perpendicular()));

Am I right in assuming that the newton matrix functions take the orientation of the nodes into account?
Zach Griffin
Posts: 13
Joined: Tue Oct 04, 2005 7:52 am

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 3 guests