NewtonBodySetCollisionScale and offset

Report any bugs here and we'll post fixes

Moderators: Sascha Willems, Thomas

NewtonBodySetCollisionScale and offset

Postby arkeon » Sat Sep 13, 2014 5:37 pm

Hello,

I finally convert my project (www.openspace3d.com) to use Newton 3 and face an issue using the NewtonBodySetCollisionScale function.

I use offset when creating collisions and want to be able to scale them after. but it seems that the offset is not scaled.

is this an issue or something I miss ?
arkeon
 
Posts: 261
Joined: Sat Sep 13, 2014 5:25 pm

Re: NewtonBodySetCollisionScale and offset

Postby Julio Jerez » Sat Sep 13, 2014 5:45 pm

the scale is local, it will not affect the matrix.
you can do that by getting the matrix and scale the position

there is a function that apply global scale,
void SetGlobalScale (const dgVector& scale);

but is it no exposed because it is use for scaling compound collisions,

-you can wrap you mesh in a compound apply the scale,
-you can apply the scale as I mentioned.
-or I can expose the global scale why apply the scale from the right and space everything.
Julio Jerez
Moderator
Moderator
 
Posts: 11040
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonBodySetCollisionScale and offset

Postby arkeon » Sat Sep 13, 2014 7:56 pm

Thanks

I will try all the ideas.
But yes expose a setGlobalScale could be useful ;)
arkeon
 
Posts: 261
Joined: Sat Sep 13, 2014 5:25 pm

Re: NewtonBodySetCollisionScale and offset

Postby manny » Sun Sep 14, 2014 5:20 am

Julio Jerez wrote:there is a function that apply global scale,
void SetGlobalScale (const dgVector& scale);

I have implemented scaling in our engine manually, as we're using BSPs (which got 1 unit = 32 bsp units) so I have to apply a factor of 1/32 to the physics world.
Meh, would have been great to know that there is a global scaling function.
http://www.instaLOD.io - InstaLOD - State of the art 3D optimization
manny
Site Admin
Site Admin
 
Posts: 131
Joined: Tue Feb 11, 2014 6:49 pm

Re: NewtonBodySetCollisionScale and offset

Postby arkeon » Sun Sep 14, 2014 6:13 am

Interesting, when using the NewtonBodySetCollisionScale function the bodies do not react the same at all depending of the scale factor.

For example if I create a collision 100 x larger and scale it to 0.01 so the size in scene is the same as 1, the DefaultElasticity and DefaultSoftness must be scalled too on the materials ?!

[Edit]
My bad since Newton 3 use collisions instance, the collision I used to calculate the mass matrix was not updated.

I'm converting a modified version of the ogrenewt wrapper for newton 2. I think there is some refactoring to do...
Last edited by arkeon on Sun Sep 14, 2014 8:17 am, edited 2 times in total.
arkeon
 
Posts: 261
Joined: Sat Sep 13, 2014 5:25 pm

Re: NewtonBodySetCollisionScale and offset

Postby Julio Jerez » Sun Sep 14, 2014 8:12 am

for scaling the collision shape of a body you should use
void NewtonBodySetCollisionScale (const NewtonBody* const body, dFloat scaleX, dFloat scaleY, dFloat scaleZ);
Julio Jerez
Moderator
Moderator
 
Posts: 11040
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonBodySetCollisionScale and offset

Postby arkeon » Sun Sep 14, 2014 8:17 am

Yes this is the function I use

The problem persist ^^
I use NewtonBodySetMassProperties(m_body, (float)mass, NewtonBodyGetCollision(m_body));
So the used collision is the right one, but my small object are bouncing like they where accelerating from high distances.

NewtonBodySetMassProperties is used in the NewtonBodySetCollisionScale function, but it must be a mistake somewhere.
arkeon
 
Posts: 261
Joined: Sat Sep 13, 2014 5:25 pm

Re: NewtonBodySetCollisionScale and offset

Postby arkeon » Sun Sep 14, 2014 12:12 pm

You can just try to reproduce by creating a body with a spherecollision with meshradius * 100
and then call NewtonBodySetCollisionScale with a scale of 0.01;
arkeon
 
Posts: 261
Joined: Sat Sep 13, 2014 5:25 pm

Re: NewtonBodySetCollisionScale and offset

Postby Julio Jerez » Sun Sep 14, 2014 12:25 pm

are you using latest newton from Github?
is not, you must get Newton 3.13 because the small object problem was fixed.

can you make a video so that I can see what are talking about?
Julio Jerez
Moderator
Moderator
 
Posts: 11040
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonBodySetCollisionScale and offset

Postby arkeon » Sun Sep 14, 2014 12:28 pm

I downloaded the Git version 3 days ago.
arkeon
 
Posts: 261
Joined: Sat Sep 13, 2014 5:25 pm

Re: NewtonBodySetCollisionScale and offset

Postby Julio Jerez » Sun Sep 14, 2014 12:43 pm

please get I again, and try again.

in the test what value are you using for meshRadius?
I ask because you are talking of scale factor 0f 10000 (from 0.01 to 100)
so a sphere of radio 1 will become a 200 in diameter,
and it will fell like a balloon, while a sphere of 0.02 will fell like a black hole.

Is that what you are seeing?
Julio Jerez
Moderator
Moderator
 
Posts: 11040
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonBodySetCollisionScale and offset

Postby arkeon » Sun Sep 14, 2014 1:28 pm



here a quick video of the issue
arkeon
 
Posts: 261
Joined: Sat Sep 13, 2014 5:25 pm

Re: NewtonBodySetCollisionScale and offset

Postby Julio Jerez » Sun Sep 14, 2014 1:56 pm

wow aside from the scale issue, that look absolutely terrible, why is that contraction so jittery?

I will try to reproduce the scale issue in the sand box demo.
I can not see very well the code fragment you are using, can you past here so that I use the same values you are using?

after that I notice you are using Ogre, is this Ogre newton or you own newton integration.
something have to be done about that setup, it's no right at all.
Julio Jerez
Moderator
Moderator
 
Posts: 11040
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonBodySetCollisionScale and offset

Postby arkeon » Sun Sep 14, 2014 2:11 pm

I use a modified version of Ogre newton 2
(a lot modified one) plus an another wrapper to the engine.

maybe my update loop is not good :/

here the scale function
orient is the offset rotation and pos the offset position of the collision shape
Code: Select all
void Body::setScale(const Ogre::Vector3& scale, const Ogre::Quaternion& orient, Ogre::Vector3& pos)
{
  float matrix[16];
  OgreNewt::Converters::QuatPosToMatrix(orient, pos, &matrix[0]);
  NewtonCollisionSetMatrix(NewtonBodyGetCollision(m_body), matrix);
  NewtonBodySetCollisionScale(m_body, scale.x, scale.y, scale.z);
}


here the update function
Code: Select all
int World::update( Ogre::Real t_step )
{
   int realUpdates = 0;

   // clamp the step if necessary
   if (t_step > (m_timestep * m_maxTicksPerFrames))
  {
      t_step = m_timestep * m_maxTicksPerFrames;
   }

   // advance the accumulator;
   m_timeAcumulator += t_step;

   while (m_timeAcumulator >= m_timestep)
  {
      NewtonUpdate (m_world, m_timestep);
      m_timeAcumulator -= m_timestep;
      realUpdates++;
   }

   for( Body* body = getFirstBody(); body; body = body->getNext() )
  {
    //hack for newton 2.35
    if ((body->getVelocity() != Ogre::Vector3::ZERO) || (body->getOmega() != Ogre::Vector3::ZERO))
      body->unFreeze();

      body->updateNode(1.0f);
  }

   return realUpdates;
}


in the video small balls are 0.075494 diameter
and it works good if I don't apply a 100 factor on the size

so I create a shape of 3,7747 radius
and apply a scale of 0,01 on the body;
arkeon
 
Posts: 261
Joined: Sat Sep 13, 2014 5:25 pm

Re: NewtonBodySetCollisionScale and offset

Postby arkeon » Sun Sep 14, 2014 2:23 pm

In fact everything goes unstable when I changed the collision creation method to use the NewtonBodySetCollisionScale function

just like the origin shape size change the simulation even if the scalled collision have a good size
arkeon
 
Posts: 261
Joined: Sat Sep 13, 2014 5:25 pm

Next

Return to Bugs and Fixes

Who is online

Users browsing this forum: Majestic-12 [Bot] and 1 guest

cron