interface change

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

interface change

Postby Julio Jerez » Sat Jun 30, 2018 7:57 pm

this is the interface for the collision instances
Code: Select all
void NewtonCollisionSetUserData (const NewtonCollision* const collision, void* const userData);
void* NewtonCollisionGetUserData (const NewtonCollision* const collision);
 void NewtonCollisionSetUserID (const NewtonCollision* const collision, unsigned id);
unsigned NewtonCollisionGetUserID (const NewtonCollision* const collision);


but is becoming too simple, I am find my self wishing that some dat can be save with the collsion shape rather that make material, so I am planning to change to this
Code: Select all
   typedef struct NewtonCollisionUserInfo
   {
      void* m_userData;
      int m_shapeId;
      int m_userFlags;
      dFloat m_userParam[4];
   } NewtonCollisionUserInfo;
void NewtonCollisionGetUserData (const NewtonCollision* const collision, NewtonCollisionUserInfo* const userData);
void NewtonCollisionSetUserData (const NewtonCollision* const collision, const NewtonCollisionUserInfo* const userData);


this is a big change specially for composite shape like Highfields and collision trees.
but the idea that only an id can be passed to the application is too simplistic, it was fine for newton 2.xx and 1.xx but where collsion was per bodies, but with per shape and per contact it s too hard to use.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: interface change

Postby JernejL » Sun Jul 01, 2018 8:39 am

That's not too bad, you could maybe let us pass a size parameter, so you can see which version of struct was sent - kinda like winapi uses, and you can see how much of struct you got, this would make it better binary compatibility for the future.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1578
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: interface change

Postby Julio Jerez » Sun Jul 01, 2018 10:52 am

oh yes that could be a good idea.

after try do remove the two old function I realize that the chnage is too big so I am doing it two steps.
first add the new data structure and the tow new function, remapping the old ones.

then after that is working them change the collision creation functions so that no longer take a shape id as parameter, the use has to set it explicitly.

doing it all at once can introduce too many confusions and bugs.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: interface change

Postby Julio Jerez » Sun Jul 01, 2018 1:01 pm

I made added the data structure, now I am going over the demos requiring changes.

for example in the restitution demo is chnged to thios now
Code: Select all
// old method
//   NewtonCollision* const collision = NewtonBodyGetCollision(body);
//   void* userData = NewtonCollisionGetUserData (collision);
//   dFloat restitution = *((dFloat*)&userData);

// new method now core 3.14 can have per collision user data
   NewtonCollisionMaterial material;
   NewtonCollision* const collision = NewtonBodyGetCollision(body);
   NewtonCollisionGetMaterial(collision, &material);
   dAssert(material.m_userId == 1);
   dFloat restitution = material.m_userParam[0];


no more weird casting and repurposing of user pointers to save different data types.
The end application can use the array of floats and the flags to store whatever it desires.
the structure looks like this. which is think is sufficient for any standard physics application,
but because it is a structure, any app can extend it if is desires and it will work.
Code: Select all
   typedef struct NewtonCollisionMaterial
   {
      void* m_userData;
      int m_userId;
      int m_userFlags;
      dFloat m_userParam[4];
   } NewtonCollisionMaterial;
Julio Jerez
Moderator
Moderator
 
Posts: 12249
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 14 guests

cron