HeightField Collison - need help

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

HeightField Collison - need help

Postby Matic » Sat Apr 16, 2011 9:03 am

Hello,

I need some help with Newtonheightfieldcollision function. I have a terrain sized 1024 x 1024. I have heightMap of the same size but when I run the simulation collision detection works only on a small part of terrain. Approx: 100 x 100. Here is my code:

iNewtonCollision *terrainCollision = CreateHeightFieldCollision(world, fileName, NULL);
iNewtonBody *terrainBody = CreateRigidBody(world, terrain, terrainCollision, 0);
[world ReleaseCollision:terrainCollision];

How do I define these values to fix the problem?
#define CELL_SIZE 1.0f
#define ELEVATION_SCALE 256.0f
#define TEXTURE_SCALE (1.0f / 16.0f)
#define ELEVATION_SCALE_INV (1.0f / ELEVATION_SCALE)

Thanks!

This is my utility function:
Code: Select all
struct iNewtonCollision* CreateHeightFieldCollision (iNewton* world, const char* fileName, int* shapeIdArray)
{
    int width;
   int height;
   char* attributes;
   unsigned short* elevations;
   FILE* file;
   iNewtonCollision* collision;
   
#define CELL_SIZE            1.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
   NSString* buffer = [[NSString alloc] initWithCString:fileName  encoding: 1];
   NSString *filePath = [[NSBundle mainBundle] pathForResource:buffer ofType:nil]; 
   const char* path = [filePath cStringUsingEncoding: 1];
   file = fopen (path, "rb");
   
   width = 1024;
   height = 1024;
   
   // load the data
   elevations = malloc (width * height * sizeof (unsigned short));
   attributes = malloc (width * width * sizeof (char));
   fread (elevations, sizeof (unsigned short), width * height, file);
   
   memset (attributes, 1, width * height * sizeof (char));
   if (shapeIdArray) {
      for (int i = 0; i < width * height; i ++) {
         attributes[i] = (char)shapeIdArray[0];
      }
   }
   
   collision = [world CreateHeightFieldCollision:width :height :0 :elevations :attributes :CELL_SIZE :ELEVATION_SCALE_INV :0];

   free (elevations);
   free (attributes);
   fclose (file);
   
   return collision;
}
Matic
 
Posts: 15
Joined: Fri Apr 08, 2011 8:23 am
Location: Ljubljana, Slovenia

Re: HeightField Collison - need help

Postby Julio Jerez » Sat Apr 16, 2011 10:54 am

maybe you need to make the work size larger, the defualt is 100 x 100.
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 2 guests