NewtonCreateUserMeshCollision Callbacks 2.0

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

NewtonCreateUserMeshCollision Callbacks 2.0

Postby Marc » Sat Jul 11, 2009 9:35 am

Hi !

In 2.0, NewtonCreateUserMeshCollision got 2 new callbacks: NewtonUserMeshCollisionGetCollisionInfo getInfoCallback and NewtonUserMeshCollisionGetFacesInAABB facesInAABBCallback. Do I have to implment those? And if yes, how? (for example, I'm not exactly sure how to fill out the info struct for NewtonUserMeshCollisionGetCollisionInfo)

In 1.53, I was able to put a 0 for NewtonUserMeshCollisionDestroyCallback, is it valid to that for the new callbacks as well? What are the consequences? (speed, precision, nothing?)

Best regards
Marc
Millenium Project Enterprises - Hobbyist Gamedev Group http://www.mpe-online.org
Walkover is now on Steam => http://store.steampowered.com/app/348700/
User avatar
Marc
 
Posts: 281
Joined: Sun Mar 14, 2004 4:07 pm
Location: Germany

Re: NewtonCreateUserMeshCollision Callbacks 2.0

Postby Julio Jerez » Sat Jul 11, 2009 11:18 am

You do not really have to implement then you can pass NULL, but if your application need that funtionalitya it this si how you can implement
You can check and examples of this in file PlaneCollision.
Those funtions are mustlly for editors, PLug in and experts.
The consecuences of not doing them is that you do not get teh futionality, for example if you do no pass a RayCast, then you still get collision but you will no be able to ray Cast tah shape.
similartly nott implementing GetCollisionInfo, you will not ba able to export the definition of that collision shape,

This wwould be an implementation for the UserMeshHeightField in the SDK
Code: Select all
#define TEST_INFO_AND_AABB

#ifdef TEST_INFO_AND_AABB
static void GetCollisionInfo (void* userData, NewtonCollisionInfoRecord* infoRecord)
{
   // copy here what ever information you wan t pass to the APP;
   UserHeightFieldCollision* me = (UserHeightFieldCollision*) userData;

   //we will pass the info int the HightField Structure bu the APP can use the extra space
   infoRecord->m_heightField.m_width = HEIGHT_SIZE;
   infoRecord->m_heightField.m_height = HEIGHT_SIZE;
   infoRecord->m_heightField.m_verticalScale = HIGHTSCALE_SIZE;
   infoRecord->m_heightField.m_horizonalScale = CELL_SIZE;
   infoRecord->m_heightField.m_elevation = (unsigned short*) me->GetElevationMap ();
   infoRecord->m_heightField.m_gridsDiagonals = 0;
   infoRecord->m_heightField.m_atributes = NULL;
}


static int UserMeshCollisionGetFacesInAABB (
   void* userData, const dFloat* p0, const dFloat* p1,
    const dFloat** vertexArray,
   int* vertexCount, int* vertexStrideInBytes,
    const int* indexList, int maxIndexCount, const int* userDataList)
{
   // this is implementation dependent,          
   // The application must find all that Faces intersecting BBox p0-p1 and copy then in to the passed parameters.

   // copy the pointer vertexArray
   // copy the vertex count into vertexCount
   // copy the vertex stride into vertexStrideInBytes

   // copy each index of the triangle list into indexList, do no copy more indices than maxIndexCount
   // for each face copy the face attribute into pointer userDataList

   // the implementation of this function is very similar to function
   // void  UserHeightFieldCollision::MeshCollisionCollideCallback (NewtonUserMeshCollisionCollideDesc* collideDesc)
   //at the end of this file

   // it must returbn the Face Count

   return 0;
}

#endif


You can test it like this
Code: Select all
   collision = NewtonCreateUserMeshCollision (nWorld, &m_minBox[0], &m_maxBox[0], this, MeshCollisionCollideCallback, UserMeshCollisionRayHitCallback, NULL, GetCollisionInfo, UserMeshCollisionGetFacesInAABB);

   NewtonCollisionInfoRecord collisionInfo;
   NewtonCollisionGetInfo (collision, &collisionInfo);
   if (collisionInfo.m_collisionType == SERIALIZE_ID_USERMESH) {
      int count;
      dVector p0(-100, -100, -100);
      dVector p1(100, 100, 100);
      const dFloat* vertexArray;
      int vertexStrideInBytes;
      int vertexCount;
      int indexList[256];
      int attributeList[256/3];
      count = NewtonTreeCollisionGetVertexListIndexListInAABB (collision, &p0[0], &p1[0],
         &vertexArray, &vertexCount, &vertexStrideInBytes,
         indexList, sizeof (indexList)/sizeof (indexList[0]),
         attributeList);
   }
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonCreateUserMeshCollision Callbacks 2.0

Postby Marc » Sun Jul 12, 2009 6:38 am

ok, so for setting up the scene and calling NewtonUpdate to simulate the physics and accessing the results, I only have to implement MeshCollisionCollideCallback?
Millenium Project Enterprises - Hobbyist Gamedev Group http://www.mpe-online.org
Walkover is now on Steam => http://store.steampowered.com/app/348700/
User avatar
Marc
 
Posts: 281
Joined: Sun Mar 14, 2004 4:07 pm
Location: Germany

Re: NewtonCreateUserMeshCollision Callbacks 2.0

Postby Marc » Wed Jul 15, 2009 7:05 am

I guess that as a yes. I just don't know when Newton calls what callbacks. So I don't know if I need them if I call some Newton method like NewtonUpdate().
Millenium Project Enterprises - Hobbyist Gamedev Group http://www.mpe-online.org
Walkover is now on Steam => http://store.steampowered.com/app/348700/
User avatar
Marc
 
Posts: 281
Joined: Sun Mar 14, 2004 4:07 pm
Location: Germany

Re: NewtonCreateUserMeshCollision Callbacks 2.0

Postby Julio Jerez » Wed Jul 15, 2009 8:46 am

yes that was a yes, I think you migh need to implemnet ray cast too if you want ray cast
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 0 guests

cron