[SOLVED]HieghtField Collision

Report any bugs here and we'll post fixes

Moderators: Sascha Willems, Thomas

[SOLVED]HieghtField Collision

Postby SFCBias » Tue Jul 27, 2010 3:54 pm

Im using Ogre3d along with Newton to try and make some terrain collision. I'm trying to use the code thats found in the NewtonTutorials for Hieghtfield collision. So what i did was create the visual terrain via Ogre and tried to export the terrain hieghtmap into a .raw file and import the collision through that. However it doesn't work as expected. I can tell that there is some kind of collision going on but im not sure where. Im using a visual debugger (like the one in OgreNewt) but there are no lines showing up. So im not sure if it is a problem with the .raw file or if it's something else.

Also i tried importing the demo hieghtmap (h2.raw) into the program im using for terrain editing and i got infinite skewers of terrain going into the air. SO my guess is that the file types are not quite the same.
Last edited by SFCBias on Wed Aug 04, 2010 10:47 pm, edited 1 time in total.
SFCBias
 
Posts: 54
Joined: Tue Jun 22, 2010 12:40 am
Location: Hephzibah,GA

Re: HieghtField Collision

Postby Julio Jerez » Tue Jul 27, 2010 4:39 pm

does it work when you make and not export it?
are using serialize to export?
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: HieghtField Collision

Postby SFCBias » Tue Jul 27, 2010 5:22 pm

No im using Ogitor to create and export the terrain hieghtmap then trying to load it into newton
SFCBias
 
Posts: 54
Joined: Tue Jun 22, 2010 12:40 am
Location: Hephzibah,GA

Re: HieghtField Collision

Postby Julio Jerez » Tue Jul 27, 2010 6:29 pm

do you mean the you made the bitmap in Ogitor, or you are made the collision in Ogitor and you serialized.
how do you know if what Ogitor save is the same that is in the serialised file?

The information you are providing is not suficent for me to know what could be happenig.

I suggest you make sure that a simple terrain make by passing the data is working first.
is this a newtonHieghtfield collision or a User define HieghtField?
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: HieghtField Collision

Postby SFCBias » Tue Jul 27, 2010 6:37 pm

This is using NewtonHieghtFieldCollision from this function:
Code: Select all
NewtonCollision* CreateHeightFieldCollision (NewtonWorld* world, char* fileName, int* shapeIdArray)
{
   int width;
   int height;
   char* attributes;
   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 = malloc (width * height * sizeof (unsigned short));
   attributes = 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, attributes, CELL_SIZE, ELEVATION_SCALE_INV, 0);
   free (elevations);
   free (attibutes);
   fclose (file);
 
   return collision;
}


The file (hieghtmap) that is produced by Ogitor is a raw 32 bit float file which i beleive is that same format as the on from the Tutorial (h2.raw)
SFCBias
 
Posts: 54
Joined: Tue Jun 22, 2010 12:40 am
Location: Hephzibah,GA

Re: HieghtField Collision

Postby Stucuk » Tue Jul 27, 2010 7:59 pm

I doubt there the same. The raw files the newton tutorials use are a custom format. There is no single "Raw" format(Some raw's are sound, textures, etc), its an extension you can dump anything into.
User avatar
Stucuk
 
Posts: 801
Joined: Sat Mar 12, 2005 3:54 pm
Location: Scotland

Re: HieghtField Collision

Postby Julio Jerez » Tue Jul 27, 2010 9:12 pm

Ok now we clarify something. you are not reading a previsully serialized newton collision file.

now let us go to the problem.
Ogitor is saving a float bitmap, if you look at teh code fragment you got form the SDK, the bitmap is expected to be a 16 bit unsigned monocrome hieght files,
(h2.raw is a 256 x 256 x 16 bitmap)

you can do teh conversion by reading the Ogitor file in a float array, the creation a temporary array of the same dimensions but 16 bit and scale the elevation from floats to unsigned int
then use that tmp buffer to make teh collision shape.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: HieghtField Collision

Postby SFCBias » Tue Jul 27, 2010 9:35 pm

I understand what you're saying but i'm not sure how to go about doing that.
SFCBias
 
Posts: 54
Joined: Tue Jun 22, 2010 12:40 am
Location: Hephzibah,GA

Re: HieghtField Collision

Postby Julio Jerez » Tue Jul 27, 2010 9:49 pm

you need to conver the hightmap you are saving from Ogitor from 32 bit float to a 16 bit elevation map.

I am not aware of any bitmap format that uses 32 bit floats for elavation,
normally elevation data is saved in the form of 16 bit PNG or 8 bit grayscale.

how did you come about saving a bitmap as a 32 bit float elevation?
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: HieghtField Collision

Postby Stucuk » Wed Jul 28, 2010 12:08 am

You can do something like the following to create an array with 16bits, where Terrain.TerrainInfo[X,Y].Height is your image's pixel.
Code: Select all
var
 HeightMap : Array of Word;
 Attribs   : Array of ShortInt;
begin
 SetLength(HeightMap,Terrain.Width*Terrain.Height);
 SetLength(Attribs,Terrain.Width*Terrain.Height); 

 C := 0;
 for Y := 0 to Terrain.Height-1 do
 for X := 0 to Terrain.Width-1 do
 begin
  HeightMap[C] := Trunc(Terrain.TerrainInfo[X,Y].Height*255);
  Attribs[C]   := 0;
  Inc(C);
 end;
User avatar
Stucuk
 
Posts: 801
Joined: Sat Mar 12, 2005 3:54 pm
Location: Scotland

Re: HieghtField Collision

Postby SFCBias » Wed Jul 28, 2010 12:16 am

I really have no idea. When i got to export hieght maps it prompts me to save as a raw 32bit float extentions (.raw,.ohm, .f32, .r32) . I've posted on the Ogitor forums about it to get more clarifacation.
Last edited by SFCBias on Wed Jul 28, 2010 12:03 pm, edited 1 time in total.
SFCBias
 
Posts: 54
Joined: Tue Jun 22, 2010 12:40 am
Location: Hephzibah,GA

Re: HieghtField Collision

Postby SFCBias » Wed Jul 28, 2010 1:10 am

Stucuk wrote:You can do something like the following to create an array with 16bits, where Terrain.TerrainInfo[X,Y].Height is your image's pixel.
Code: Select all
var
 HeightMap : Array of Word;
 Attribs   : Array of ShortInt;
begin
 SetLength(HeightMap,Terrain.Width*Terrain.Height);
 SetLength(Attribs,Terrain.Width*Terrain.Height); 

 C := 0;
 for Y := 0 to Terrain.Height-1 do
 for X := 0 to Terrain.Width-1 do
 begin
  HeightMap[C] := Trunc(Terrain.TerrainInfo[X,Y].Height*255);
  Attribs[C]   := 0;
  Inc(C);
 end;


i almost have that deciphered but It's hard to read since it's not in a language i know o.O
SFCBias
 
Posts: 54
Joined: Tue Jun 22, 2010 12:40 am
Location: Hephzibah,GA

Re: HieghtField Collision

Postby ledahut » Wed Jul 28, 2010 3:10 am

Its not difficult.
You read float data trough your raw 32 bit file [with two FOR loop], and you put the elevation in unsigned short array [16bit] with a TRUNC or ROUND function.

Be aware of negative float data and data higher than 65535 in your raw file.
ledahut
 
Posts: 98
Joined: Mon Jun 21, 2010 8:03 am
Location: France

Re: HieghtField Collision

Postby Stucuk » Wed Jul 28, 2010 10:57 am

It should be easier to read than C/C++ as its 99% English. ledahut's is correct, tho its proberly best to divide the number by the max a 32bit float can hold to get it into the 0 to 1 range and then multiply it by 65535 to get it into a 16bit range(Need to Trunc or Round the result). That gets around having to check the number is within range, and should properly convert it.
User avatar
Stucuk
 
Posts: 801
Joined: Sat Mar 12, 2005 3:54 pm
Location: Scotland

Re: HieghtField Collision

Postby SFCBias » Wed Jul 28, 2010 11:51 am

Thank you I believe I Understand now. Ill be back if anything changes
SFCBias
 
Posts: 54
Joined: Tue Jun 22, 2010 12:40 am
Location: Hephzibah,GA

Next

Return to Bugs and Fixes

Who is online

Users browsing this forum: No registered users and 7 guests

cron