NewtonHeightFieldCollisionCallback

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

NewtonHeightFieldCollisionCallback

Postby Chooka » Fri Dec 10, 2010 9:02 pm

can NewtonHeightFieldCollisionCallback and NewtonHeightFieldCollisionSetUserRayCastCallback be added to the next version. or do i just use NewtonTreeCollisionCallback and NewtonTreeCollisionSetUserRayCastCallback ?
Chooka
 
Posts: 10
Joined: Fri Dec 10, 2010 8:48 pm

Re: NewtonHeightFieldCollisionCallback

Postby Julio Jerez » Fri Dec 10, 2010 10:00 pm

Aren't they in?
are they failling to work?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonHeightFieldCollisionCallback

Postby Chooka » Sat Dec 11, 2010 12:34 am

I am pretty sure they're not, im using 2.26.
Chooka
 
Posts: 10
Joined: Fri Dec 10, 2010 8:48 pm

Re: NewtonHeightFieldCollisionCallback

Postby Julio Jerez » Sat Dec 11, 2010 1:16 am

Ok I will verify,
what are you doing?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonHeightFieldCollisionCallback

Postby Chooka » Sat Dec 11, 2010 4:42 am

i was just trying to resolve a issue with OgreNewt for this thread http://www.ogre3d.org/addonforums/viewt ... 275#p77251 i made a suggestion to the problem but decided to dive into the OgreNewt source to fix it for him but found those functions were not available.
Last edited by Chooka on Sat Dec 11, 2010 9:48 pm, edited 1 time in total.
Chooka
 
Posts: 10
Joined: Fri Dec 10, 2010 8:48 pm

Re: NewtonHeightFieldCollisionCallback

Postby Julio Jerez » Sat Dec 11, 2010 5:13 pm

I am confused, are you saying that the function are not exposed in OgreNewt, or that teh are disable in the newton.dll?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonHeightFieldCollisionCallback

Postby Chooka » Sat Dec 11, 2010 6:56 pm

they aren't in newton.dll we need them included to be able to update OgreNewt.
Chooka
 
Posts: 10
Joined: Fri Dec 10, 2010 8:48 pm

Re: NewtonHeightFieldCollisionCallback

Postby Julio Jerez » Sat Dec 11, 2010 9:51 pm

Ok I will check it out tomorrow.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonHeightFieldCollisionCallback

Postby Chooka » Sat Dec 11, 2010 10:53 pm

cool thankyou. also could you consider adding some methods for getting/setting attributes at x,y positions and maybe include the attribute info into the callback? I don't mean to make more work for you but trying to save you from having to revisit the topic in the future :)
Chooka
 
Posts: 10
Joined: Fri Dec 10, 2010 8:48 pm

Re: NewtonHeightFieldCollisionCallback

Postby Julio Jerez » Mon Dec 13, 2010 12:06 pm

This get me confused, I just added thsi test to a collision tree demo implemention in the Netwon tutorial

Code: Select all
// test function to see if NewtonTreeCollisionSetUserRayCastCallback is still working
static dFloat UserCollisionCallcack (dFloat interception, dFloat* normal, int faceId, void* usedData)
{
     // this does get called with all correct parameters.
     // do what ever you want here. 
     return 1.0f;
}


NewtonCollision* CreateMeshCollision (NewtonWorld* world, Entity* ent, int* shapeIdArray)
{
   NewtonCollision* collision;

   // now create and empty collision tree
   collision = NewtonCreateTreeCollision (world, 0);

   // start adding faces to the collision tree
   NewtonTreeCollisionBeginBuild (collision);
   // step over the collision geometry and add all faces to the collision tree
   for (int i = 0; i <  ent->m_subMeshCount; i ++) {

      // add each sub mesh as a face id, will will sue this later for a multi material sound effect in and advanced tutorial
      for (int j = 0; j < ent->m_subMeshes[i].m_indexCount; j += 3 ) {
         int index;
         dVector face[3];

         index = ent->m_subMeshes[i].m_indexArray[j + 0] * 3;
         face[0] = dVector (ent->m_vertex[index + 0], ent->m_vertex[index + 1], ent->m_vertex[index + 2]);

         index = ent->m_subMeshes[i].m_indexArray[j + 1] * 3;
         face[1] = dVector (ent->m_vertex[index + 0], ent->m_vertex[index + 1], ent->m_vertex[index + 2]);

         index = ent->m_subMeshes[i].m_indexArray[j + 2] * 3;
         face[2] = dVector (ent->m_vertex[index + 0], ent->m_vertex[index + 1], ent->m_vertex[index + 2]);

         if (shapeIdArray) {
            NewtonTreeCollisionAddFace(collision, 3, &face[0].m_x, sizeof (dVector), shapeIdArray[i]);
         } else {
            NewtonTreeCollisionAddFace(collision, 3, &face[0].m_x, sizeof (dVector), i + 1);
         }
      }
   }

   // end adding faces to the collision tree, also optimize the mesh for best performance
   NewtonTreeCollisionEndBuild (collision, 1);


   // look here, this is how you add the user callback to the collision tree mesh,
   // not to be confused with the filter callback wihch is called on each collision shape that the ray hit.
   // this function is called on each face of this collision tree that ray hit.
   NewtonTreeCollisionSetUserRayCastCallback(collision, UserCollisionCallcack);

   return collision;
}



Chooka wrote:cool thankyou. also could you consider adding some methods for getting/setting attributes at x,y positions and maybe include the attribute info into the callback?

what do you mean? x,y position to what?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonHeightFieldCollisionCallback

Postby Chooka » Mon Dec 13, 2010 8:41 pm

i am here about HeightFieldCollision not TreeCollision. i made this topic because NewtonHeightFieldCollisionCallback and NewtonHeightFieldCollisionSetUserRayCastCallback are not in the newton.dll
Chooka
 
Posts: 10
Joined: Fri Dec 10, 2010 8:48 pm

Re: NewtonHeightFieldCollisionCallback

Postby Julio Jerez » Mon Dec 13, 2010 10:02 pm

Chooka wrote:can NewtonHeightFieldCollisionCallback and NewtonHeightFieldCollisionSetUserRayCastCallback be added to the next version. or do i just use NewtonTreeCollisionCallback and NewtonTreeCollisionSetUserRayCastCallback ?


Oh you mean adding user Ray cast raycasr collsion to the ray heighfild collision.
HightField and collison tree come formn teh same base class, it dosul be very simple, I will check it out tonoight.

Sorry, I thought you were taking aboput collision trees.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonHeightFieldCollisionCallback

Postby Chooka » Tue Dec 14, 2010 2:20 am

sounds like were on the same page now :)

about the attributes i mentioned, i'm sorry i misunderstood what the purpose of them was, after re-reading the HeightFieldCollision tutorial i realized they are there to identify the cell id. just the same it would be handy to have get and set functions like NewtonTreeCollisionGetFaceAttribute and NewtonTreeCollisionSetFaceAttribute.
Chooka
 
Posts: 10
Joined: Fri Dec 10, 2010 8:48 pm

Re: NewtonHeightFieldCollisionCallback

Postby Julio Jerez » Sat Dec 18, 2010 12:51 pm

Ok I see the problem the callback for highfield.

This is the prototype function for the collision call back of the
dFloat UserCollisionCallcack (dFloat interception, dFloat* normal, int faceId, void* usedData)


the funtion is a membet of the dgCollisionMesh class which is the base call fo all static collision in the engine, which are dgCollisionBVH, dgCollisionUserMesh, dgCollisionHeightField and dgCollisionScene
however the funtion will be only call from dgCollisionBVH,

I thpnk teh besh is to move tah funtion to class dgCollisionBVH and
the add anoteh call back to dgCollisionHeightField, wit a diffrnet prototype.

maybe the prototype for thsi can be

dFloat UserHighFieldCollisionCallback (NewtonBody* body, NetwonCollision* collision, int row, int col, dFloat interception, dFloat* normal, int faceId, void* usedData)

is this what you mean?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonHeightFieldCollisionCallback

Postby Julio Jerez » Sat Dec 18, 2010 1:50 pm

Ok I have set it up liek this

// prototype
Code: Select all
static dFloat UserHeightFieldCollisionCallback (const NewtonBody* const body, const NewtonCollision* const heightField, dFloat interception, int row, int col, dFloat* normal, int faceId, void* usedData)
{
   return 1.0f;
}



Code: Select all
// Create a height field collision form a elevation file
NewtonCollision* CreateHeightFieldCollision (NewtonWorld* world, char* fileName, int* shapeIdArray)
{
   int width;
   int height;
   char* attibutes;
   unsigned short* elevations;
   FILE* file;
   NewtonCollision* collision;
   char fullPathName[2048];

   #define CELL_SIZE            12.0f
   #define ELEVATION_SCALE         256.0f
   #define TEXTURE_SCALE         (1.0f / 16.0f)
   #define ELEVATION_SCALE_INV      (1.0f / ELEVATION_SCALE)

   //load from raw data
   GetWorkingFileName (fileName, fullPathName);
   file = fopen (fullPathName, "rb");
   _ASSERTE (file);

   width = 256;
   height = 256;

   // load the data;
   elevations = (unsigned short*) malloc (width * height * sizeof (unsigned short));
   attibutes = (char*) malloc (width * width * sizeof (char));
   fread (elevations, sizeof (unsigned short), width * height, file);

   memset (attibutes, 1, width * height * sizeof (char));
   if (shapeIdArray) {
      for (int i = 0; i < width * height; i ++) {
         attibutes[i] = char(shapeIdArray[0]);
      }
   }

   collision = NewtonCreateHeightFieldCollision (world, width, height, 0, elevations, attibutes, CELL_SIZE, ELEVATION_SCALE_INV, 0);
   free (elevations);
   free (attibutes);
   fclose (file);


   // look here, this is how you add the user callback to the collision tree mesh,
   // not to be confused with the filter callback which is called on each collision shape that the ray hit.
   // this function is called on each face of this collision tree that ray hit.
   NewtonHeightFieldSetUserRayCastCallback(collision, UserHeightFieldCollisionCallback);

   return collision;
}


I got it read, Tell me if the prototype is is ok before I build the SDK. I will post 2.28 tonight with the update, if this is alright
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Next

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 0 guests

cron