Update heightfield collision dynamically?

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Update heightfield collision dynamically?

Postby Aphex » Wed Apr 22, 2009 11:46 am

Hi,

I need to update a heightfield collision body in realtime - is there a way to just change the height of single points on one quickly? Re-creating it completely is too slow for realtime.
I reckon this would be a useful feature for heightmaps if not already available ;)

[ed] hmm benchmark fun... actually something else was eating up the cpu... but it would still be nice to be able to tweak a height level separately, for deformable terrain ;)
Aphex
 
Posts: 144
Joined: Fri Jun 18, 2004 6:08 am
Location: UK

Re: Update heightfield collision dynamically?

Postby Leadwerks » Thu Apr 23, 2009 12:39 am

There is a structure that contains a pointer to the height data. I do this all the time.
User avatar
Leadwerks
 
Posts: 569
Joined: Fri Oct 27, 2006 2:54 pm

Re: Update heightfield collision dynamically?

Postby Aphex » Thu Apr 23, 2009 9:05 am

Hmm... Is that using the NewtonCollisionGetInfo fn?
Aphex
 
Posts: 144
Joined: Fri Jun 18, 2004 6:08 am
Location: UK

Re: Update heightfield collision dynamically?

Postby Aphex » Mon Apr 27, 2009 5:22 am

No that doesn't work... any clue to what this structure is? :?:
Aphex
 
Posts: 144
Joined: Fri Jun 18, 2004 6:08 am
Location: UK

Re: Update heightfield collision dynamically?

Postby Julio Jerez » Mon Apr 27, 2009 9:48 am

NewtonCollisionGetInfo should do it.
It give yo uall teh infomation in the shape.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Update heightfield collision dynamically?

Postby Aphex » Mon Apr 27, 2009 1:06 pm

When I modify the heightmap data pointed at in the info structure Visual studio tells me the stack has been corrupted - doesn't sound good..?
Aphex
 
Posts: 144
Joined: Fri Jun 18, 2004 6:08 am
Location: UK

Re: Update heightfield collision dynamically?

Postby Julio Jerez » Mon Apr 27, 2009 10:55 pm

you call

NewtonCollisionInfoRecord collisionInfo;
void NewtonCollisionGetInfo collision, NewtonCollisionInfoRecord* collisionInfo);

the you must check that collision type is an actual SERIALIZE_ID_HEIGHTFIELD typr

if it is the member collisionInfo.NewtonHeightFieldCollisionParam;
containg the pointer to the elevation and everything else

Code: Select all
struct NewtonHeightFieldCollisionParam
{
   int m_width;
   int m_height;
   int m_gridsDiagonals;
   dFloat m_horizonalScale;
   dFloat m_verticalScale;
   unsigned short *m_elevation;
   char *m_atributes;
};
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Update heightfield collision dynamically?

Postby Aphex » Tue Apr 28, 2009 3:52 am

OK here's my code:

Code: Select all
         NewtonCollisionInfoRecord collisionInfo;
         NewtonCollisionGetInfo(NewtonBodyGetCollision(mPhysicsBody), &collisionInfo);
         _ASSERT(collisionInfo.m_collisionType == SERIALIZE_ID_HEIGHFIELD);


When I run this (apparently benign) code I get this error on function exit:

'Run-Time Check Failure #2 - Stack around the variable 'collisionInfo' was corrupted.'

i.e. it thinks Newton is writing past the end of the info buffer??


[ed] If I add some padding to the Newton structure after m_atributes, the error goes away...
Code: Select all
   char *m_atributes;
   char buff[129*129];  // my heightmap = 129x129


Maybe Newton's copy of the attributes data is being allocated to just [width], not [width*height] or something similiar?
Aphex
 
Posts: 144
Joined: Fri Jun 18, 2004 6:08 am
Location: UK

Re: Update heightfield collision dynamically?

Postby Julio Jerez » Tue Apr 28, 2009 9:52 am

not it does no copy the arry o elevation ther may be a bug with size,
the side of NewtonCollisionInfoRecord is 128 byte

Are you are using double? maybe there is problem with data size there
please try this

char *m_atributes;
char buff[1024];

NewtonCollisionInfoRecord* collisionInfo = buff;
NewtonCollisionGetInfo(NewtonBodyGetCollision(mPhysicsBody), collisionInfo);

this one of teh reason I do no liek using data strutore in cross platform code
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Update heightfield collision dynamically?

Postby Julio Jerez » Tue Apr 28, 2009 10:13 am

I just pasted thsi code in teh test demo, and I runnint in 32 and 64 bit, it seem to work find
NewtonCollisionGetInfo(NewtonBodyGetCollision(m_level), &collisionInfo);
_ASSERT(collisionInfo.m_collisionType == SERIALIZE_ID_HEIGHTFIELD);


this is the internal code tha support that funtion.

Code: Select all
void dgCollisionHeightField::GetCollisionInfo(dgCollisionInfo* info) const
{
   dgCollision::GetCollisionInfo(info);

   info->m_offsetMatrix = GetOffsetMatrix();
   info->m_collisionType = m_collsionId;

   dgCollisionInfo::dgHeightMapCollisionData& data = info->m_heightFieldCollision;
   data.m_width = m_width;
   data.m_height = m_height;
   data.m_gridsDiagonals = m_diagonalMode;
   data.m_verticalScale = m_verticalScale;
   data.m_horizonalScale = m_horizontalScale;
   data.m_atributes = m_atributeMap;
   data.m_elevation = m_elevationMap;
}


// Name: NewtonCollisionGetInfo
// Get creation parameters for this collision objects.
//
// Parameters:
// *const NewtonCollision* collision - is the pointer to a convex collision primitive.
// *NewtonCollisionInfoRecord* *collisionInfo - pointer to a collision information record.
//
// Remarks: This function can be used by the application for writing file format and for serialization.
//
// See also: NewtonCollisionGetInfo, NewtonCollisionSerialize 
void NewtonCollisionGetInfo(const NewtonCollision* collision, NewtonCollisionInfoRecord* collisionInfo)
{
   dgCollision *coll;
   coll = (dgCollision *)collision;

   TRACE_FUNTION(__FUNCTION__);

   _ASSERTE (sizeof (dgCollisionInfo) <= sizeof (NewtonCollisionInfoRecord));
   coll->GetCollisionInfo ((dgCollisionInfo*) collisionInfo);
}
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Update heightfield collision dynamically?

Postby Aphex » Tue Apr 28, 2009 2:08 pm

Yeah I'm using the double version. sizeof(NewtonCollisionInfoRecord) gives me 1208.
Setting the buff to 1024 prevents the error too.
Aphex
 
Posts: 144
Joined: Fri Jun 18, 2004 6:08 am
Location: UK

Re: Update heightfield collision dynamically?

Postby Aphex » Wed Apr 29, 2009 4:20 am

Also wondering if this is related to the strange behaviour I get on heightfields with poly winding of '1'...
Aphex
 
Posts: 144
Joined: Fri Jun 18, 2004 6:08 am
Location: UK

Re: Update heightfield collision dynamically?

Postby Julio Jerez » Wed Apr 29, 2009 6:10 pm

and what would that be?
Newon only wind the faces on way.

you can set the orientation of the quads diagonals at creation time, but you can not change then at run time.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Update heightfield collision dynamically?

Postby Aphex » Thu Apr 30, 2009 3:50 am

Whoops yes I meant the diagonal orientation, not face winding :oops:
That problem is that my multibody vehicle wheels can sink into the heightmap body when the diagonals are set to '1'.
Aphex
 
Posts: 144
Joined: Fri Jun 18, 2004 6:08 am
Location: UK

Re: Update heightfield collision dynamically?

Postby Aphex » Thu Apr 30, 2009 2:16 pm

Here's a wmv of it in action: http://homepage.ntlworld.com/martingbell/files/NewtonHeightmapProb01.wmv

[ed] hmm... in a bit of recursive thinking, maybe this problem was fixed by that raytrace bug you fixed a while back... but I haven't been able to use the newest sdk due to the vehicle problems ;)
Aphex
 
Posts: 144
Joined: Fri Jun 18, 2004 6:08 am
Location: UK

Next

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 25 guests