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;
}