Picking scaled instances does work anymore

Report any bugs here and we'll post fixes

Moderators: Sascha Willems, Thomas

Picking scaled instances does work anymore

Postby Bird » Thu Apr 21, 2016 3:15 pm

Hi Julio,

My picking code no longer works when trying to pick instances with scale applied. It's worked fine in previous versions of Newton and it works fine now in the latest version when there's no scaling applied. Do you know of any recent change you may have made that might cause this?

My project uses instances where I reuse the Collision shape of the original body like this.

-Bird
Code: Select all
NewtonCollision * NewtonOps::createCollisionShape (PhysicsBody::Ptr & pBody)
{   
   if (!pBody) return nullptr;

   // reuse the source body's collision shape if we're an instance
   if (pBody->isInstance())
   {
      NewtonBody * const newtonBody = (NewtonBody*)pBody->instancedFrom->userData;
      if (!newtonBody)
      {
         LOG(CRITICAL) << pBody->instancedFrom->name << " is not bound to a NewtonBody ";
         return nullptr;
      }
      return NewtonBodyGetCollision(newtonBody);
   }
   
   switch ( pBody->desc.shape )
   {
      case CollisionShape::Box:            return createBoxShape(pBody);
      case CollisionShape::Ball:            return createBallShape(pBody);
      case CollisionShape::ConvexHull:      return createConvexHullShape(pBody);
      case CollisionShape::Composite:         return createCompositeShape(pBody);
      case CollisionShape::Compound:         return createCompoundShape(pBody);
        case CollisionShape::Mesh:            return createStaticMeshShape(pBody);

      default:                        return nullptr;
   }

   return nullptr;
}


Later after creating the NewtonBody, I apply the scale like this.

Code: Select all
NewtonBodySetCollisionScale(newtonBody, pBody->t.scale[0], pBody->t.scale[1], pBody->t.scale[2]);
Bird
 
Posts: 437
Joined: Tue Nov 22, 2011 1:27 am

Re: Picking scaled instances does work anymore

Postby Bird » Thu Apr 21, 2016 3:44 pm

I played around some more and it does work when scale is less than 1.0 but starts to fail when scale hits around 1.2

-Bird
Bird
 
Posts: 437
Joined: Tue Nov 22, 2011 1:27 am

Re: Picking scaled instances does work anymore

Postby Julio Jerez » Thu Apr 21, 2016 3:55 pm

no it should works on all scale.
In the scale demo there are larger than one and smaller than one scale. and I believe they can be picked.
if not maybe you can change the demo to reproduce the error.
Julio Jerez
Moderator
Moderator
 
Posts: 11048
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Picking scaled instances does work anymore

Postby Bird » Thu Apr 21, 2016 4:33 pm

Found it!

I was using the NewtonBodySetCollisionScale() call that you have commented out now in the latest demo. When I switched over to NewtonCollisionSetScale() like you're using in the demo it works fine.

Whew! :)

Thanks for the help!

-Bird
Bird
 
Posts: 437
Joined: Tue Nov 22, 2011 1:27 am

Re: Picking scaled instances does work anymore

Postby Julio Jerez » Thu Apr 21, 2016 4:46 pm

so NewtonBodySetCollisionScale() is not working?

that function has a purpose, is apply the scale and update the prophase for that body.
The one that apply for the collision does not.
I will take a look tonight because that function is important.
Julio Jerez
Moderator
Moderator
 
Posts: 11048
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Picking scaled instances does work anymore

Postby Bird » Thu Apr 21, 2016 4:53 pm

Julio Jerez wrote:so NewtonBodySetCollisionScale() is not working?

Doesn't seem to be when using scales greater then 1.2 or so in my tests. Scales less then 1.0 seem to work ok
Bird
 
Posts: 437
Joined: Tue Nov 22, 2011 1:27 am

Re: Picking scaled instances does work anymore

Postby Julio Jerez » Thu Apr 21, 2016 5:59 pm

I just change the no unifoprm scale so that is use eh body scale and also the scale foes for
1.0 +- 0.75

and it seem to be working. O can no checking now, I will do tonigh.
as far as I know it should be working

That function is actually important, because in Newton 3.15 or maybe late in 3.14
The body state variable to store the velocity and angular velocity in a body will change to store the linear and angular momentum.
what means is that if for example you take a body and you scale the to be twice the size, the angular velocity would reduce but half. by the simple fact that angular momentum is conserved.
so is L = W * I

if you make I twice as big the W should be half small since L should be contact.
at the momentum newton does obey the conservation of but linear and angular momentum by only at the integration level, no as the state variable.

This is why for example demos like the gyroscope tops lose momentum, because one the calculation process numerical errors make the L to be smaller and small on each step.
but if L is constant the w is what change in each step. I already try that with the vehicle and it work quite well. It will be just better physics.

anyway I will check the change later so that you test it.
Julio Jerez
Moderator
Moderator
 
Posts: 11048
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Picking scaled instances does work anymore

Postby Julio Jerez » Thu Apr 21, 2016 11:55 pm

Ok I committed the scale mesh using NewtonBodySetCollisionScale
and applying large that 1.2 scale. It seems to work fine.
Please check it out
Julio Jerez
Moderator
Moderator
 
Posts: 11048
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Picking scaled instances does work anymore

Postby Bird » Fri Apr 22, 2016 8:04 am

Julio Jerez wrote:Ok I committed the scale mesh using NewtonBodySetCollisionScale
and applying large that 1.2 scale. It seems to work fine.
Please check it out


Yes, it works as expected. I tried higher scales too and they all worked

Maybe my problem was just that I was only using NewtonBodySetCollisionScale() instead of calling NewtonCollisionSetScale() too. Could that be it?

-Bird
Bird
 
Posts: 437
Joined: Tue Nov 22, 2011 1:27 am

Re: Picking scaled instances does work anymore

Postby Julio Jerez » Fri Apr 22, 2016 9:29 am

Bird wrote:Maybe my problem was just that I was only using NewtonBodySetCollisionScale() instead of calling NewtonCollisionSetScale() too. Could that be it?
-Bird


Glad it works, by you should not have to call both functions, NewtonBodySetCollisionScale is calls
NewtonCollisionSetScale and set the state of the body in the broadphase.
any way is working now.
Julio Jerez
Moderator
Moderator
 
Posts: 11048
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles


Return to Bugs and Fixes

Who is online

Users browsing this forum: Google [Bot] and 4 guests

cron