Request: extra simple accessor methods

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Request: extra simple accessor methods

Postby aitzolmuelas » Thu Apr 30, 2015 10:46 am

Hi, I have had to customly add a couple of methods to the Newton.h interface which can come in handy (and are extremely simple). I was hoping they could be added to the official releases. Mainly:

Code: Select all
dFloat NewtonContactJointGetClosestDistance(const NewtonJoint* const contactJoint)
{
   TRACE_FUNCTION(__FUNCTION__);
   dgContact* const joint = (dgContact *)contactJoint;

   return joint->GetClosestDistance( );
}

void NewtonBodyGetPosition(const NewtonBody* const bodyPtr, dFloat* const posPtr)
{
   TRACE_FUNCTION(__FUNCTION__);
   dgBody* const body = (dgBody *)bodyPtr;
   const dgVector & rot = body->GetPosition();
   posPtr[0] = rot.m_x;
   posPtr[1] = rot.m_y;
   posPtr[2] = rot.m_z;
}


The second is handy to avoid having a matrix if you only need a vector3.
Also, I found the following could be optimized (not much though):
Code: Select all
void NewtonBodyGetRotation(const NewtonBody* const bodyPtr, dFloat* const rotPtr)
{
   TRACE_FUNCTION(__FUNCTION__);
   dgBody* const body = (dgBody *)bodyPtr;
   const dgQuaternion rot = body->GetRotation(); // This was before
   const dgQuaternion & rot = body->GetRotation(); // Reference avoid uneeded copy
   rotPtr[0] = rot.m_q0;
   rotPtr[1] = rot.m_q1;
   rotPtr[2] = rot.m_q2;
   rotPtr[3] = rot.m_q3;
}
aitzolmuelas
 
Posts: 78
Joined: Wed Mar 25, 2015 1:10 pm

Re: Request: extra simple accessor methods

Postby Julio Jerez » Thu Apr 30, 2015 11:00 am

All good,
I am out until the ten, could you remind me by the again, and I add them.
Maybe you could Github patch
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Request: extra simple accessor methods

Postby Julio Jerez » Sun May 10, 2015 8:50 am

Done.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest