JointLibrary hinge angle

Report any bugs here and we'll post fixes

Moderators: Sascha Willems, Thomas

JointLibrary hinge angle

Postby kallaspriit » Sun Jan 31, 2010 1:51 pm

The custom hinge of jointlibrary returns m_curJointAngle.m_angle in CustomHinge::GetJointAngle () but that variable is only set if limits are on and exceeded.

To fix this, the line:
Code: Select all
m_curJointAngle.m_angle = angle;

should be added, for example after line 116 of CustomHinge.cpp:
Code: Select all
angle = m_curJointAngle.CalculateJointAngle (cosAngle, sinAngle);


Fixed submitContraint:
Code: Select all
void CustomHinge::SubmitConstraints (dFloat timestep, int threadIndex)
{
//   dFloat angle;
//   dFloat sinAngle;
//   dFloat cosAngle;
   dMatrix matrix0;
   dMatrix matrix1;

   // 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]);

   dFloat angle;
   dFloat sinAngle;
   dFloat cosAngle;

   // the joint angle can be determine by getting the angle between any two non parallel vectors
//      sinAngle = (matrix0.m_up * matrix1.m_up) % matrix0.m_front;
//      cosAngle = matrix0.m_up % matrix1.m_up;
//      angle = dAtan2 (sinAngle, cosAngle);

   // the joint angle can be determine by getting the angle between any two non parallel vectors
   sinAngle = (matrix0.m_up * matrix1.m_up) % matrix0.m_front;
   cosAngle = matrix0.m_up % matrix1.m_up;
   angle = m_curJointAngle.CalculateJointAngle (cosAngle, sinAngle);
   m_curJointAngle.m_angle = angle;

   // if limit are enable ...
   if (m_limitsOn) {
//      if (angle < m_minAngle) {
      if (angle < m_minAngle) {
         dFloat relAngle;

//         relAngle = angle - m_minAngle;
         relAngle = angle - m_minAngle;
         // the angle was clipped save the new clip limit
         m_curJointAngle.m_angle = m_minAngle;

         // tell joint error will minimize the exceeded angle error
         NewtonUserJointAddAngularRow (m_joint, relAngle, &matrix0.m_front[0]);

         // need high stiffness here
         NewtonUserJointSetRowStiffness (m_joint, 1.0f);

         // allow the joint to move back freely
         NewtonUserJointSetRowMaximumFriction (m_joint, 0.0f);


      } else if (angle  > m_maxAngle) {
         dFloat relAngle;

//         relAngle = angle - m_maxAngle;

         relAngle = angle - m_maxAngle;

         // the angle was clipped save the new clip limit
         m_curJointAngle.m_angle = m_maxAngle;
         
         // tell joint error will minimize the exceeded angle error
         NewtonUserJointAddAngularRow (m_joint, relAngle, &matrix0.m_front[0]);

         // need high stiffness here
         NewtonUserJointSetRowStiffness (m_joint, 1.0f);

         // allow the joint to move back freely
         NewtonUserJointSetRowMinimumFriction (m_joint, 0.0f);

      }
   }

   // save the current joint Omega
   dVector omega0(0.0f, 0.0f, 0.0f, 0.0f);
   dVector omega1(0.0f, 0.0f, 0.0f, 0.0f);
   NewtonBodyGetOmega(m_body0, &omega0[0]);
   if (m_body1) {
      NewtonBodyGetOmega(m_body1, &omega1[0]);
   }
   m_jointOmega = (omega0 - omega1) % matrix0.m_front;
 }
kallaspriit
 
Posts: 216
Joined: Sun Aug 14, 2005 6:31 pm

Re: JointLibrary hinge angle

Postby Julio Jerez » Sun Jan 31, 2010 4:28 pm

yes you are correct, there is only one reduncance

Code: Select all
   // the joint angle can be determine by getting the angle between any two non parallel vectors
   sinAngle = (matrix0.m_up * matrix1.m_up) % matrix0.m_front;
   cosAngle = matrix0.m_up % matrix1.m_up;
   angle = m_curJointAngle.CalculateJointAngle (cosAngle, sinAngle);

// thisi line is no needed
   m_curJointAngle.m_angle = angle;


I will make the corrections make the change. I will try to pu and update tonoght witho this change and teh blnk joint yo sugested, plus a while bunck of oteh changes tha are no ready yet bu that are so much the
I need to mak eteh update before I continue.
Thanks for the Bug
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: JointLibrary hinge angle

Postby kallaspriit » Sun Jan 31, 2010 5:11 pm

Good, then I can update OgreNewt with some changes that rely on that new class :)
kallaspriit
 
Posts: 216
Joined: Sun Aug 14, 2005 6:31 pm

Re: JointLibrary hinge angle

Postby Julio Jerez » Mon Feb 01, 2010 3:17 pm

Umm I still need a day or two, I have the PC working but before I make a release I am trying to make the Linux build so that I do not have surprices with Non working SDKs.

It took me all day yesteday top get wxWidget running on Linux 64, an dfor some reason teh same project with teh only diffremnce is the -m32 or -m64 flag does no compile on my 32 bit paptop.
Anyway I mhave teh Gui going pn Linux now I am trin to buidl Collada.

It turns out that the version of Collada that I was using (and I spend lot of time fixing teh Crashes and memory Leaks)
does not compile at all on Linux box, so I had not choice but to give it up and get latest 2.2 archive.
On the bright side they too fixedd all the gross memory leaks and the uri crashes.
Bu teh best fo all si that now it also has an option to use TinyXML as the xml parcer, instead of thoso dreaded XML2 f%$k libraries.

Anyway as soon as I manage to get the Build with the WxWidget GUI (wich is done already) and Collada running in Linux 64 I Will put the Update.
It is still incomplete but it is enought to put a new update. I did not know this was going to be so time consuming but it is for teh better.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles


Return to Bugs and Fixes

Who is online

Users browsing this forum: No registered users and 4 guests

cron