Heightfield collision, newton 2

Report any bugs here and we'll post fixes

Moderators: Sascha Willems, Thomas

Re: Heightfield collision, newton 2

Postby Crashy » Wed Mar 21, 2012 7:07 am

I've got debug mesh working, I replaced this code :

Code: Select all
dgCollisionInstance* const collision = (dgCollisionInstance*) staticCollision;
   if (collision->IsType (dgCollision::dgCollisionMesh_RTTI)) {
      dgCollisionMesh* const mesh = (dgCollisionMesh*) staticCollision;
      mesh->SetCollisionCallback ((dgCollisionMeshCollisionCallback) userCallback);
   } else if (collision->IsType (dgCollision::dgCollisionScene_RTTI)) {
      dgCollisionScene* const scene = (dgCollisionScene*) staticCollision;
      scene->SetCollisionCallback ((dgCollisionMeshCollisionCallback) userCallback);
   }

by this

Code: Select all
dgCollisionInstance* const collision = (dgCollisionInstance*) staticCollision;
   if (collision->IsType (dgCollision::dgCollisionMesh_RTTI)) {
      dgCollisionMesh* const mesh = (dgCollisionMesh*) collision->GetChildShape();
      mesh->SetCollisionCallback ((dgCollisionMeshCollisionCallback) userCallback);
   } else if (collision->IsType (dgCollision::dgCollisionScene_RTTI)) {
      dgCollisionScene* const scene = (dgCollisionScene*) collision->GetChildShape();
      scene->SetCollisionCallback ((dgCollisionMeshCollisionCallback) userCallback);
   }



I'm trying to see what's the problem now with the problem of collision, I'll send you more infos if I cannot get it working.
Crashy
 
Posts: 101
Joined: Fri Dec 03, 2010 6:30 am

Re: Heightfield collision, newton 2

Postby Crashy » Wed Mar 21, 2012 7:31 am

I sent you another video. At 0"23 it seems that the collision is detected too late.
Crashy
 
Posts: 101
Joined: Fri Dec 03, 2010 6:30 am

Re: Heightfield collision, newton 2

Postby Julio Jerez » Wed Mar 21, 2012 8:44 am

Ok I fix that debug display bug.

It looks like the rounding of the Box around the collison shape is off.

let us do som etest.
first can you also show the debug display of teh airplne mesh?
are you using a compound collision? if you are, for this test only replace teh compoind collision with a convex hull around teh plane. this will show if teh bug is in teh compound or wit teh collison field.
but is important to see both collision not just one.

do that and make another video capture and to see where we are.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Heightfield collision, newton 2

Postby Crashy » Wed Mar 21, 2012 8:46 am

Okay I think I've found the problem.

In Ogrenewt the horizontal scale was computed like this

Code: Select all
 Ogre::Real horizontalScale = (terrain->getWorldSize()
          / (terrain->getSize() -2 ));



And I've replaced this by this code

Code: Select all
 Ogre::Real horizontalScale = (terrain->getWorldSize()
          / (terrain->getSize() ));


Now after a few tests I've never seen collision problems.

Thanks for your help:)
Crashy
 
Posts: 101
Joined: Fri Dec 03, 2010 6:30 am

Re: Heightfield collision, newton 2

Postby Julio Jerez » Wed Mar 21, 2012 10:03 am

Crashy wrote:In Ogrenewt the horizontal scale was computed like this
Code: Select all
 Ogre::Real horizontalScale = (terrain->getWorldSize()
          / (terrain->getSize() -2 ));



upps, that will definilly make a scale the will be off, and it will show the simtomos that you are seem.
Debug display should had shown that problem by looking at thr far edge of the collision mesh and the visual mesh at the same time.
but anyway, glad the bug is solved.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Heightfield collision, newton 2

Postby Crashy » Thu Mar 22, 2012 7:40 am

Another last question about collision Instance. With newton 2, The OgreNewt::Collision class was like this:

Code: Select all
Collision::Collision( const Collision& shape) : m_col(shape.m_col)
{
   m_world = shape.m_world;
   if (m_col) {
      NewtonAddCollisionReference (m_col);
   }
}

Collision::Collision(const NewtonCollision* collision, const World* world) : m_col((NewtonCollision*)collision)
{
   m_world = world;
   NewtonAddCollisionReference (m_col);
}

Collision::~Collision()
{
    if (m_world->getNewtonWorld() && m_col)
    {
        NewtonReleaseCollision( m_world->getNewtonWorld(), m_col );
    }
}


I made changes in order to compile with Newton3 to finally have this:
Code: Select all
Collision::Collision( const Collision& shape) : m_col(shape.m_col)
{
   m_world = shape.m_world;
   if (m_col)
   {
      NewtonCollisionCreateInstance (m_col);
   }
}

Collision::Collision(const NewtonCollision* collision, const World* world) : m_col((NewtonCollision*)collision)
{
   m_world = world;
   NewtonCollisionCreateInstance (m_col);
}

Collision::~Collision()
{
    if (m_world->getNewtonWorld() && m_col)
    {
        NewtonDestroyCollision( m_col );
    }
}


However, this code leads to crashes and memory corruption when a OgreNewt::Collision object is deleted, Is it the right way to do it?

The use case is when raycasting, ogrenewt does something like this (minimal test case) in it's prefilter function

Code: Select all
 unsigned _CDECL Raycast::newtonRaycastPreFilter(const NewtonBody *body, const NewtonCollision *collision, void* userData)
    {
        // get our object!
        Raycast* me = (Raycast*)userData;

        Body* bod = (Body*)NewtonBodyGetUserData( body );
        const World* world = bod->getWorld();


      Collision* coll = new Collision(collision,world);
      delete coll; // <------------------here, when deleting the object, memory corruption
      return 1;
    }


It seems that the collision instance that was tested against the ray is deleted.


EDIT: I removed the code causing troubles because it was useless.
Crashy
 
Posts: 101
Joined: Fri Dec 03, 2010 6:30 am

Re: Heightfield collision, newton 2

Postby Crashy » Thu Mar 22, 2012 9:39 am

One last question and I'll let you work on newton 3 :lol:

With newton2 when a raycast was made it was possible to retrieve the exact sub collision ID of a compound collision that was intersected, but now, looking at this code:

Code: Select all
inline dgFloat32 dgCollisionInstance::RayCast (const dgVector& localP0, const dgVector& localP1, dgContactPoint& contactOut, OnRayPrecastAction preFilter, const dgBody* const body, void* const userData) const
{
   _ASSERTE (m_isUnitScale);
   if (!preFilter || preFilter(body, this, userData)) {
      if (m_isUnitScale) {
         dgFloat32 t = m_childShape->RayCast (localP0, localP1, contactOut, body, userData);
         if (t <= 1.0f) {
            if (!m_childShape->IsType(dgCollision::dgCollisionMesh_RTTI)) {
               contactOut.m_userId = GetUserDataID();
            }
         }
         return t;
      } else {
         _ASSERTE (0);
      }
   }

   return dgFloat32 (1.2f);
}


the line "contactOut.m_userId = GetUserDataID();" erase the id of the sub collision by the global id value of the compound collision.
Is this intended or still in work in progress?
Crashy
 
Posts: 101
Joined: Fri Dec 03, 2010 6:30 am

Re: Heightfield collision, newton 2

Postby Julio Jerez » Thu Mar 22, 2012 10:06 am

Crashy wrote:One last question and I'll let you work on newton 3 :lol:
the line "contactOut.m_userId = GetUserDataID();" erase the id of the sub collision by the global id value of the compound collision.
Is this intended or still in work in progress?


Oh yes that is a bug, that code check check that the chield shape is not a compound first, andif ti is it reycast teh chidl shape and return, I will fix it.


on this
Code: Select all
unsigned _CDECL Raycast::newtonRaycastPreFilter(const NewtonBody *body, const NewtonCollision *collision, void* userData)
    {
        // get our object!
        Raycast* me = (Raycast*)userData;

        Body* bod = (Body*)NewtonBodyGetUserData( body );
        const World* world = bod->getWorld();


      Collision* coll = new Collision(collision,world);
      delete coll; // <------------------here, when deleting the object, memory corruption
      return 1;
    }


I do not undertand what that code is doing, but wite teh collsion instance, teh collison you use to creat a body is not the sam ethat is assigned to the body.
each body get its own copy of a collsion intance and it is teh collsion intance that share teh assest of the shape.
Before all teh per instance and and the per shape data was in teh same object bu that make it defficult to add properties to collsion shape.
for example before making a compoind with teh same shape resues was impossible, bu now is very eassy.

teh will also eliminate the Proxy collsion of teh scene collsion since each collsion how is a proxy. besacally teh collison intance is the Proxy and the collision modifres combine int one and applyed to all collsion shapes.
I have bib plan for collsion intances, so far it is only replacyin corrent funtionality.
but later I will add the scale. and a funtion in newton that has being bothering me for a while.

That is the concept of inertial frame.
Although the engine is bases on the three newtonian law of motion: force equal mass time acceleration, action reaction, Inertia
On the inertia law, teh law say body is in equalbriium when the linear velocity remaind constant. The other way to say that law is "A body is in equelibrium when is a rest on an inertial frame"

so in core 200 an previsu only teh world was cosidered an inertia frame. but with collsion instance, a body any parte of a chile shape can be an inertia frame.
for this the collsion intance will have a variable for linear and angular velocity.
so the say for example you make a compound collision that represnt a ship, insise thet sheep ther are many parts, many of them can have local velocityes, an dteh ship can be moving.

say an elevator go up, teh can be doen by moving teh local shape and setting the velocity of teh local shape,
any object in the way of the elevator that was at equlibrium will ge teh new velocity shabeg and react until teh objec
itself goes to rest is the elevator velocity is also contact. wh eh elevator stops, again the local velocity change whi will be a change in any body accelration an dteh bady react again.
for a long time I have being trying to formalize this engine funtionality and not as a client functionality.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Heightfield collision, newton 2

Postby Crashy » Thu Mar 22, 2012 10:17 am

Nice, thanks:)
Crashy
 
Posts: 101
Joined: Fri Dec 03, 2010 6:30 am

Re: Heightfield collision, newton 2

Postby Julio Jerez » Sat Mar 24, 2012 8:43 pm

Ok I fixed that bug.
now the collison is actually re-entrant, you get prefilter call on the parent shape, and on each of the children shapes in the path of the ray.

the cool thing is that you can also set user data and user id on the child shapes because they are instance.
you can change the transform matrix of any child shape, and the new matrix will collide, you can use that to animate different part of your compound collision airplane.
for example you can make retratible landing gears, or wings, that has collision.

and this is just one of the new cool feature of instance based collision shapes.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Heightfield collision, newton 2

Postby Crashy » Mon Mar 26, 2012 4:30 am

Nice, I can't wait to test these features:)
Crashy
 
Posts: 101
Joined: Fri Dec 03, 2010 6:30 am

Re: Heightfield collision, newton 2

Postby Crashy » Tue Apr 24, 2012 12:01 pm

Any news on the vehicles implementation in newton 3?
Crashy
 
Posts: 101
Joined: Fri Dec 03, 2010 6:30 am

Re: Heightfield collision, newton 2

Postby Julio Jerez » Tue Apr 24, 2012 12:07 pm

I started to work on it last weekend, some time this week.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Heightfield collision, newton 2

Postby Crashy » Tue Apr 24, 2012 12:16 pm

Ok thanks:)
Crashy
 
Posts: 101
Joined: Fri Dec 03, 2010 6:30 am

Previous

Return to Bugs and Fixes

Who is online

Users browsing this forum: No registered users and 9 guests

cron