[SOLVED] Heightfield collision write access error

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

[SOLVED] Heightfield collision write access error

Postby Leadwerks » Thu Nov 19, 2020 6:55 am

I am getting access write errors when I try to modify collision heightfield elevation data. I don't understand what I am doing wrong?

Code: Select all
#include "pch.h"

int main(int argc, const char* argv[])
{
   int resolutionx = 1024;
   int resolutiony = 1024;
   auto collisionworld = NewtonCreate();
   std::vector<unsigned short> heightdata(resolutionx * resolutiony);
   std::vector<char> attribdata(resolutionx * resolutiony);
   std::fill(heightdata.begin(), heightdata.end(), 0);
   std::fill(attribdata.begin(), attribdata.end(), 0);
   unsigned short h1 = heightdata[0];
   unsigned short h2 = heightdata[1];
   heightdata[0] = 0;
   heightdata[1] = 65535;
   auto pickcollision = NewtonCreateHeightFieldCollision(collisionworld, resolutionx, resolutiony, 0, 1, &heightdata[0], &attribdata[0], 1.0 / 65535.0, 1.0, 1.0, 0);
   NewtonCollisionInfoRecord collisioninfo;
   NewtonCollisionGetInfo(pickcollision, &collisioninfo);
   ((unsigned short*)collisioninfo.m_heightField.m_vertialElevation)[0] = h1;
   ((unsigned short*)collisioninfo.m_heightField.m_vertialElevation)[1] = h2;

   int n = 0;
   for (int x = 0; x < resolutionx; x++)
   {
      for (int y = 0; y < resolutiony; y++)
      {
         // Error here when x = 513, y = 928, n = 526240
         ((unsigned short*)collisioninfo.m_heightField.m_vertialElevation)[n] = 0;
         n++;
      }
   }

   return 0;
}
Last edited by Leadwerks on Thu Nov 19, 2020 8:41 am, edited 1 time in total.
User avatar
Leadwerks
 
Posts: 569
Joined: Fri Oct 27, 2006 2:54 pm

Re: Heightfield collision write access error

Postby Leadwerks » Thu Nov 19, 2020 8:25 am

I found something. These structures don't match?:
Code: Select all
   typedef struct NewtonHeightFieldCollisionParam
   {
      int m_width;
      int m_height;
      int m_gridsDiagonals;
      int m_elevationDataType;   // 0 = 32 bit floats, 1 = unsigned 16 bit integers
      dFloat m_verticalScale;
      dFloat m_horizonalScale_x;
      dFloat m_horizonalScale_z;
      dFloat m_horizonalDisplacementScale_x;
      dFloat m_horizonalDisplacementScale_z;
      void* m_vertialElevation;
      short* m_horizotalDisplacement;
      char* m_atributes;
   } NewtonHeightFieldCollisionParam;

   struct dgHeightMapCollisionData
   {
      dgInt32 m_width;
      dgInt32 m_height;
      dgInt32 m_gridsDiagonals;
      dgInt32 m_elevationDataType;      // 0 = 32 bit floats, 1 = unsigned 16 bit intergers
      dgFloat32 m_verticalScale;
      dgFloat32 m_horizonalScale_x;
      dgFloat32 m_horizonalScale_z;
      void* m_elevation;
      dgInt8* m_atributes;
   };
User avatar
Leadwerks
 
Posts: 569
Joined: Fri Oct 27, 2006 2:54 pm

Re: Heightfield collision write access error

Postby Leadwerks » Thu Nov 19, 2020 8:30 am

I don't think the error is present in the last build of 3.14 on Github, so I am updating now...
User avatar
Leadwerks
 
Posts: 569
Joined: Fri Oct 27, 2006 2:54 pm

Re: [SOLVED] Heightfield collision write access error

Postby Julio Jerez » Thu Nov 19, 2020 11:15 am

In newton 4.00 there will be a new terrain type 3d height field.
It is like a 3d terrain. No need for those hacks anymore.
This will allows for terrain with caves, over hangs, boulders and possibly deformable.

There is a class that is there for helping make those kind of maps, if you get later and play, you will see a 2d terrain.
Later using the same algorithm it will extend to a 3d terrain.
The trick to make it like a surface with mountain that have overhangs is to add the third dimension layer at a small resolution.
This way the third dimension is not so dominant that end up looking like and under water cave system more like a land scape. The result is a 2d terrain with layers that can be air brush from an editor.
The under water cave is also possible although those system as impressive the demos I'd seen are, are not really practical. But are good for making small geo like the same way people place building on a map.

Also, on the c data structures, there are not two layers of data structures, since the interface is exposed directly in cpp. this exposes all of the full functionality it of the engine to the user.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: [SOLVED] Heightfield collision write access error

Postby Leadwerks » Fri Nov 20, 2020 9:14 am

I will release our new engine in February 2021 using Newton 3.14, and then start working with 4.0 and make those features a big part of the 1.1 upgrade when it is ready. Really looking forward to seeing what you invent next!
User avatar
Leadwerks
 
Posts: 569
Joined: Fri Oct 27, 2006 2:54 pm


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 53 guests

cron