[SOLVED]HieghtField Collision

Report any bugs here and we'll post fixes

Moderators: Sascha Willems, Thomas

Re: HieghtField Collision

Postby SFCBias » Mon Aug 02, 2010 4:34 pm

The collision is in the right place now but this is the only debug object that doesn't update its position.
SFCBias
 
Posts: 54
Joined: Tue Jun 22, 2010 12:40 am
Location: Hephzibah,GA

Re: HieghtField Collision

Postby Julio Jerez » Mon Aug 02, 2010 5:44 pm

I did not get that.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: HieghtField Collision

Postby SFCBias » Mon Aug 02, 2010 6:14 pm

Sorry, the actual collision is in the right place. But i may not be able to show an accurate DD because the visual debug object will not move.
SFCBias
 
Posts: 54
Joined: Tue Jun 22, 2010 12:40 am
Location: Hephzibah,GA

Re: HieghtField Collision

Postby Julio Jerez » Mon Aug 02, 2010 6:29 pm

if the debug display is missing then it is because the two meshes are in the righ place, which is right.

now the next step is to see if the elevation is right, for that can you go to you editor and change just one elevation point in the map,
say the point at the lowest left corner of teh highmap, and make a lithe spike there.

then render the mesh and the debug display and see if they match in position, oerinetation and size.

by this we are looking to see if the rotation betwen Ogre and newton are right, and also if the orientation of the diagonals on each grid are the same.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: HieghtField Collision

Postby SFCBias » Mon Aug 02, 2010 9:02 pm

Image

Uploaded with ImageShack.us

These are the results

Ok theres not much i can say about that. The code for the verticalScale is in the last post i had with code.
SFCBias
 
Posts: 54
Joined: Tue Jun 22, 2010 12:40 am
Location: Hephzibah,GA

Re: HieghtField Collision

Postby Julio Jerez » Mon Aug 02, 2010 9:33 pm

you raced few points at a corner and that's how is looks?
why I do not see the elevation in the visual mesh?
there should be some mountains in the map too, by I only see the high being elevated.

In any case the image shows that some how the calculation of the elevation is wrong.
But before we work on that I like to see how the elevation in the visual mesh looks like so tah we have an idea of how the scale should be worked.

also it looks to me like the hieghfield in Ogre is rotated 90 degre with respect to the hieght file in newton,
can you make the elevation at the corner more notizable in the visual mesh, we should be able to fix that.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: HieghtField Collision

Postby SFCBias » Mon Aug 02, 2010 9:38 pm

I made it bigger so it's more visible in the visual mesh. It was there but the picture was at a bad angle

Image

Uploaded with ImageShack.us
SFCBias
 
Posts: 54
Joined: Tue Jun 22, 2010 12:40 am
Location: Hephzibah,GA

Re: HieghtField Collision

Postby Julio Jerez » Mon Aug 02, 2010 11:00 pm

Ok you can see that teh tow high map are rotate by 90 degree relative to each other,

you need to pre mutiply the matrix of the rigid body by 90 degrees around the y axis, do you know hwo to do that?
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: HieghtField Collision

Postby SFCBias » Tue Aug 03, 2010 3:17 am

No, im not certain
SFCBias
 
Posts: 54
Joined: Tue Jun 22, 2010 12:40 am
Location: Hephzibah,GA

Re: HieghtField Collision

Postby Julio Jerez » Tue Aug 03, 2010 7:15 am

in thsi function after you get the matrix form teh Ogre entry you nee to create a 90 rotation matrix aron the Y axis


Code: Select all
void PhysX::createRigidBody(NewtonWorld* world, SceneNode* sourceNode,
         NewtonCollision* m_col, dFloat mass, const String& materialId,
         Terrain* terrain)
   {
      NewtonBody* body = NewtonCreateBody(mWorld, m_col);

      float matrix[16];
      if (sourceNode != NULL)
      {
         // here make a 90 quaternion rotation
         OgreQuat rot (OgreVectror (0, 1, 0), 3.1416* 0.5f);
         rot =  rot * sourceNode->getOrientation();     
         PhysXTools::QuatPosToMatrix(rot, sourceNode->getPosition(), &matrix[0]); _matManager->assignMaterial(body, materialId);
      }
      else
      {
         SceneNode* sn = SceneHandler::getSingleton().getSceneManager("Octree1")->getRootSceneNode();

         // here make a 90 quaternion rotation
         OgreQuat rot (OgreVectror (0, 1, 0), 3.1416* 0.5f);
         rot =  rot * sn->getOrientation();     
         PhysXTools::QuatPosToMatrix(rot,  sn->getPosition(), &matrix[0]);
         _matManager->assignMaterial(body, "GroundMaterial");
      }

       // here set the origin offset like you did to align the mesh and the collision
       x =  (width / 2) * OgreTerrainGetCellSize();
       z =  (height / 2) * OgreTerrainGetCellSize();
      matrix[3 * 4 + 0] -= x;
      matrix[3 * 4 + 2] -= z;



      NewtonBodySetMatrix(body, &matrix[0]);
      NewtonBodySetForceAndTorqueCallback(body, globalForceCallback);
      NewtonBodySetTransformCallback(body, globalTransformCallback);

      NewtonBodySetUserData(body, sourceNode);
      DataLog.LogMessage(LogDataManager::MT_OBJ_CREATED,
            "NewtonBody created at: %p", body);

   }
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: HieghtField Collision

Postby SFCBias » Tue Aug 03, 2010 10:06 am

Results:

Image

Uploaded with ImageShack.us
SFCBias
 
Posts: 54
Joined: Tue Jun 22, 2010 12:40 am
Location: Hephzibah,GA

Re: HieghtField Collision

Postby Julio Jerez » Tue Aug 03, 2010 11:56 am

Ok now the bothe map are aligned, ther are tow problems still, the scale, an dteh diagonal of each cell.

we discude teh Scale, but I guess that ther were som many othe bugs that you did not get the code rights, so let us try agaim.

can I see teh code you wrote to calculate resample the elvation form teh Ogre map to eth Netwon Map?
there have to be a bug there, either the scaling is wrong or the scave you pass to the function CreateHieghtfiled collision is wrong.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: HieghtField Collision

Postby SFCBias » Tue Aug 03, 2010 2:09 pm

Code: Select all
void PhysX::ObjectParser::createHieghtFieldCollision(String& filename,
         Terrain* terrain, int* shapeIdArray)
   {
      int width, height;
      width = height = terrain->getSize() - 1;
      int size = width * height;
      float* array32 = terrain->getHeightData();
      char* attributes;

      // find the min am max in the map
      float min = terrain->getMinHeight();
      float max = terrain->getMaxHeight();

      // crate the new map
      unsigned short* elevation = new unsigned short[size];
      attributes = (char*) malloc(width * width * sizeof(char));
      float scale = max - min;
      Ogre::Real horizontalScale = terrain->getWorldSize()
            / (terrain->getSize() - 2);
               float verticalScale = (1.0f / (65535 * scale));

      for (int i = 0; i < size; i++)
      {
         elevation[i] = (unsigned short) (65535.0f * (array32[i] - min)
               * scale);
         cout << elevation[i] << "\t" << array32[i] << endl;
      }

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

      

      collision = NewtonCreateHeightFieldCollision(WORLD, width, height, 1,
            elevation, attributes, horizontalScale, verticalScale, 0);

      delete[] elevation;
      free(attributes);

      PhysX::getSingleton().createRigidBody(PhysX::getSingleton().getWorld(),
            collision, terrain);

      NewtonReleaseCollision(PhysX::getSingleton().getWorld(), collision);
   }
SFCBias
 
Posts: 54
Joined: Tue Jun 22, 2010 12:40 am
Location: Hephzibah,GA

Re: HieghtField Collision

Postby Julio Jerez » Tue Aug 03, 2010 2:19 pm

I see you did not write the scale teh way I said before, here is the correction, I think

Code: Select all
void PhysX::ObjectParser::createHieghtFieldCollision(String& filename, Terrain* terrain, int* shapeIdArray)
{
   int width, height;
   width = height = terrain->getSize() - 1;
   int size = width * height;
   float* array32 = terrain->getHeightData();
   char* attributes;

   // find the min am max in the map
   float min = terrain->getMinHeight();
   float max = terrain->getMaxHeight();

   // crate the new map
   unsigned short* elevation = new unsigned short[size];
   attributes = (char*) malloc(width * width * sizeof(char));

   // this is wrong
//   float scale = max - min;
   float scale = (fabsf (max - min) > 1.0e-1f) ? 1.0 : 66535.0f / (max - min);

   Ogre::Real horizontalScale = terrain->getWorldSize() / (terrain->getSize() - 2);
   for (int i = 0; i < size; i++)
   {
      // this is wrong
//      elevation[i] = (unsigned short) (65535.0f * (array32[i] - min) * scale);
      elevation[i] = (unsigned short) ((array32[i] - min) * scale);
      cout << elevation[i] << "\t" << array32[i] << endl;
   }

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

   float verticalScale = 1.0f / scale;
   collision = NewtonCreateHeightFieldCollision(WORLD, width, height, 1,
      elevation, attributes, horizontalScale, verticalScale, 0);

   delete[] elevation;
   free(attributes);

   PhysX::getSingleton().createRigidBody(PhysX::getSingleton().getWorld(),
      collision, terrain);

   NewtonReleaseCollision(PhysX::getSingleton().getWorld(), collision);
}



if the elevation in teh oger mesh are allowed to be negative, this may show teh newton terrain and the Ogre mesh displace as if they where in parellel planes.
othewise it sodul be fine.

if the collision and the mesh are parallel all you nee to do is offset the vertical position of the body, the same way you offset the origin.
but let us see how it looks now.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: HieghtField Collision

Postby SFCBias » Tue Aug 03, 2010 2:24 pm

Heights are fine, now it's just getting them aligned properly.

Image

Uploaded with ImageShack.us
SFCBias
 
Posts: 54
Joined: Tue Jun 22, 2010 12:40 am
Location: Hephzibah,GA

PreviousNext

Return to Bugs and Fixes

Who is online

Users browsing this forum: No registered users and 8 guests

cron